Leaflet.LabelTextCollision
Leaflet.LabelTextCollision copied to clipboard
labelTextCollission with GeoJSON
Hello, Your plug-in looks perfect for my project. Could you tell me how I could implement it using GeoJSON polygons.
L.geoJSON(settings.polygons, {})
same question.
Steps to get labels on GeoJSON
- Create collision as described
- Add it as as renderer to map
- Create geojson obj:
let geojson = L.geoJSON(null, {
style: (feature) => {
// value of text needs to be added from feature object. Can be under properties or directly under feature itself
// text what will be shown on the label
return {color: "red", text: feature.properties.text};
}
})
let listOfGeoJSONFeatures = [];
// load in data
geojson.addData(listOfGeoJSONFeatures).addTo(map);
- If you run into issue, (i ran into error when trying to implement this solution. Specifically: TypeError: Cannot set properties of undefined (setting '45')) then take the code from doc/dist/L.LabelTextCollision.js. It has extra code in the initialize method, compared to the one in repo dist/L.LabelTextCollision.js. I got the working code from demo example, after trying to figure out the issue for couple of hours