Comments (5)
Ok, I found a way :
function getJson(url) {
return JSON.parse($.ajax({
type: 'GET',
url: url,
dataType: 'json',
global: false,
async:false,
success: function(data) {
return data;
}
}).responseText);
}
// set here the instance id
var settlements = getJson('http://data.unhcr.org/api/population/settlements.json?instance_id=car');
sett_markers = L.layerJSON({
caching: false,
callData: function(bbox, callback) {
rData = [];
for(var i in settlements)
rData.push({loc: L.latLng(settlements[i].latitude,settlements[i].longitude),name:settlements[i].name, pop:settlements[i].population});
callback(rData);
},
dataToMarker: function(settlements, loc) {
return L.marker(loc).bindPopup("name:"+settlements.name);
},
}
);
I store the JSON in a variable using AJAX and JSON.parse then I use your plugin to display the markers following this example : http://labs.easyblog.it/maps/leaflet-layerjson/examples/calldata.html
Thanks again for this very usefull plugin ;)
- leo
from leaflet-layerjson.
I think that if your API do not support bbox requests.. and you have fixed number of items, this plugin is not more useful... but you can arrange with few smart options, without jQuery, see here:
http://labs.easyblog.it/maps/leaflet-layerjson/examples/fixed-remote-data.html
from leaflet-layerjson.
I indeed prefer your way, it only uses one variable and i like your popup template :p
Thanks again,
Leo
from leaflet-layerjson.
@l-martine do you work in UNHCR? Can I publish that example in my site?
from leaflet-layerjson.
I'm working for CartONG (http://www.cartong.org), a french NGO that does GIS, mapping and mobile data collection services for other NGO's and UN Agencies like the UNHCR.
Yes, of course, you can publish it on your website, it's your code and the API is public ;)
from leaflet-layerjson.
Related Issues (14)
- Markers diseappearing on zoom in/out when updateOutBounds is set to true HOT 3
- local file? HOT 1
- use debounce function on map moveend zoomend
- What about polygons? HOT 2
- 'async: false' and console warning HOT 2
- function icon builder HOT 2
- Deprecated include of L.Mixin.Events: this property will be removed in future releases... HOT 1
- glitch on moveend
- Layer cache persists after remove HOT 1
- OVERPASS API - Visualize way center HOT 3
- Lines and Polygons with layerJSON HOT 1
- jsonp request HOT 3
- caching: true & zoomOut is not realoding data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet-layerjson.