欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

卷帘

程序员文章站 2022-07-13 11:57:33
...

思路

  1. 定义要素图层
  2. new一个卷帘对象
  3. 开启小部件
    PS:要素图层需要添加在map容器中才能在卷帘对象中设置layers
实用方法
swipeWidget01.disable();//禁用小部件
swipeWidget23.enable();//启用小部件

完整代码

<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Layer Swipe</title>
    <link rel="stylesheet" type="text/css" href="esri.css" />
    <link rel="stylesheet" type="text/css" href="tundra.css" />
    <style>
        html,
        body,
        #map {
            padding: 0;
            margin: 0;
            height: 100%;
            position: relative;
        }
    </style>
     <script src="https://js.arcgis.com/3.29/"></script>
</head>

<body class="calcite">
<div id="map" class="map">
    <div id="swipeDiv"></div>
</div>
</body>

<script>
    require([
        "esri/map",
        "esri/layers/FeatureLayer",
        "esri/dijit/LayerSwipe",
        "dojo/domReady!"
    ], function (
        Map, FeatureLayer, LayerSwipe
    ) {
        var map = new Map("map");
        thingslayer0 = new FeatureLayer("http://localhost:6080/arcgis/rest/services/gaofen/bazhou/MapServer" + "/0", {
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
        });
        thingslayer1 = new FeatureLayer("http://localhost:6080/arcgis/rest/services/gaofen/bazhou/MapServer" + "/1", {
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
        });
        //矢量
        map.addLayer(thingslayer0);
        map.addLayer(thingslayer1);
        var swipeWidget = new LayerSwipe({
            type: "vertical",
            map: map,
            // 要卷帘哪些图层
            layers: [thingslayer0, thingslayer1],
        }, "swipeDiv");
        swipeWidget.startup();
    });
</script>

</html>