-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load data on layer show #8
Comments
??? |
Hey man, wait a litle more then a hour to close this issue, I'm waiting for half year. 😃 Let my explain: To declare a over layer, you need to do something like this: var overLayers = [
{
name: "Drinking Water",
icon: '<i class="icon icon-water"></i>',
layer: L.geoJson(WaterGeoJSON)
},
]; But the necessary data must already be loaded at the time of the overlayer statement My suggestion is make the layer load using a data loaded or a callback function, only when the layer is selected to be shown: var overLayers = [
{
name: "Drinking Water",
icon: '<i class="icon icon-water"></i>',
layer: function(layer){
$.get('some/url/path').done(function(data){
layer.render(L.geoJson(data))
});
}
},
]; This will be helpful when you need to show to much data on a layer. |
Closing the issue was an incentive to describe best your idea :-) Great idea! |
Hi @ebertti in latest days I have thought a lot about this solution.. From version 0.2.2 you can add new layer using two methods: Your code can be changed in this way: var panel = L.control.panelLayers();
$.getJSON('some/url/path.geojson', function(data){
panel.addOverlay({
name: "Drinking Water",
icon: '<i class="icon icon-water"></i>',
layer: L.geoJson(data)
});
}); |
Hi @stefanocudini, 👍 this solution already help. But lets think this scenario. If I have 10 overlay with 200 points. With this solution I steel need to preload all data before add the overlay on map interface. |
waiting upgrade compatibility to Leaflet 1.0, this is the best solution: var panel = L.control.panelLayers(),
var river = L.geoJson();
map.on('layeradd', function(e) {
if(L.stamp(e.layer) === L.stamp(river)) {
$.getJSON('data/river.json', function(data) {
river.addData( data );
});
}
});
panel.addOverlay({
name: "Drinking Water",
icon: '<i class="icon icon-water"></i>',
layer: river
}); add an empty layer and after addData on this |
Have some way to only load data (AJAX) after clicking on a layer button?
The text was updated successfully, but these errors were encountered: