Getting the number of layers in LeafletHow to change Leaflet Map panes layering order (z-index)?Add simple...
Bash script should only kill those instances of another script's that it has launched
Single word request: Harming the benefactor
NASA's RS-25 Engines shut down time
Database Backup for data and log files
'The literal of type int is out of range' con número enteros pequeños (2 dígitos)
Why was Goose renamed from Chewie for the Captain Marvel film?
When traveling to Europe from North America, do I need to purchase a different power strip?
How is the wildcard * interpreted as a command?
Does this video of collapsing warehouse shelves show a real incident?
What wound would be of little consequence to a biped but terrible for a quadruped?
Do items de-spawn in Diablo?
Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?
Could you please stop shuffling the deck and play already?
Was Luke Skywalker the leader of the Rebel forces on Hoth?
Do f-stop and exposure time perfectly cancel?
How to secure an aircraft at a transient parking space?
Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?
How does one describe somebody who is bi-racial?
Is "history" a male-biased word ("his+story")?
Latex does not go to next line
Is it necessary to separate DC power cables and data cables?
PTIJ: Should I kill my computer after installing software?
What are some noteworthy "mic-drop" moments in math?
What was the Kree's motivation in Captain Marvel?
Getting the number of layers in Leaflet
How to change Leaflet Map panes layering order (z-index)?Add simple image layers to MapBox / Leaflet?Adding multiple cartodb layers in viz.json to Leaflet layer control?Removing added layer using leaflet and CartodbIs it possible to put a raster layer on a shifted Chinese basemap using leaflet API?Leaflet Vector Layers (lvector.js) not working in layercontrolLeaflet Remove filtered layerMap IDs to add Mapbox basemaps to Leaflet or OpenLayersLeaflet minimap plugin setView conflictLeaflet API - select one overlay at a time like base layers
There does not seem to be a command to get the number of layers in the map, or am I missing it?
One way to count the layers would be:
Object.keys(map._layers).length
Or is there another preferred way? For instance, I would be interested in finding out how many vectors or how many basemaps have been added to the map, and I am not sure how to achieve that via the above snippet.
leaflet
add a comment |
There does not seem to be a command to get the number of layers in the map, or am I missing it?
One way to count the layers would be:
Object.keys(map._layers).length
Or is there another preferred way? For instance, I would be interested in finding out how many vectors or how many basemaps have been added to the map, and I am not sure how to achieve that via the above snippet.
leaflet
add a comment |
There does not seem to be a command to get the number of layers in the map, or am I missing it?
One way to count the layers would be:
Object.keys(map._layers).length
Or is there another preferred way? For instance, I would be interested in finding out how many vectors or how many basemaps have been added to the map, and I am not sure how to achieve that via the above snippet.
leaflet
There does not seem to be a command to get the number of layers in the map, or am I missing it?
One way to count the layers would be:
Object.keys(map._layers).length
Or is there another preferred way? For instance, I would be interested in finding out how many vectors or how many basemaps have been added to the map, and I am not sure how to achieve that via the above snippet.
leaflet
leaflet
asked Dec 11 '17 at 11:46
BritishSteelBritishSteel
4,17911840
4,17911840
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Leaflet's public API has an eachLayer method for the Map class:
let i = 0;
map.eachLayer(function(){ i += 1; });
console.log('Map has', i, 'layers.');
Please note that eachLayer will properly iterate through layers inside a L.LayerGroup, L.FeatureGroup and L.GeoJson.
Also note that .getLayers() works for LayerGroup (and FeatureGroup and GeoJson), but not for L.Map.
Usage of "private" properties and methods like _layers or _leaflet_id or _latlng is discouraged.
add a comment |
If you mean of features in a layer try:
console.log(myRoadLayer.getLayers().length + " Features in the Roads Layer");
If you mean BaseMaps like "Aerial", "Streets", "Topo" you define what you want in your map. Likewise overlay layers like, "Roads", "Water", "Parcels" are also defined in the creation of your map.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f264921%2fgetting-the-number-of-layers-in-leaflet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Leaflet's public API has an eachLayer method for the Map class:
let i = 0;
map.eachLayer(function(){ i += 1; });
console.log('Map has', i, 'layers.');
Please note that eachLayer will properly iterate through layers inside a L.LayerGroup, L.FeatureGroup and L.GeoJson.
Also note that .getLayers() works for LayerGroup (and FeatureGroup and GeoJson), but not for L.Map.
Usage of "private" properties and methods like _layers or _leaflet_id or _latlng is discouraged.
add a comment |
Leaflet's public API has an eachLayer method for the Map class:
let i = 0;
map.eachLayer(function(){ i += 1; });
console.log('Map has', i, 'layers.');
Please note that eachLayer will properly iterate through layers inside a L.LayerGroup, L.FeatureGroup and L.GeoJson.
Also note that .getLayers() works for LayerGroup (and FeatureGroup and GeoJson), but not for L.Map.
Usage of "private" properties and methods like _layers or _leaflet_id or _latlng is discouraged.
add a comment |
Leaflet's public API has an eachLayer method for the Map class:
let i = 0;
map.eachLayer(function(){ i += 1; });
console.log('Map has', i, 'layers.');
Please note that eachLayer will properly iterate through layers inside a L.LayerGroup, L.FeatureGroup and L.GeoJson.
Also note that .getLayers() works for LayerGroup (and FeatureGroup and GeoJson), but not for L.Map.
Usage of "private" properties and methods like _layers or _leaflet_id or _latlng is discouraged.
Leaflet's public API has an eachLayer method for the Map class:
let i = 0;
map.eachLayer(function(){ i += 1; });
console.log('Map has', i, 'layers.');
Please note that eachLayer will properly iterate through layers inside a L.LayerGroup, L.FeatureGroup and L.GeoJson.
Also note that .getLayers() works for LayerGroup (and FeatureGroup and GeoJson), but not for L.Map.
Usage of "private" properties and methods like _layers or _leaflet_id or _latlng is discouraged.
edited 8 mins ago
meetar
218128
218128
answered Dec 11 '17 at 14:20
IvanSanchezIvanSanchez
6,0331619
6,0331619
add a comment |
add a comment |
If you mean of features in a layer try:
console.log(myRoadLayer.getLayers().length + " Features in the Roads Layer");
If you mean BaseMaps like "Aerial", "Streets", "Topo" you define what you want in your map. Likewise overlay layers like, "Roads", "Water", "Parcels" are also defined in the creation of your map.
add a comment |
If you mean of features in a layer try:
console.log(myRoadLayer.getLayers().length + " Features in the Roads Layer");
If you mean BaseMaps like "Aerial", "Streets", "Topo" you define what you want in your map. Likewise overlay layers like, "Roads", "Water", "Parcels" are also defined in the creation of your map.
add a comment |
If you mean of features in a layer try:
console.log(myRoadLayer.getLayers().length + " Features in the Roads Layer");
If you mean BaseMaps like "Aerial", "Streets", "Topo" you define what you want in your map. Likewise overlay layers like, "Roads", "Water", "Parcels" are also defined in the creation of your map.
If you mean of features in a layer try:
console.log(myRoadLayer.getLayers().length + " Features in the Roads Layer");
If you mean BaseMaps like "Aerial", "Streets", "Topo" you define what you want in your map. Likewise overlay layers like, "Roads", "Water", "Parcels" are also defined in the creation of your map.
answered Dec 11 '17 at 13:23
Bill ChappellBill Chappell
2,6661815
2,6661815
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f264921%2fgetting-the-number-of-layers-in-leaflet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown