Dear All,
I'm working with leaflet+GitSpatial. I have points on a map and I want to use a spatial query to load them on the map, on a click.
I have done something like this but it is completely bad!!
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString()+" "+ urlgeo)
.openOn(map);
var geojsonURL = "http://gitspatial.com/api/v1/Solimyr/WebGIS/Equake_12_13.geojson?lat="+e.latlng.lat.toString()+"lon="+e.latlng.lng.toString()+"&distance=3000000";
var geojsonTileLayer = new L.TileLayer.GeoJSON(geojsonURL);
map.addLayer(geojsonTileLayer);
//urlgeo = "http://gitspatial.com/api/v1/Solimyr/WebGIS/Equake_12_13.geojson?lat=4.780&lon=-0.024&distance=3000";
}
map.on('zoomend', onZoomend);
function onZoomend(){
if(map.getZoom()>=5)
{map.on('click', onMapClick);
}
if(map.getZoom()< 5)
{map.off('click', onMapClick);
}
};
It works but it is really slow. My question is if you know a better way and, actually, if I could get the number of geojson elements within the query. I'm thinking to use the number in a leaflet vector layer poput template.
Thanks All!
P.S. Do you know a good tutorial of Ajax linked to GIS?