美文网首页Arcgis for javaScript
Arcgis动态图层如何控制最大最小缩放层级

Arcgis动态图层如何控制最大最小缩放层级

作者: 华夏车前子 | 来源:发表于2019-06-25 15:15 被阅读0次

    当只加载动态图层(ArcGISDynamicMapServiceLayer)时,调用map.getZoom()方法只会返回-1,为什么呢?
    由于Zoom属性是基于地图的lods属性,而动态地图服务图层并没有lods属性,此时则需人为定义map的lods来实现层级控制。

    实例:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://192.168.2.118:8484/arcgis_js_api/library/3.20/3.20/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://192.168.2.118:8484/arcgis_js_api/library/3.20/3.20/esri/css/esri.css">
    <script src="http://192.168.2.118:8484/arcgis_js_api/library/3.20/3.20/init.js"></script>
    <script type="text/javascript" src="jquery-1.10.2.min.js"></script>
    <title>动态图层</title>
    <script type="text/javascript">
    require([
             "esri/map",
             "esri/layers/ArcGISDynamicMapServiceLayer",
             "dojo/domReady!"
           ], function(
                Map,ArcGISDynamicMapServiceLayer
           ) {
    
            //wkid:3857
               var lods = [
                        { "level": 0, "resolution": 156543.03392800014, "scale": 5.91657527591555E8},
                        { "level": 1, "resolution": 78271.51696399994, "scale": 2.95828763795777E8},
                        { "level": 2, "resolution": 39135.75848200009, "scale": 1.47914381897889E8},
                        { "level": 3, "resolution": 19567.87924099992, "scale": 7.3957190948944E7},
                        { "level": 4, "resolution": 9783.93962049996, "scale": 3.6978595474472E7},
                        { "level": 5, "resolution": 4891.96981024998, "scale": 1.8489297737236E7},
                        { "level": 6, "resolution": 2445.98490512499, "scale": 9244648.868618},
                        { "level": 7, "resolution": 1222.992452562495, "scale": 4622324.434309},
                        { "level": 8, "resolution": 611.4962262813797, "scale": 2311162.217155},
                        { "level": 9, "resolution": 305.74811314055756, "scale": 1155581.108577},
                        { "level": 10, "resolution": 152.87405657041106, "scale": 577790.554289},
                        { "level": 11, "resolution": 76.43702828507324, "scale": 288895.277144},
                        { "level": 12, "resolution": 38.21851414253662, "scale": 144447.638572}
                ];
        //wkid:4326
        // var lods = [
        //         { "level": 1, "resolution": 0.7031249999891485, "scale": 2.958293554545656E8},
        //         { "level": 2, "resolution": 0.35156249999999994, "scale": 1.479146777272828E8},
        //         { "level": 3, "resolution": 0.17578124999999997, "scale":  7.39573388636414E7},
        //         { "level": 4, "resolution": 0.08789062500000014, "scale": 3.69786694318207E7},
        //         { "level": 5, "resolution": 0.04394531250000007, "scale": 1.848933471591035E7},
        //         { "level": 6, "resolution": 0.021972656250000007, "scale": 9244667.357955175},
        //         { "level": 7, "resolution": 0.01098632812500002, "scale": 4622333.678977588},
        //         { "level": 8, "resolution": 0.00549316406250001, "scale": 2311166.839488794},
        //         { "level": 9, "resolution": 0.0027465820312500017, "scale": 1155583.419744397},
        //         { "level": 10, "resolution": 0.0013732910156250009, "scale": 577791.7098721985},
        //         { "level": 11, "resolution": 0.000686645507812499, "scale": 288895.85493609926},
        //         { "level": 12, "resolution": 0.0003433227539062495, "scale": 144447.92746804963}
        // ];
            map = new Map("map", {
                extent: initExtent,
                logo: false,
                slider: false,
                minZoom:6,
                zoom:5,
                maxZoom:9,
                lods:lods,
                autoResize:true
            });
             var url="http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineStreetGray/MapServer";
             var layer = new ArcGISDynamicMapServiceLayer(url);
             map.addLayer(layer);
            //地图比例缩放结束事件
             map.on("zoom-end",function(){
                 //弹出当前地图缩放比例值
                 alert(map.getZoom());
             });
       });
    </script>
    </head>
    <body>
        <div id="map" style="width: 100%;height:500px;border: 1px blue solid;">
        
        </div>
        <h2>世界地图ArcGISDynamicMapServiceLayer图层</h2>
        <h4>针对ArcGISDynamicMapServiceLayer获取当前Zoom的值为-1的解决方法</h4>
    </body>
    </html>
    
    

    注意:v4.7 换成了view.constraints.lods = lods;

    相关文章

      网友评论

        本文标题:Arcgis动态图层如何控制最大最小缩放层级

        本文链接:https://www.haomeiwen.com/subject/adotcctx.html