question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

geoJson.addData() event

See original GitHub issue

I suggest to add an event for when data is added to a geoJson layer so plugins can hook into it if they want to work with that data.

Me from the viewpoint of the plugin currently can’t tell if any data is added via addData to the geoJson layer. Is that correct? Is there any workaround to this?

It came up with this issue in my drawing/editing plugin.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
jwoyamecommented, May 30, 2016

GeoJSON is internally a FeatureGroup, a layer that contains other layers. The layeradd and layerremove events are fired for the GeoJSON layer when its content layers are modified.

The addData function goes through each of the JSON objects in your array and calls addLayer on them, which fires layeradd for each one and provides you access to the new layer (via the layer property):

var geoJsonLayer = L.geoJson().addTo(map);
// called N times, where N is the number of objects in "json"
geoJsonLayer.on('layeradd', function (e) {
   // do something with e.layer
});
geoJsonLayer.addData(json);
0reactions
codeofsumitcommented, Jun 2, 2016

FYI: it worked perfectly

Read more comments on GitHub >

github_iconTop Results From Across the Web

in-place Update Leaflet GeoJSON feature - Stack Overflow
I the case of a CREATE I just do a GeoJSon.AddData() to the appropriate layer. But for the UPDATE and DELETE I want...
Read more >
Using GeoJSON with Leaflet
GeoJSON is a very popular data format among many GIS technologies and services ... var myLayer = L.geoJSON().addTo(map); myLayer.addData(geojsonFeature); ...
Read more >
Leaflet add data to GeoJSON without showing on map
I am adding using GeoJSON data pulled from a service. I want to load the GeoJSON layer but I don't want to display...
Read more >
L.GeoJson
Useful for attaching events and popups to features. filter( <GeoJSON> featureData ... addData( <GeoJSON> data ), this, Adds a GeoJSON object to the...
Read more >
Walkthrough: Adding interactive GeoJSON layers in Leaflet
Note that a call to L.DomEvent.stopPropogation() is needed so that if someone clicks a feature, only the feature click event handler code runs,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found