Nicolás Caputo
Nicolás Caputo

Reputation: 11

Leaflet marker in polygon

I made a map with Leaflet.js with GeoJSON data and all it's right. But when i want put a marker in a Polygon i cant.

I leave a clipping of my code. Everything works except the marker

          data: squareParkData,
          color: "black",
          fillColor: "green",
          fillOpacity: 0.3,
          weight: 1,
          onEachFeature:onEachFeature,
          pointToLayer: function (feature, latlng) {
            return L.marker(latlng, { icon: municipalDependenceIcon });
          }
        }) ```

Thanks

Upvotes: 1

Views: 707

Answers (1)

Leion Tamer
Leion Tamer

Reputation: 11

According to the specifications, it seems like the pointToLayer is used for geomtery type 'points'.

Points are handled differently than polylines and polygons

You can use the (onEachFeature's) feature geometries and add a new marker to the layer.

To compute for the center of multiple points, you can use TurfJS https://turfjs.org/docs/#centroid

Upvotes: 1

Related Questions