-
Notifications
You must be signed in to change notification settings - Fork 176
/
layerswitcher.js
128 lines (127 loc) · 4.45 KB
/
layerswitcher.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(function () {
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Group({
// A layer must have a title to appear in the layerswitcher
title: 'Base maps',
layers: [
new ol.layer.Group({
// A layer must have a title to appear in the layerswitcher
title: 'Water color with labels',
// Setting the layers type to 'base' results
// in it having a radio button and only one
// base layer being visibile at a time
type: 'base',
// Setting combine to true causes sub-layers to be hidden
// in the layerswitcher, only the parent is shown
combine: true,
visible: false,
layers: [
new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'watercolor'
})
}),
new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'terrain-labels'
})
})
]
}),
new ol.layer.Tile({
// A layer must have a title to appear in the layerswitcher
title: 'Water color',
// Again set this layer as a base layer
type: 'base',
visible: false,
source: new ol.source.Stamen({
layer: 'watercolor'
})
}),
new ol.layer.Tile({
// A layer must have a title to appear in the layerswitcher
title: 'OSM',
// Again set this layer as a base layer
type: 'base',
visible: true,
source: new ol.source.OSM()
})
]
}),
new ol.layer.Group({
// A layer must have a title to appear in the layerswitcher
title: 'Overlays',
// Adding a 'fold' property set to either 'open' or 'close' makes the group layer
// collapsible
fold: 'open',
layers: [
new ol.layer.Group({
// A layer must have a title to appear in the layerswitcher
title: 'Boundaries',
// Adding a 'fold' property set to either 'open' or 'close' makes the group layer
// collapsible
fold: 'open',
layers: [
new ol.layer.Image({
// A layer must have a title to appear in the layerswitcher
title: 'Counties',
visible: false,
opacity: 0.5,
source: new ol.source.ImageArcGISRest({
ratio: 1,
params: { LAYERS: 'show:3' },
url:
'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/USA/MapServer'
})
}),
new ol.layer.Image({
// A layer must have a title to appear in the layerswitcher
title: 'States',
visible: true,
source: new ol.source.ImageArcGISRest({
ratio: 1,
params: { LAYERS: 'show:2' },
url:
'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/USA/MapServer'
})
})
]
}),
new ol.layer.Image({
// A layer must have a title to appear in the layerswitcher
title: 'Highways',
visible: false,
source: new ol.source.ImageArcGISRest({
ratio: 1,
params: { LAYERS: 'show:1' },
url:
'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/USA/MapServer'
})
}),
new ol.layer.Image({
// A layer must have a title to appear in the layerswitcher
title: 'Cities',
visible: false,
source: new ol.source.ImageArcGISRest({
ratio: 1,
params: { LAYERS: 'show:0' },
url:
'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/USA/MapServer'
})
})
]
})
],
view: new ol.View({
center: ol.proj.transform([-80.789, 37.926], 'EPSG:4326', 'EPSG:3857'),
zoom: 5
})
});
var layerSwitcher = new ol.control.LayerSwitcher({
tipLabel: 'Légende', // Optional label for button
groupSelectStyle: 'children' // Can be 'children' [default], 'group' or 'none'
});
map.addControl(layerSwitcher);
})();