Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
580 views
in Technique[技术] by (71.8m points)

zooming - Leaflet Layer Groups with one layer representing a custom overlay specified for different zoomlevels

I made a leaflets map with three different layers [osm, highresSatellite, Sentinel2]. I want the map to have a layer control where one can choose between four different layers

  1. osm
  2. higresaerial
  3. Sentinel2
  4. Overlay

The fourth layer Overlay should display Sentinel2 up to zoom level 13 and then switch to highresaerial layer until zoom level 22 I managed to import the different layer and create the overlay via selective diplay based on the current zoomlevel.

My Question is as follows:

How do I add a LayerControl to switch between and show my four different layers. Right now I left out this function because I don't know how to implement this. Currently the map only consists of the overlay. I added some general code parts for the LayerControl.

    var osm = L.tileLayer("http://osm/wmts/OpenStreetMap/webmercator/{z}/{x}/{y}.png", {
                                                attribution: 'OSM Streetmaps',
                                                tileSize: 256,
                                                maxZoom: 22,
                                                minZoom: 0
                                        }),
                        oneatlas = L.tileLayer("http://highressatimages{z}/{y}/{x}.jpeg", {
                                                attribution: 'OneAtlas',
                                                tileSize: 256,
                                                maxZoom: 22,
                                                minZoom: 0,
                                                maxNativeZoom: 17
                                        }),
                        s2 = L.tileLayer.wms("https://Sentinel2/WmsServer?", {
                                                layers: '0',
                                                minZoom: 0,
                                                maxZoom: 20,
                                                maxNativeZoom:20
                                        });
                                       
                var map = L.map('map', {
                        center: [50,13],
                        zoom: 4,
                        layers:[s2]
                        });
                       
                var baseMaps = {
                        'OSM': osm,
                        'OneAtlas': oneatlas,
                        's2': s2,
                        'overlay': ?overlay?
                        };
               
                /*        
                var drawnItems = new L.FeatureGroup();
                map.addLayer(drawnItems);
               
                var options = {
                        position: 'topleft',
                        draw: {
                                marker: false,
                                polyline: false,
                                polygon: {
                                        allowIntersection: false,
                                        drawError: {
                                                color: '#e1e100',
                                                message: 'Dont'
                                        },
                                        shapeOptions:{
                                        color: '#bada55'
                                        }
                                },
                                circle: false,
                                rectangle: {
                                        shapeOptions: {
                                                clickable: false
                                        }
                                },
                                circlemarker:false,
                        },
                        edit:{
                                featureGroup: drawnItems,
                                remove: true
                        }
                };
               
                var drawControl = new L.Control.Draw(options);
       
       
                map.addControl(drawControl);
               
                */

                map.on(L.Draw.Event.CREATED, function(evt) {
                        var type = evt.layerType,
                                layer = evt.layer;

                        drawnItems.addLayer(layer)
                       
                });
                map.on('zoomend',function(){
                        var zoomlevel = map.getZoom();
                        if (zoomlevel <14){
                                if (map.hasLayer(oneatlas)){
                                        map.removeLayer(oneatlas);
                                }
                                map.addLayer(s2);
                       
                        }
                        if (zoomlevel >=14){
                                if (map.hasLayer(s2)){
                                        map.removeLayer(s2);
                                }
                                //map.addLayer(s2);
                                map.addLayer(oneatlas);
                        }
                        console.log("current zoomlevel=" + zoomlevel)
                });
               

                //L.control.layers(baseMaps).addTo(map);

question from:https://stackoverflow.com/questions/65921448/leaflet-layer-groups-with-one-layer-representing-a-custom-overlay-specified-for

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...