-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhtml-annotations.html
365 lines (344 loc) · 14.1 KB
/
html-annotations.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Display custom HTML annotations — Maps for HTML reference examples</title>
<link rel="stylesheet" href="examples.css">
<script src="api-keys.js"></script>
</head>
<body>
<h1>Examples for
<a href="../#use-case-html-annotations">Use Case: Display custom web content describing map features</a>
</h1>
<p>
</p>
<details>
<summary>Jump to section…</summary>
<ul class="toc">
<li>Iframe embeds: <ul>
<li><a href="#google-maps-embed">Google Maps embed</a></li>
<li><a href="#openstreetmap">OpenStreetMap embed</a></li>
<li><a href="#bing-maps-embed">Bing Maps embed</a></li>
<li><a href="#mapbox-embed">Mapbox Studio embed</a></li>
</ul></li>
<li>Client-side frameworks: <ul>
<li><a href="#leaflet-js">Leaflet.js API</a></li>
<li><a href="#openlayers">OpenLayers API</a></li>
<li><a href="#google-maps-api">Google Maps Platform API</a></li>
<li><a href="#bing-maps-api">Bing Maps Control API</a></li>
<li><a href="#mapkit-js">MapKit JS (Apple Maps) API</a></li>
<li><a href="#mapbox-api">Mapbox GL JS API</a></li>
<li><a href="#tomtom">TomTom Maps SDK for Web with vector maps</a></li>
<li><a href="#d3-geo">D3 Geographies APIs</a></li>
</ul></li>
</ul>
</details>
<section id="google-maps-embed">
<h2>Google Maps embed</h2>
<p>Not applicable</p>
</section>
<section id="openstreetmap">
<h2>OpenStreetMap embed</h2>
<p>Not applicable</p>
</section>
<section id="bing-maps-embed">
<h2>Bing Maps embed</h2>
<p>Not applicable</p>
</section>
<section id="mapbox-embed">
<h2>MapBox Studio embed</h2>
<p>Not applicable</p>
</section>
<section id="leaflet-js">
<h2>Leaflet.js (with OpenStreetMap tiles)</h2>
<div id="leaflet-js-map" style="width: 600px; height: 450px;"></div>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>
<code class="script-example">
<script>
{
const map = L.map('leaflet-js-map').setView([46.233226, 6.055737], 15);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
minZoom: 0,
maxZoom: 20,
attribution: 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
const centerMarker = L.marker(map.getCenter());
centerMarker.addTo(map);
centerMarker.bindPopup("<h3>CERN</h3><p>The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.</p>").openPopup();
}
</script>
</code>
</section>
<section id="openlayers">
<h2>OpenLayers with OpenStreetMap tiles</h2>
<div id="openlayers-map" style="width: 600px; height: 450px;"></div>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<code class="script-example">
<script>
{
const vectorLayerFeatures = [];
const vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: vectorLayerFeatures
})
});
const baseMapLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
const view = new ol.View({
center: ol.proj.fromLonLat([6.054893732070923, 46.2334537001]),
zoom: 15
});
const map = new ol.Map({
target: 'openlayers-map',
layers: [baseMapLayer, vectorLayer],
view: view
});
// set up the center marker
const markerSVGData = "data:image/svg+xml,%3Csvg width='36px' height='36px' viewBox='-18 -18 36 36' xmlns='http://www.w3.org/2000/svg'%3E%3Ctitle%3Eround-marker%3C/title%3E%3Cg stroke-width='3' stroke='%236af'%3E%3Ccircle fill='%23fc2' fill-opacity='0.7' r='16'/%3E%3Ccircle r='1.5'/%3E%3C/g%3E%3C/svg%3E";
// simple SVG circle icon,
// the marker will be centered by default
const style = new ol.style.Style({
image: new ol.style.Icon({
opacity: 1,
scale: 0.5,
src: markerSVGData
})
});
const centerMarker = new ol.Feature({
geometry: new ol.geom.Point(view.getCenter())
});
centerMarker.setStyle(style);
vectorLayer.getSource().addFeature(centerMarker);
const popupElement = document.createElement('div');
popupElement.classList.add('popup', 'openlayers');
popupElement
.appendChild(document.createElement('h3'))
.appendChild(document.createTextNode('CERN'));
popupElement
.appendChild(document.createElement('p'))
.appendChild(document.createTextNode('The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.'));
const closeButton = document.createElement('button');
closeButton.type = 'button';
closeButton.classList.add('close');
closeButton.appendChild(document.createTextNode('×'));
const closeFunction = (evt => {
popup.setPosition(undefined);
});
closeButton.onclick = closeFunction;
popupElement
.appendChild(closeButton);
const popup = new ol.Overlay({
element: popupElement,
positioning: 'bottom-center',
stopEvent: false,
offset: [0, -10]
});
map.addOverlay(popup);
map.on('click', (evt) => {
const feature = map.forEachFeatureAtPixel(evt.pixel, (feature) => {
return feature;
});
if (feature) {
const coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
} else {
closeFunction(evt);
}
});
popup.setPosition(view.getCenter());
}
</script>
</code>
</section>
<section id="google-maps-api">
<h2>Google Maps API</h2>
<div id="google-maps-api-map" style="width: 600px; height: 450px;"></div>
<script>
const apiUrl = 'https://maps.googleapis.com/maps/api/js?key=' + m4h.keys.google + '&callback=initMap',
scriptElement = document.createElement('script');
scriptElement.setAttribute('src', apiUrl);
document.body.appendChild(scriptElement);
</script>
<code class="script-example">
<script>
function initMap() {
// set up the map
const mapCenter = new google.maps.LatLng(46.233226, 6.055737);
const map = new google.maps.Map(
document.getElementById('google-maps-api-map'),
{
center: mapCenter,
zoom: 15
}
);
// set up the center marker
const centerMarker = new google.maps.Marker({
map: map,
position: mapCenter
});
const infoWindow = new google.maps.InfoWindow({
content: "<h3>CERN</h3><p>The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.</p>"
});
centerMarker.addListener('click', () => {
infoWindow.open(map, centerMarker);
});
infoWindow.open(map, centerMarker);
}
</script>
</code>
</section>
<section id="bing-maps-api">
<h2>Bing Maps Control API</h2>
<div id="bing-maps-api-map" style="width: 600px; height: 450px;"></div>
<script>
const bingApiUrl = 'https://www.bing.com/api/maps/mapcontrol?key=' + m4h.keys.bing + '&callback=initBingMap',
bingScriptElement = document.createElement('script');
bingScriptElement.setAttribute('src', bingApiUrl);
document.body.appendChild(bingScriptElement);
</script>
<code class="script-example">
<script>
function initBingMap() {
// set up the map
const mapCenter = new Microsoft.Maps.Location(46.233226, 6.055737);
const map = new Microsoft.Maps.Map(document.getElementById('bing-maps-api-map'), {
center: mapCenter,
zoom: 15
});
// set up the center marker
const centerMarker = new Microsoft.Maps.Pushpin(mapCenter);
map.entities.push(centerMarker);
const infoBox = new Microsoft.Maps.Infobox(mapCenter, {
visible: true,
title: 'CERN',
description: 'The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.'
});
infoBox.setMap(map);
Microsoft.Maps.Events.addHandler(centerMarker, 'click', (evt) => {
infoBox.setOptions({
location: centerMarker.getLocation(),
visible: true
})
})
}
</script>
</code>
</section>
<section id="mapkit-js">
<h2>MapKit JS (Apple Maps) API</h2>
<div id="mapkit-js-map" style="width: 600px; height: 450px;"></div>
<script src="https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js"></script>
<code class="script-example">
<script>
{
mapkit.addEventListener('error', function(err) {
console.log(err);
});
let mapkitKey = m4h.keys.mapkit.maps4html;
if (self.location.hostname === 'localhost') {
if (self.location.protocol === 'https:') {
mapkitKey = m4h.keys.mapkit.httpslocalhost8000;
} else {
mapkitKey = m4h.keys.mapkit.localhost8000;
}
}
mapkit.init({
authorizationCallback: function(done) {
done(mapkitKey);
},
language: "en"
});
const center = new mapkit.Coordinate(46.233226, 6.055737),
span = new mapkit.CoordinateSpan(0.004, 0.004),
region = new mapkit.CoordinateRegion(center, span);
const map = new mapkit.Map(document.getElementById('mapkit-js-map'), {
region: region
});
// set up the center marker
const marker = new mapkit.MarkerAnnotation(center, {
title: 'CERN',
subtitle: 'The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.'
});
marker.selected = true;
map.addAnnotation(marker);
}
</script>
</code>
</section>
<section id="mapbox-api">
<h2>Mapbox GL JS API</h2>
<div id="mapbox-api-map" style="width: 600px; height: 450px;"></div>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.css' rel='stylesheet' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.js'></script>
<code class="script-example">
<script>
{ // block to restrict let and const scope to this example
// set up map
mapboxgl.accessToken = m4h.keys.mapboxGL;
const mapCenter = [6.055737, 46.233226];
const map = new mapboxgl.Map({
container: 'mapbox-api-map',
style: 'mapbox://styles/mapbox/streets-v9',
center: mapCenter,
zoom: 15
});
// set up the center marker
const centerMarker = new mapboxgl.Marker();
centerMarker.setLngLat(mapCenter);
centerMarker.addTo(map);
centerMarker.on('click', evt => {
debugger;
});
const popup = new mapboxgl.Popup({ offset: [0, -20]})
.setLngLat(mapCenter)
.setHTML("<h3>CERN</h3><p>The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.</p>")
.addTo(map);
centerMarker.setPopup(popup);
}
</script>
</code>
</section>
<section id="tomtom">
<h2>TomTom Maps SDK for Web with vector maps</h2>
<div id="tomtom-single-location" style="width: 600px; height: 450px;"></div>
<script src='https://api.tomtom.com/maps-sdk-js/4.47.6/examples/sdk/tomtom.min.js'></script>
<!--<link rel='stylesheet' href='https://api.tomtom.com/maps-sdk-js/4.47.6/examples/sdk/map.css'>-->
<link rel='stylesheet' href='tomtom/maps-extract.css'>
<link rel='stylesheet' href='https://api.tomtom.com/maps-sdk-js/4.47.6/examples/elements.css'>
<code class="script-example">
<script>
{
tomtom.setProductInfo('Maps4HTML Examples', '4.47.6');
const map = tomtom.map('tomtom-single-location', {
key: m4h.keys.tomtom,
source: 'vector',
basePath: 'https://api.tomtom.com/maps-sdk-js/4.47.6/examples/sdk',
center: [46.233226, 6.055737],
zoom: 15
});
const centerMarker = tomtom.L.marker(map.getCenter());
centerMarker.addTo(map);
centerMarker.bindPopup("<h3>CERN</h3><p>The World Wide Web was invented here by Sir Tim Berners-Lee between 1989 and 1991.</p>").openPopup();
}
</script>
</code>
</section>
<section id="d3-geo">
<h2>D3 Geographies APIs</h2>
***TODO<!--
Replace with code including link/external scripts. Custom script has <code class="script-example"> parent element.
or <p>Not applicable</p>
-->***
</section>
</body>
</html>