/
openlayers.html
118 lines (109 loc) · 3.88 KB
/
openlayers.html
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
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css" type="text/css">
<style>
.map {
height: 600px;
width: 800px;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/build/ol.js"></script>
<script src="https://unpkg.com/mapbox-gl@0.54.0/dist/mapbox-gl.js"></script>
<script src="/static/ol-layerswitcher.js"></script>
<link rel="stylesheet" href="https://unpkg.com/mapbox-gl@0.54.0/dist/mapbox-gl.css">
<link rel="stylesheet" href="/static/ol-layerswitcher.css" />
<title>Debug Map</title>
</head>
<body>
<div id="map" class="map"></div>
<table>
<tbody id="infos"></tbody>
</table>
<script type="text/javascript">
var mbMap = new mapboxgl.Map({
container: 'map', // container id
style: '{{ .TilesBaseURL }}/static/osm-liberty-gl.style{{ if .TilesKey}}?key={{ .TilesKey }}{{ end }}', // stylesheet location
center: [{{ .CenterLng }}, {{ .CenterLat }}], // starting position [lng, lat]
zoom: 9, // starting zoom
attributionControl: false,
boxZoom: false,
center: [{{ .CenterLng }}, {{ .CenterLat }}],
container: 'map',
doubleClickZoom: false,
dragPan: false,
dragRotate: false,
interactive: false,
keyboard: false,
pitchWithRotate: false,
scrollZoom: false,
touchZoomRotate: false
});
var mbLayer = new ol.layer.Layer({
type: 'base',
title: 'Local',
render: function(frameState) {
var canvas = mbMap.getCanvas();
var viewState = frameState.viewState;
var visible = mbLayer.getVisible();
canvas.style.display = visible ? 'block' : 'none';
var opacity = mbLayer.getOpacity();
canvas.style.opacity = opacity;
// adjust view parameters in mapbox
var rotation = viewState.rotation;
if (rotation) {
mbMap.rotateTo(-rotation * 180 / Math.PI, {
animate: false
});
}
mbMap.jumpTo({
center: ol.proj.toLonLat(viewState.center),
zoom: viewState.zoom - 1,
animate: false
});
// cancel the scheduled update & trigger synchronous redraw
// see https://github.com/mapbox/mapbox-gl-js/issues/7893#issue-408992184
// NOTE: THIS MIGHT BREAK WHEN UPDATING MAPBOX
if (mbMap._frame) {
mbMap._frame.cancel();
mbMap._frame = null;
}
mbMap._render();
return canvas;
}
});
var map = new ol.Map({
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([{{ .CenterLng }}, {{ .CenterLat }}]),
zoom: 9
}),
layers: [
mbLayer,
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: false,
source: new ol.source.OSM()
}),
new ol.layer.Tile({
// A layer must have a title to appear in the layerswitcher
title: 'Stamen',
// Again set this layer as a base layer
type: 'base',
visible: false,
source: new ol.source.Stamen({
layer: 'toner'
})
})
]
});
var layerSwitcher = new ol.control.LayerSwitcher({
groupSelectStyle: 'children' // Can be 'children' [default], 'group' or 'none'
});
map.addControl(layerSwitcher);
</script>
</body>
</html>