Reputation: 101
I want to make edit support for currently displayed geojson polygon layers on the leaflet map. When editing button is pressed it gives me
Uncaught TypeError: Cannot read property 'lat' of null
Here is my code:
const leafletGeoJSON = new L.GeoJSON(arr, {
style(feature: any) {
const temp = getColor(feature.properties.id);
return {
color: temp,
fillColor: temp
};
},
onEachFeature(feature, layer) {
layer.bindTooltip(feature.properties.description);
}
});
leafletGeoJSON.eachLayer(layer => {
reactRef.leafletElement.addLayer(layer);
});
I use the leaflet-draw
Upvotes: 2
Views: 2098
Reputation: 101
I I finally found the root cause because of we are using Multipolyon on DB I just render as it is but in fact leaflet-draw is not support MultiPolygon I changed data structure to Polygon then now everything works fine.
The key here is the featureGroup option. This tells the plugin which FeatureGroup contains the layers that should be editable. The featureGroup can contain 0 or more features with geometry types Point, LineString, and Polygon. Leaflet.draw does not work with multigeometry features such as MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection. If you need to add multigeometry features to the draw plugin, convert them to a FeatureCollection of non-multigeometries (Points, LineStrings, or Polygons).
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw-feature
Upvotes: 1