0
votes

I accept points from the server and I want to create markers on my leaflet map.

I can do this as follows:

1) Get geojson with points and add to my map:

$.getJSON(dataurl, function(data) {
    L.geoJson(data).addTo(map);
})

2) Get arrays of coordinates and add to my map:

$.getJSON(dataurl, function(points) {
    var markers = L.featureGroup();
    _.forEach(points, function (point) {
        markers.push(L.marker(point.latlng, opts))
    }
    map.addLayer(markers);
})

I would like to find the answer to the following question: what is the difference between these approaches? Is there a performance gain using geojson?

1

1 Answers

0
votes

I don't know if there is any better performance for one or another but GeoJSON is the most famous format for encoding geographic data structures. There is a lot of documentation on it and leaflet is designed to use it.

The best way is to use this format because you can simply add properties to your shape, marker, line and there is a lot of method to use them after.

To answer, the difference is that your complicated something which already exist. There is a performance gain on the code side because it is more readable and easier.