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













3















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.










share|improve this question



























    3















    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.










    share|improve this question

























      3












      3








      3








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 11 '17 at 11:46









      BritishSteelBritishSteel

      4,17911840




      4,17911840






















          2 Answers
          2






          active

          oldest

          votes


















          6














          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.






          share|improve this answer

































            0














            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.





            share























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              6














              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.






              share|improve this answer






























                6














                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.






                share|improve this answer




























                  6












                  6








                  6







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 8 mins ago









                  meetar

                  218128




                  218128










                  answered Dec 11 '17 at 14:20









                  IvanSanchezIvanSanchez

                  6,0331619




                  6,0331619

























                      0














                      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.





                      share




























                        0














                        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.





                        share


























                          0












                          0








                          0







                          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.





                          share













                          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.






                          share











                          share


                          share










                          answered Dec 11 '17 at 13:23









                          Bill ChappellBill Chappell

                          2,6661815




                          2,6661815






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

                              Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                              Энтрерриос (город) Содержание История | Географическое...