Difference between marker label and featureLayer file
I realized that I could use a generic sheet layer
and a more advanced map drawer featureLayer
that provides useful functions as a filter. However, I don't understand the difference between
marker = L.Marker (new L.LatLng(lat, lng),
{
icon: L.mapbox.marker.icon(
{'marker-color': 'fc4353'
'marker-size': 'large'
}),
title: name,
});
map.addLayer(marker);
and
var poijson = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lng, lat]
},
"properties": {
"title": poi.name,
"marker-color": "#fc4353",
"marker-size": "large"
}
};
map.featureLayer.setGeoJSON(geojson);
It is the same?
[UPDATE]
Also, if I had a lot of markers, should I add a new layer for each marker? It doesn't seem to be good for performance. For example, if I:
var pois; //loaded with pois info
var geojson=[]; //will contain geojson data
for (p=0; p< pois.length; p++)
{
var poi = pois[p];
var poijson =
{
"type": "Feature",
"geometry":
{
"type": "Point",
"coordinates": [poi.lng, poi.lat]
}
};
geojson.push(poijson);
}
map.featureLayer.setGeoJSON(geojson);
Will there be many layers for each poi
or just one layer with all markers?
Thank you
source to share
When you add a marker to the leaflet via map map.addLayer(marker);
, the marker is added to the sheet creator panel. Markers are simple images / icons.
You can use a geoJSON layer to draw GIS functions: points, lines, polygons, etc. See here: http://leafletjs.com/examples/geojson.html
Mapbox featureLayers is just an extension to the Leaflet geoJSONLayer
Call addMarker
multiple times to add multiple markers . The flyer will create a new layer for each of the markers. Each marker will be added as an image element in the div leaflet-marker-pane
:
http://bl.ocks.org/d3noob/9150014
Updated answer:
If you add a GeoJSON layer with multiple features, Leaflet will create a separate layer for each feature. You can check the map layers by calling map._layers
GeoJSON after adding the layer.
marker.addTo(map)
and map.addLayer(marker)
do the same. Here's a function addTo
taken from source
addTo: function (map) {
map.addLayer(this);
return this;
},
source to share