-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.html
More file actions
268 lines (248 loc) · 13.2 KB
/
index.html
File metadata and controls
268 lines (248 loc) · 13.2 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>index-map.html</title>
<script type="module" src="dist/mapml.js"></script>
<style>
html,
body {
height: 100%;
}
* {
margin: 0;
padding: 0;
}
/* Specifying the `:defined` selector is recommended to style the map
element, such that styles don't apply when fallback content is in use
(e.g. when scripting is disabled or when custom/built-in elements isn't
supported in the browser). */
mapml-viewer:defined {
/* Responsive map. */
max-width: 100%;
/* Full viewport. */
width: 100%;
height: 50%;
/* Remove default (native-like) border. */
border: none;
vertical-align: middle;
}
/* Pre-style to avoid FOUC of inline map-layer and fallback content. */
mapml-viewer:not(:defined) > * {
display: none;
}
/* Pre-style to avoid Layout Shift. */
mapml-viewer:not(:defined) {
display: inline-block;
contain: size;
contain-intrinsic-size: 304px 154px;
}
/* Specifying the `:defined` selector is recommended to style the map
element, such that styles don't apply when fallback content is in use
(e.g. when scripting is disabled or when custom/built-in elements isn't
supported in the browser). */
map[is="web-map"]:defined {
/* Responsive map. */
max-width: 100%;
/* Full viewport. */
width: 100%;
height: 50%;
/* Remove default (native-like) border. */
border: none;
vertical-align: middle;
}
/* Pre-style to avoid Layout Shift. */
map[is="web-map"]:not(:defined) {
display: inline-block;
contain: size;
contain-intrinsic-size: 304px 154px;
}
/* Pre-style to avoid FOUC of inline map-layer and fallback content. */
map[is="web-map"]:not(:defined) + img[usemap],
map[is="web-map"]:not(:defined) > :not(area):not(.mapml-web-map) {
display: none;
}
/* Ensure inline layer content is hidden if custom/built-in elements isn't
supported, or if javascript is disabled. This needs to be defined separately
from the above, because the `:not(:defined)` selector invalidates the entire
declaration in browsers that do not support it. */
map-layer {
display: none;
}
</style>
<noscript>
<style>
/* Ensure fallback content (children of the map element) is displayed if
custom/built-in elements is supported but javascript is disabled. */
mapml-viewer:not(:defined) > :not(map-layer) {
display: initial;
}
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
custom/built-in elements is supported but javascript is disabled. */
mapml-viewer:not(:defined) {
display: initial;
contain: initial;
contain-intrinsic-size: initial;
}
/* Ensure client-side image map fallbacks are displayed if custom/built-in
elements is supported but javascript is disabled. */
map[is="web-map"]:not(:defined) + img[usemap] {
display: initial;
}
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
custom/built-in elements is supported but javascript is disabled. */
map[is="web-map"]:not(:defined) {
display: initial;
contain: initial;
contain-intrinsic-size: initial;
}
</style>
</noscript>
</head>
<body>
<!-- this map defines > 1 searchable layer each with different results format,
so it requires a custom search handler (see below) to render the results -->
<mapml-viewer lang="en" projection="CBMTILE" controls controlslist="geolocation search" zoom="16" lat="45.406314" lon="-75.6883335">
<map-layer label="Canada Base Map - Transportation" checked>
<map-link rel="suggestions" tref="https://geogratis.gc.ca/services/geoname/en/geonames.json?q={searchTerms}*&num=20"></map-link>
<map-link rel="search" tref="https://geogratis.gc.ca/services/geoname/en/geonames.json?q={searchTerms}&num=20"></map-link>
<map-extent checked units="CBMTILE">
<map-meta name="extent" content="top-left-easting=-5388605, top-left-northing=7005413, bottom-right-easting=3895643, bottom-right-northing=-4427255"></map-meta>
<map-link rel="license" href="https://open.canada.ca/en/open-government-licence-canada" title="Open Government Licence - Canada"></map-link>
<map-input name="z" type="zoom" min="0" max="17" value="17"></map-input>
<map-input name="y" type="location" units="tilematrix" axis="row"></map-input>
<map-input name="x" type="location" units="tilematrix" axis="column"></map-input>
<map-link rel="tile" tref="https://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/CBMT3978/MapServer/tile/{z}/{y}/{x}?m4h=t"></map-link>
</map-extent>
</map-layer>
<map-layer label="Current Conditions" checked>
<map-link rel="license" href="https://csw.open.canada.ca/geonetwork/srv/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=csw:IsoRecord&elementsetname=full&id=1f864766-7f7f-4be7-8292-295065c65c78" title="TC211 Metadata for Current Conditions"></map-link>
<map-link rel="legend" href="https://geo.weather.gc.ca/geomet?version=1.3.0&service=WMS&request=GetLegendGraphic&sld_version=1.1.0&layer=CURRENT_CONDITIONS&format=image/png&STYLE=default" title="default" width="35" height="5"></map-link>
<map-extent units="CBMTILE" checked="">
<map-input name="xmin" type="location" position="top-left" axis="easting" units="pcrs"></map-input>
<map-input name="ymin" type="location" position="bottom-left" axis="northing" units="pcrs"></map-input>
<map-input name="xmax" type="location" position="bottom-right" axis="easting" units="pcrs"></map-input>
<map-input name="ymax" type="location" position="top-right" axis="northing" units="pcrs"></map-input>
<map-input name="w" type="width" min="1" max="10000"></map-input>
<map-input name="h" type="height" min="1" max="10000"></map-input>
<map-input name="i" type="location" axis="i" units="map"></map-input>
<map-input name="j" type="location" axis="j" units="map"></map-input>
<map-select id="style-selector" name="style">
<map-option value="default" selected="">default</map-option>
</map-select>
<map-link rel="image" tref="https://geo.weather.gc.ca/geomet/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=CURRENT_CONDITIONS&WIDTH={w}&HEIGHT={h}&FORMAT=image%2Fpng&TRANSPARENT=TRUE&STYLES={style}&CRS=EPSG:3978&BBOX={xmin},{ymin},{xmax},{ymax}"></map-link>
<map-link rel="query" data-query-link="true" tref="https://geo.weather.gc.ca/geomet/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&LAYERS=CURRENT_CONDITIONS&QUERY_LAYERS=CURRENT_CONDITIONS&WIDTH={w}&HEIGHT={h}&FORMAT=image%2Fpng&TRANSPARENT=TRUE&INFO_FORMAT=application%2Fjson&STYLES={style}&CRS=EPSG:3978&BBOX={xmin},{ymin},{xmax},{ymax}&I={i}&J={j}"></map-link>
</map-extent>
</map-layer>
<map-layer label="Photon Search" checked>
<map-meta name="projection" content="CBMTILE"></map-meta>
<map-link rel="suggestions" tref="https://photon.komoot.io/api?q={searchTerms}"></map-link>
<map-link rel="search" tref="https://photon.komoot.io/api?q={searchTerms}"></map-link>
</map-layer>
</mapml-viewer>
<!-- this map uses the default search handler (supports GeoJSON search results only) -->
<map lang="fr" is="web-map" projection="OSMTILE" zoom="14" lat="45.406314" lon="-75.6883335" controls controlslist="geolocation search">
<map-layer data-testid="osm-layer" label="OpenStreetMap" checked >
<map-link rel="license" title="© OpenStreetMap contributors CC BY-SA" href="https://www.openstreetmap.org/copyright"></map-link>
<!-- Register your own geonames.org account at https://www.geonames.org/login
and enable web services at https://www.geonames.org/manageaccount
then replace username=demo with your username
<map-link rel="search" tref="https://secure.geonames.org/searchJSON?q={searchTerms}&maxRows=25&inclBbox=true&username=prushforth"></map-link>
<map-link rel="suggestions" tref="https://secure.geonames.org/searchJSON?name_startsWith={searchTerms}&maxRows=25&inclBbox=true&orderby=relevance&username=prushforth"></map-link>
-->
<!-- default search handler uses GeoJSON responses that have a quasi-standard 'schema' -->
<map-link rel="suggestions" tref="https://photon.komoot.io/api?q={searchTerms}"></map-link>
<map-link rel="search" tref="https://photon.komoot.io/api?q={searchTerms}"></map-link>
<map-extent units="OSMTILE" checked="checked">
<map-input name="z" type="zoom" value="18" min="0" max="18"></map-input>
<map-input name="x" type="location" units="tilematrix" axis="column" min="0" max="262144"></map-input>
<map-input name="y" type="location" units="tilematrix" axis="row" min="0" max="262144"></map-input>
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
</map-extent>
</map-layer>
<map-layer label="Restaurants" checked="">
<map-meta name="extent" content="top-left-easting=-8433179, top-left-northing=5689316, bottom-right-easting=-8420968, bottom-right-northing=5683139"></map-meta>
<map-extent units="OSMTILE" checked="">
<map-select id="restaurants" name="cusine">
<map-option value="restaurants" selected="selected">All cuisines</map-option>
<map-option value="african">African</map-option>
<map-option value="asian">Asian</map-option>
<map-option value="cajun">Cajun</map-option>
<map-option value="indian">Indian</map-option>
<map-option value="italian">Italian</map-option>
<map-option value="mexican">Mexican</map-option>
</map-select>
<map-link tref="https://maps4html.org/experiments/shared/restaurants/{cusine}.mapml" rel="features"></map-link>
</map-extent>
</map-layer>
</map>
<script>
document.addEventListener('DOMContentLoaded', () => {
const viewer = document.querySelector('mapml-viewer');
function toItems(responses, includeValue) {
const items = [];
for (const r of responses) {
const data = r.data;
if (!data) continue;
// geogratis format (items array)
if (data.items) {
for (const item of data.items) {
const entry = {
text: item.name
+ (item.concise ? ' (' + item.concise.code + ')' : '')
+ (item.province ? ', ' + item.province.code : ''),
lat: item.latitude,
lng: item.longitude,
bbox: item.bbox || undefined
};
if (includeValue) entry.value = item.name;
items.push(entry);
}
}
// GeoJSON format (Photon etc.)
if (data.features) {
for (const feature of data.features) {
const props = feature.properties || {};
const parts = [props.name];
for (const key of ['city', 'county', 'state', 'country']) {
if (props[key] && props[key] !== props.name) parts.push(props[key]);
}
const coords = feature.geometry?.coordinates || [];
const bbox = feature.bbox
|| (props.extent?.length === 4 ? props.extent : undefined);
const entry = {
text: parts.filter(Boolean).join(', ') || 'Unnamed',
lat: coords[1],
lng: coords[0],
bbox: bbox || undefined
};
if (includeValue) entry.value = props.name || entry.text;
items.push(entry);
}
}
}
return items;
}
viewer.addEventListener('mapsuggestions', (e) => {
e.preventDefault();
e.detail.setResults(toItems(e.detail.responses, true));
});
viewer.addEventListener('mapsearch', (e) => {
e.preventDefault();
const items = toItems(e.detail.responses, false);
e.detail.setResults(items);
// Auto-navigate to the first result (matches default handler behaviour)
if (items.length > 0) {
const first = items[0];
if (first.bbox && first.bbox.length === 4) {
viewer.zoomToExtent(...first.bbox);
} else if (first.lat != null && first.lng != null) {
viewer.zoomTo(first.lat, first.lng, 14);
}
}
});
});
</script>
</body>
</html>