LeafletLayerJSON plugin printing only first json element

18 views
Skip to first unread message

André Fincato

unread,
Mar 13, 2017, 6:36:50 AM3/13/17
to Leaflet
Hello,

first time I use `leafleft.js` and `json` to populate a map with some markers.

Since I can only export `json` and not `geojson` from an array of data from the website I am working on, I am using leaflet-layerJSON to upload to leaftlet's maps the coordinates.

My current code is

var map = new L.Map('map', {scrollWheelZoom: false}).setView([46.4620, 11.3540], 10);
    map
.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));


var jsonLayer = new L.LayerJSON({url: Kirby.url('/api/luoghi')});
map
.addLayer(jsonLayer);


where `Kirby.url` stands for the baseUrl of the website's current page.

Also, I am linking to a `json` page and not to a `json` file, if that might be relevant.

The `json` page output all the markers coordinates like so

[{ "title": "Biblioteca di Laives", "loc": [46.428279, 11.340092] }, { "title": "Centro Trevi Bolzano", "loc": [46.49583, 11.352416] }, { "title": "Biblioteca di Egna", "loc": [46.314294, 11.272767] }]

If I change the order of the `json`, the map correctly prints the first (and only) element.

What am I missing?


Thanks,
André

André Fincato

unread,
Mar 13, 2017, 6:52:07 AM3/13/17
to Leaflet
UPDATE:

I did not realise that having an `ID` value for each `json` element was so important, now that I added it all elements are being printed out.

(:
Reply all
Reply to author
Forward
0 new messages