Giter VIP home page Giter VIP logo

Comments (5)

l-martine avatar l-martine commented on July 23, 2024

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.

stefanocudini avatar stefanocudini commented on July 23, 2024

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.

l-martine avatar l-martine commented on July 23, 2024

I indeed prefer your way, it only uses one variable and i like your popup template :p

Thanks again,

Leo

from leaflet-layerjson.

stefanocudini avatar stefanocudini commented on July 23, 2024

@l-martine do you work in UNHCR? Can I publish that example in my site?

from leaflet-layerjson.

l-martine avatar l-martine commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.