mirror of
https://github.com/symfony/ux-map.git
synced 2026-03-23 23:42:07 +01:00
[Map] Add Map::removeAll*() methods
This commit is contained in:
committed by
Hugo Alliaume
parent
bb30afa5f3
commit
97e5fd66c6
@@ -1,5 +1,9 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 2.32
|
||||
|
||||
- Add `Map::removeAllMarkers()`, `Map::removeAllPolygons()`, `Map::removeAllPolylines()`, `Map::removeAllCircles()` and `Map::removeAllRectangles()` methods
|
||||
|
||||
## 2.31
|
||||
|
||||
- Add `fitBoundsToMarkers` parameter to `ux_map()` Twig function
|
||||
|
||||
@@ -292,6 +292,22 @@ If you haven't stored the element instance, you can still remove them by passing
|
||||
$map->removeCircle('my-circle');
|
||||
$map->removeRectangle('my-rectangle');
|
||||
|
||||
To remove all instances of a certain element, you can use the `Map::removeAll*()` methods::
|
||||
|
||||
// Add elements
|
||||
$map->addMarker($marker = new Marker(/* ... */));
|
||||
$map->addPolygon($polygon = new Polygon(/* ... */));
|
||||
$map->addPolyline($polyline = new Polyline(/* ... */));
|
||||
$map->addCircle($circle = new Circle(/* ... */));
|
||||
$map->addRectangle($rectangle = new Rectangle(/* ... */));
|
||||
|
||||
// And later, remove those elements
|
||||
$map->removeAllMarkers();
|
||||
$map->removeAllPolygons();
|
||||
$map->removeAllPolylines();
|
||||
$map->removeAllCircles();
|
||||
$map->removeAllRectangles();
|
||||
|
||||
Render a map
|
||||
------------
|
||||
|
||||
|
||||
@@ -64,6 +64,13 @@ abstract class Elements
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAll(): static
|
||||
{
|
||||
$this->elements->removeAll($this->elements);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
foreach ($this->elements as $element) {
|
||||
|
||||
35
src/Map.php
35
src/Map.php
@@ -133,6 +133,13 @@ final class Map
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAllMarkers(): self
|
||||
{
|
||||
$this->markers->removeAll();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addPolygon(Polygon $polygon): self
|
||||
{
|
||||
$this->polygons->add($polygon);
|
||||
@@ -147,6 +154,13 @@ final class Map
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAllPolygons(): self
|
||||
{
|
||||
$this->polygons->removeAll();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addPolyline(Polyline $polyline): self
|
||||
{
|
||||
$this->polylines->add($polyline);
|
||||
@@ -161,6 +175,13 @@ final class Map
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAllPolylines(): self
|
||||
{
|
||||
$this->polylines->removeAll();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCircle(Circle $circle): self
|
||||
{
|
||||
$this->circles->add($circle);
|
||||
@@ -175,6 +196,13 @@ final class Map
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAllCircles(): self
|
||||
{
|
||||
$this->circles->removeAll();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRectangle(Rectangle $rectangle): self
|
||||
{
|
||||
$this->rectangles->add($rectangle);
|
||||
@@ -189,6 +217,13 @@ final class Map
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAllRectangles(): self
|
||||
{
|
||||
$this->rectangles->removeAll();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $extra Extra data forwarded to the JavaScript side. It can be used in your custom
|
||||
* Stimulus controller to benefit from greater flexibility and customization.
|
||||
|
||||
Reference in New Issue
Block a user