-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow marker, polygone and polyline removal
- Loading branch information
Showing
15 changed files
with
392 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Map; | ||
|
||
interface Element | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Map; | ||
|
||
/** | ||
* Represents a collection of map elements. | ||
* | ||
* @author Sylvain Blondeau <[email protected]> | ||
*/ | ||
abstract class Elements | ||
{ | ||
protected \SplObjectStorage $elements; | ||
|
||
public function __construct( | ||
array $elements, | ||
) { | ||
$this->elements = new \SplObjectStorage(); | ||
foreach ($elements as $element) { | ||
$this->elements->attach($element); | ||
} | ||
} | ||
|
||
public function add(Element $element): self | ||
{ | ||
$this->elements->attach($element, $element->id ?? $this->elements->getHash($element)); | ||
|
||
return $this; | ||
} | ||
|
||
private function getElement(string $id): ?Element | ||
{ | ||
foreach ($this->elements as $element) { | ||
if ($element->id === $id) { | ||
return $element; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function remove(Element|string $elementOrId): self | ||
{ | ||
if (\is_string($elementOrId)) { | ||
$elementOrId = $this->getElement($elementOrId); | ||
} | ||
|
||
if (null === $elementOrId) { | ||
return $this; | ||
} | ||
|
||
if ($this->elements->contains($elementOrId)) { | ||
$this->elements->detach($elementOrId); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
foreach ($this->elements as $element) { | ||
$elements[] = $element->toArray(); | ||
} | ||
|
||
return $elements ?? []; | ||
} | ||
|
||
abstract public static function fromArray(array $elements): self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,18 @@ | |
* | ||
* @author Hugo Alliaume <[email protected]> | ||
*/ | ||
final readonly class Marker | ||
final readonly class Marker implements Element | ||
{ | ||
/** | ||
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and | ||
* use them later JavaScript side | ||
*/ | ||
public function __construct( | ||
private Point $position, | ||
private ?string $title = null, | ||
private ?InfoWindow $infoWindow = null, | ||
private array $extra = [], | ||
public Point $position, | ||
public ?string $title = null, | ||
public ?InfoWindow $infoWindow = null, | ||
public array $extra = [], | ||
public ?string $id = null, | ||
) { | ||
} | ||
|
||
|
@@ -38,6 +39,7 @@ public function __construct( | |
* title: string|null, | ||
* infoWindow: array<string, mixed>|null, | ||
* extra: array, | ||
* id: string|null | ||
* } | ||
*/ | ||
public function toArray(): array | ||
|
@@ -47,6 +49,7 @@ public function toArray(): array | |
'title' => $this->title, | ||
'infoWindow' => $this->infoWindow?->toArray(), | ||
'extra' => $this->extra, | ||
'id' => $this->id, | ||
]; | ||
} | ||
|
||
|
@@ -56,6 +59,7 @@ public function toArray(): array | |
* title: string|null, | ||
* infoWindow: array<string, mixed>|null, | ||
* extra: array, | ||
* id: string|null | ||
* } $marker | ||
* | ||
* @internal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Map; | ||
|
||
/** | ||
* Represents a Marker collection. | ||
* | ||
* @author Sylvain Blondeau <[email protected]> | ||
*/ | ||
final class Markers extends Elements | ||
{ | ||
public static function fromArray(array $elements): self | ||
{ | ||
$elementObjects = []; | ||
|
||
foreach ($elements as $element) { | ||
$elementObjects[] = Marker::fromArray($element); | ||
} | ||
|
||
return new self(elements: $elementObjects); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Map; | ||
|
||
/** | ||
* Represents a Polygon collection. | ||
* | ||
* @author Sylvain Blondeau <[email protected]> | ||
*/ | ||
final class Polygons extends Elements | ||
{ | ||
public static function fromArray(array $elements): self | ||
{ | ||
$elementObjects = []; | ||
|
||
foreach ($elements as $element) { | ||
$elementObjects[] = Polygon::fromArray($element); | ||
} | ||
|
||
return new self(elements: $elementObjects); | ||
} | ||
} |
Oops, something went wrong.