-
-
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.
feature #2547 [Map] markers, polygons and polylines removal (sblondea…
…u, Kocal) This PR was merged into the 2.x branch. Discussion ---------- [Map] markers, polygons and polylines removal | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Add new methods to remove markers, polygons or polylines (map elements) Map elements will be store in SplObjectStorage instead of arrays. When create a map element, you can now add an optional identfier (string). New methods `getMarker(string identifier)`, `getPolygon(string identifier)` and `getPolyline(string $identifier)` car retreive a map element from its identfiier. example $departureMarker = new Marker ( position: new Point(45.7640, 4.8357), title: 'Lyon', identifier: 'departure' ) $map->addMarker($departureMarker); // remove marker with $map->removeMarker($departureMarker) // or $map->removeMarker($map->getMarker('departure')); Commits ------- 7f48247 [Map] Minor adjustements a27bd08 allow marker, polygone and polyline removal
- Loading branch information
Showing
15 changed files
with
404 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,21 @@ | ||
<?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; | ||
|
||
/** | ||
* @author Sylvain Blondeau <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
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,79 @@ | ||
<?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]> | ||
* | ||
* @internal | ||
*/ | ||
abstract class Elements | ||
{ | ||
private \SplObjectStorage $elements; | ||
|
||
public function __construct( | ||
array $elements, | ||
) { | ||
$this->elements = new \SplObjectStorage(); | ||
foreach ($elements as $element) { | ||
$this->elements->attach($element); | ||
} | ||
} | ||
|
||
public function add(Element $element): static | ||
{ | ||
$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): static | ||
{ | ||
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,33 @@ | ||
<?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]> | ||
* | ||
* @internal | ||
*/ | ||
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
Oops, something went wrong.