forked from walkermatt/ol-layerswitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddlayer.js
49 lines (44 loc) · 1.56 KB
/
addlayer.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
(function() {
// Create a group for overlays. Add the group to the map when it's created
// but add the overlay layers later
var overlayGroup = new ol.layer.Group({
title: 'Overlays',
layers: [
]
});
// Create a map containing two group layers
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Group({
'title': 'Base maps',
layers: [
new ol.layer.Tile({
title: 'Satellite',
type: 'base',
source: new ol.source.MapQuest({layer: 'sat'})
})
]
}),
overlayGroup
],
view: new ol.View({
center: ol.proj.transform([-0.92, 52.96], 'EPSG:4326', 'EPSG:3857'),
zoom: 6
})
});
// Create a LayerSwitcher instance and add it to the map
var layerSwitcher = new ol.control.LayerSwitcher();
map.addControl(layerSwitcher);
// Add a layer to a pre-exiting ol.layer.Group after the LayerSwitcher has
// been added to the map. The layer will appear in the list the next time
// the LayerSwitcher is shown or LayerSwitcher#renderPanel is called.
overlayGroup.getLayers().push(new ol.layer.Tile({
title: 'Countries',
source: new ol.source.TileWMS({
url: 'http://demo.opengeo.org/geoserver/wms',
params: {'LAYERS': 'ne:ne_10m_admin_1_states_provinces_lines_shp'},
serverType: 'geoserver'
})
}));
})();