卷帘

思路

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

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!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>