-
Notifications
You must be signed in to change notification settings - Fork 72
/
demo.html
583 lines (399 loc) · 25.2 KB
/
demo.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>leaflet-map web-component demo</title>
<script type="text/javascript" src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="demo-header.html">
<link rel="import" href="leaflet-map.html">
<link rel="import" href="demo-advanced.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<style type="text/css">
body {
height: 100%;
margin: 0;
font-family: sans-serif;
background-color: #DDD;
}
#content, .announcement {
max-width: 790px;
background-color: #FFF;
padding: 1em;
margin: 0 auto;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
}
.announcement {
margin: 1em auto;
border: 2px solid #0A0;
}
h2 {
font-size: 1.8em;
margin: 1.5em 0 0.5em -2px;
font-weight: bold;
padding: .2em .5em;
background: #edeeef;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
color: #fff;
background-color: #b0de5c;
background-image: -moz-linear-gradient(top, #b0de5c, #82cb00);
background-image: -o-linear-gradient(top, #b0de5c, #82cb00);
background-image: -webkit-gradient(linear, left top, left bottom, from(#b0de5c), to(#82cb00));
background-image: -webkit-linear-gradient(top, #b0de5c, #82cb00);
background-image: linear-gradient(top, #b0de5c, #82cb00);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#b0de5c', EndColorStr='#82cb00');
border-radius: 5px;
text-shadow: 0 -1px 1px rgba(0,0,0,0.35);
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.2);
}
.nav {
color: #000;
text-decoration: none;
border-bottom: 1px dashed #000;
display: inline-block;
padding: 3px;
}
.nav:hover {
background-color: #DDF;
}
leaflet-map,
geolocation-sample {
max-width: 20em;
height: 20em;
border: 1px solid #aaa;
}
geolocation-sample {
height: 21em;
}
pre {
font-size: large;
padding: 0.5em 1em;
background-color: #DDD;
clear: all;
}
.i {
color: #00D
}
.a {
color: #008;
}
.v {
color: #800;
}
.c {
color: #080;
}
</style>
</head>
<body>
<demo-header></demo-header>
<div class="announcement">
<leaflet-map> 1.0.0 was released on 2015-05-28. Please check out the <a href="https://github.com/leaflet-extras/leaflet-map/releases/tag/v1.0.0">change notes</a> for breaking changes.
</div>
<div id="content">
<p>Most of the options documented in the <a href="http://leafletjs.com/reference.html">Leaflet reference</a> are exported as html attributes. All events are mapped into html events of the same name.</p>
<h2 id="simple">Simple</h2>
<p>Creating a leaflet based map is as simple as adding a <leaflet-map> tag after two lines of boilerplate code to load the web component platform and import the leaflet-map component.</p>
<leaflet-map> </leaflet-map>
<pre class="html"><code>
<<span class="i">script</span> <span class="a">src</span>="<span class="v">../webcomponentsjs/webcomponents-lite.min.js</span>"></<span class="i">script</span>>
<<span class="i">link</span> <span class="a">rel</span>="<span class="v">import</span>" <span class="a">href</span>="<span class="v">leaflet-map.html</span>">
<<span class="i">leaflet-map</span>> </<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="view">Initial View</h2>
<p>Like normal html elements, the map is configurable with attributes. Those attributes correspond to the option parameter of L.map as defined in the <a href="http://leafletjs.com/reference.html">leaflet documentation</a>. For example the initial view is defined as follows:</p>
<leaflet-map latitude="51.505" longitude="-0.09" zoom="13"> </leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">51.505</span>" <span class="a">longitude</span>="<span class="v">-0.09</span>" <span class="a">zoom</span>="<span class="v">13</span>">
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="marker">Marker</h2>
<p>Markers can be defined using html tags as well. The following examples creates a semi transparent marker on the left hand side. And a second marker with a popup on click.</p>
<leaflet-map fit-to-markers>
<leaflet-marker latitude="51.5" longitude="-0.10" title="Transparent" opacity="0.6">
</leaflet-marker>
<leaflet-marker latitude="51.5" longitude="-0.09" title="Popup Demo">
<b>Bold</b>
<p>Text</p>
</leaflet-marker>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">fit-to-markers</span>>
<<span class="i">leaflet-marker</span> <span class="a">latitude</span>="<span class="v">51.5</span>" <span class="a">longitude</span>="<span class="v">-0.10</span>" <span class="a">title</span>="<span class="v">Transparent</span>"
<span class="a">opacity</span>="<span class="v">0.6</span>"> </<span class="i">leaflet-marker</span>>
<<span class="i">leaflet-marker</span> <span class="a">latitude</span>="<span class="v">51.5</span>" <span class="a">longitude</span>="<span class="v">-0.09</span>" <span class="a">title</span>="<span class="v">Popup Demo</span>">
<<span class="i">b</span>>Bold</<span class="i">b</span>>
<<span class="i">p</span>>Text</<span class="i">p</span>>
</<span class="i">leaflet-marker</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="icon">Marker with custom icons</h2>
<p>Markers are based on formating templates called "icons". There are three ways to reference such an icon definition:</p>
<leaflet-map latitude="51.505" longitude="-0.09" zoom="13">
<leaflet-icon id="myicon" icon-url="https://stendhalgame.org/images/mapmarker/me.png"></leaflet-icon>
<leaflet-marker latitude="51.5" longitude="-0.10" title="Icon element reference" icon="myicon">
</leaflet-marker>
<leaflet-marker latitude="51.5" longitude="-0.09" title="Icon json" icon='{"iconUrl": "https://stendhalgame.org/images/mapmarker/dungeon.png"}'>
</leaflet-marker>
<leaflet-marker id="icon-reference" latitude="51.5" longitude="-0.08" title="Icon L.icon()">
</leaflet-marker>
</leaflet-map>
<script>
document.addEventListener("load", function() {
var marker = document.getElementById("icon-reference");
marker.icon = L.icon({
"iconUrl": "https://stendhalgame.org/images/mapmarker/npc.png",
"iconSize": L.point(26, 25),
"iconAnchor": L.point(0, 0)
});
});
</script>
<p>The template icon may be defined using <leaflet-icon> elements. This is the prefered way. Please note that iconSize is mapped to the attributes iconWidth and iconHeight. iconAnchor is mapped to iconAnchorX and iconAnchorY and so on:</p>
<pre class="html"><code>
<<span class="i">leaflet-icon</span> <span class="a">id</span>="<span class="v">myicon</span>"
<span class="a">icon-url</span>="<span class="v">https://stendhalgame.org/images/mapmarker/me.png</span>"> <<span class="i">/leaflet-icon</span>>
<<span class="i">leaflet-marker</span> <span class="a">latitude</span>="<span class="v">51.5</span>" <span class="a">longitude</span>="<span class="v">-0.10</span>" <span class="a">title</span>="<span class="v">Element</span>" <span class="a">icon</span>="<span class="v">myicon</span>">
</<span class="i">leaflet-marker</span>>
</code></pre>
<p>Alternatively plain json is understood, too:</p>
<pre class="html"><code>
<<span class="i">leaflet-marker</span> <span class="a">latitude</span>="<span class="v">51.5</span>" <span class="a">longitude</span>="<span class="v">-0.09</span>" <span class="a">title</span>="<span class="v">Icon json</span>"
<span class="a">icon</span>='<span class="v">{"iconUrl": "https://stendhalgame.org/images/mapmarker/dungeon.png"}</span>'>
</<span class="i">leaflet-marker</span>>
</code></pre>
<p>Last but not least, an instance of L.icon may be assigned:</p>
<pre class="html"><code>
<<span class="i">leaflet-marker</span> <span class="a">id</span>="<span class="v">icon-ref</span>" <span class="a">latitude</span>="<span class="v">51.5</span>" <span class="a">longitude</span>="<span class="v">-0.8</span>" <span class="a">title</span>="<span class="v">L.icon()</span>">
</<span class="i">leaflet-marker</span>>
<<span class="i">script</span>>
document.addEventListener("load", function() {
var marker = document.getElementById("icon-ref");
marker.icon = L.icon({
"iconUrl": "https://stendhalgame.org/images/mapmarker/npc.png",
"iconSize": L.point(26, 25),
"iconAnchor": L.point(0, 0)
});
});
</<span class="i">script</span>>
</code></pre>
<h2 id="vector">Circles, polyline and polygons</h2>
<p>Circles, polylines and polygons can be drawn on the map.</p>
<leaflet-map longitude="77.6" latitude="12.95" zoom="12">
<leaflet-polygon color="#f00">
<leaflet-point longitude="77.5700" latitude="12.9700"></leaflet-point>
<leaflet-point longitude="77.6034" latitude="13.0001"></leaflet-point>
<leaflet-point longitude="77.6006" latitude="12.9547"></leaflet-point>
Hi, I am a <b>polygon</b>.
</leaflet-polygon>
<leaflet-circle longitude="77.58" latitude="12.9300"
radius="2000" color="#0a0" fillColor="#aa0" fillopacity="0.5" fill="true">
Hi, I am a <b>circle</b>.
</leaflet-circle>
<leaflet-polyline>
<leaflet-point longitude="77.6400" latitude="12.9100"></leaflet-point>
<leaflet-point longitude="77.6229" latitude="12.9259"></leaflet-point>
<leaflet-point longitude="77.6499" latitude="12.9699"></leaflet-point>
<leaflet-point longitude="77.6119" latitude="12.9738"></leaflet-point>
</leaflet-polyline>
<leaflet-circle longitude="77.64" latitude="12.9300"
radius="500" color="#077">
</leaflet-circle>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">longitude</span>="<span class="v">77.6</span>" <span class="a">latitude</span>="<span class="v">12.95</span>" <span class="a">zoom</span>="<span class="v">12</span>">
<<span class="i">leaflet-polygon</span> <span class="a">color</span>="<span class="v">#f00</span>">
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.5700</span>" <span class="a">latitude</span>="<span class="v">12.9700</span>"> </<span class="i">leaflet-point</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6034</span>" <span class="a">latitude</span>="<span class="v">13.0001</span>"> </<span class="i">leaflet-point</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6006</span>" <span class="a">latitude</span>="<span class="v">12.9547</span>"> </<span class="i">leaflet-point</span>>
Hi, I am a <<span class="i">b</span>>polygon</<span class="i">b</span>>.
</<span class="i">leaflet-polygon</span>>
<<span class="i">leaflet-circle</span> <span class="a">longitude</span>="<span class="v">77.58</span>" <span class="a">latitude</span>="<span class="v">12.93</span>"
<span class="a">radius</span>="<span class="v">2000</span>" <span class="a">color</span>="<span class="v">#0a0</span>" <span class="a">fillColor</span>="<span class="v">#aa0</span>" <span class="a">fillOpacity</span>="<span class="v">0.5</span>" <span class="a">fill</span>="<span class="v">true</span>"
Hi, I am a <<span class="i">b</span>>circle</<span class="i">b</span>>.
</<span class="i">leaflet-circle</span>>
<<span class="i">leaflet-polyline</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6400</span>" <span class="a">latitude</span>="<span class="v">12.9100</span>"> </<span class="i">leaflet-point</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6229</span>" <span class="a">latitude</span>="<span class="v">12.9259</span>"> </<span class="i">leaflet-point</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6499</span>" <span class="a">latitude</span>="<span class="v">12.9699</span>"> </<span class="i">leaflet-point</span>>
<<span class="i">leaflet-point</span> <span class="a">longitude</span>="<span class="v">77.6119</span>" <span class="a">latitude</span>="<span class="v">12.9738</span>"> </<span class="i">leaflet-point</span>>
</<span class="i">leaflet-polyline</span>>
<<span class="i">leaflet-circle</span> <span class="a">longitude</span>="<span class="v">77.64</span>" <span class="a">latitude</span>="<span class="v">12.93</span>"
<span class="a">radius</span>="<span class="v">500</span>" <span class="a">color</span>="<span class="v">#0a0</span>" <span class="a">fillColor</span>="<span class="v">#077</span>">
</<span class="i">leaflet-circle</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="tilelayer">Tile layer</h2>
<p>Custom tile layers, for example from online games can be defined using the leaflet-tilelayer element. If there is no explicit tilelayer defined, a default one will be used as shown in previous examples.</p>
<leaflet-map latitude="78.8" longitude="-96" zoom="5" min-zoom="2" max-zoom="6">
<leaflet-tilelayer
url="https://stendhalgame.org/map/3/{z}-{x}-{y}.png"
min-zoom="2" max-zoom="6" no-wrap>
Map source: <a href="https://stendhalgame.org">Stendhal MMORPG</a>
</leaflet-tilelayer>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">78.8</span>" <span class="a">longitude</span>="<span class="v">-96</span>" <span class="a">zoom</span>="<span class="v">5</span>" <span class="a">max-zoom</span>="<span class="v">6</span>">
<<span class="i">leaflet-tilelayer</span>
<span class="a">url</span>="<span class="v">https://stendhalgame.org/map/3/{z}-{x}-{y}.png</span>"
<span class="a">min-zoom</span>="<span class="v">2</span>" <span class="a">max-zoom</span>="<span class="v">6</span>" <span class="a">noWrap</span>>
Map source: <<span class="i">a</span> <span class="a">href</span>="<span class="v">https://stendhalgame.org</span>">Stendhal MMORPG</<span class="i">a</span>>
</<span class="i">leaflet-tilelayer</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="layerwms">Tile layer WMS</h2>
<p>It is possible to display data from external WMS services as tile layers on the map.</p>
<leaflet-map latitude="40" longitude="-85" zoom="4">
<leaflet-tilelayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" max-zoom="18">
Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,
<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>,
Imagery © <a href="http://mapbox.com">Mapbox</a>
</leaflet-tilelayer>
<leaflet-tilelayer-wms
url="https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi"
layers="nexrad-n0r-900913" format="image/png" transparent opacity="0.5">
Weather data © 2012 IEM Nexrad
</leaflet-tilelayer-wms>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">40</span>" <span class="a">longitude</span>="<span class="v">-85</span>" <span class="a">zoom</span>="<span class="v">4</span>">
<<span class="i">leaflet-tilelayer</span>
<span class="a">url</span>="<span class="v">https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png</span>" <span class="a">max-zoom</span>="<span class="v">19</span>">
Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contr.,
<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>,
Imagery © <a href="http://mapbox.com">Mapbox</a>
</<span class="i">leaflet-tilelayer</span>>
<<span class="i">leaflet-tilelayer-wms</span>
<span class="a">url</span>="<span class="v">https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi</span>"
<span class="a">layers</span>="<span class="v">nexrad-n0r-900913</span>" <span class="a">format</span>="<span class="v">image/png</span>" <span class="a">transparent</span> <span class="a">opacity</span>="<span class="v">0.5</span>">
Weather data © 2012 IEM Nexrad
</<span class="i">leaflet-tilelayer-wms</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="event">Events</h2>
<p>Leaflet events are converted into html events which originate from the component.</p>
<div id="eventout">Center: 51.505, -0.091</div>
<leaflet-map id="eventmap" latitude="51.505" longitude="-0.091" zoom="8"> </leaflet-map>
<script>
var map = document.getElementById("eventmap");
map.addEventListener("moveend", function(e) {
var text = "Center: " + this.latitude.toFixed(3) + ", "
+ this.longitude.toFixed(3);
document.getElementById("eventout").textContent = text;
});
</script>
<pre class="html"><code>
<<span class="i">div</span> <span class="a">id</span>="<span class="v">eventout</span>">Center: 51.505, -0.091</<span class="i">div</span>>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">51.505</span>" <span class="a">longitude</span>="<span class="v">-0.091</span>" <span class="a">zoom</span>="<span class="v">8</span>"> </<span class="i">leaflet-map</span>>
<<span class="i">script</span>>
var map = document.getElementById("eventmap");
map.addEventListener("moveend", function(e) {
var text = "Center: " + this.latitude.toFixed(3)
+ ", " + this.longitude.toFixed(3);
document.getElementById("eventout").textContent = text;
});
</<span class="i">script</span>>
</code></pre>
<h2 id="scale">Scale control</h2>
<p>A scale control can be added and configured using <leaflet-scale-control>. By default it displays both metric and imperial units.</p>
<leaflet-map latitude="51.505" longitude="-0.09" zoom="6">
<leaflet-scale-control position="topright" metric imperial>
</leaflet-scale-control>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">51.505</span>" <span class="a">longitude</span>="<span class="v">-0.09</span>" <span class="a">zoom</span>="<span class="v">13</span>">
<<span class="i">leaflet-scale-control</span> <span class="a">position</span>="<span class="v">topright</span>" <span class="a">metric</span> <span class="a">imperial</span>>
</<span class="i">leaflet-scale-control</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="geojson">GeoJSON</h2>
<p>Example of a GeoJSON layer, which is filled by an ajax request.</p>
<leaflet-map longitude="102.304" latitude="0.3516" zoom="6">
<leaflet-tilelayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" maxZoom="18">
Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,
<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>,
Imagery © <a href="http://mapbox.com">Mapbox</a>
</leaflet-tilelayer>
<template is="dom-bind">
<iron-ajax url="demo-geojson.json" handle-as="json" auto last-response="{{data}}"></iron-ajax>
<leaflet-geojson id="leafletgeojson" color="#FF0000" data="[[data]]"></leaflet-geojson>
</template>
</leaflet-map>
<pre class="html"><code>
<<span class="i">leaflet-map</span> <span class="a">latitude</span>="<span class="v">0.3516</span>" <span class="a">longitude</span>="<span class="v">102.304</span>" <span class="a">zoom</span>="<span class="v">6</span>">
<<span class="i">leaflet-tilelayer</span>
<span class="a">url</span>="<span class="v">https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png</span>" <span class="a">max-zoom</span>="<span class="v">19</span>">
Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contr.,
<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>,
Imagery © <a href="http://mapbox.com">Mapbox</a>
</<span class="i">leaflet-tilelayer</span>>
<<span class="i">template</span> <span class="a">is</span>="<span class="v">dom-bind</span>">
<<span class="i">iron-ajax</span> <span class="a">url</span>="<span class="v">demo-geojson.json</span>" <span class="a">last-response</span>="<span class="v">{{data}}</span>" <span class="a">auto</span>>
</<span class="i">iron-ajax</span>>
<<span class="i">leaflet-geojson</span> <span class="a">color</span>="<span class="v">#FF0000</span>" <span class="a">data</span>="<span class="v">[[data]]</span>"></<span class="i">leaflet-geojson</span>>
</<span class="i">template</span>>
</<span class="i">leaflet-map</span>>
</code></pre>
<h2 id="databinding">Data binding and custom components</h2>
<p>Data binding can be used to create markers based on dynamic information, e. g. from the rows of a spreadsheet.
In this example a new component is created which listens for location tracking information and sets a marker accordingly.
A circle is used to indicate the range of uncertainty.</p>
<button id="advanceddemo-button">Show advanced demo</button>
<div id="advanceddemo-target"></div>
<template id=advanceddemo-template>
<geolocation-sample> </geolocation-sample>
<pre class="html"><code>
<span class="c"><-- define geolocation-sample component --></span>
<<span class="i">dom-module</span> <span class="a">id</span>="<span class="v">geolocation-sample</span>">
<<span class="i">template</span>>
<<span class="i">style</span>>
:host { display: block; overflow: hidden}
:host leaflet-map {height:18em; width:99%; border: none}
</<span class="i">style</span>>
<span class="c"><-- information text above the map --></span>
<<span class="i">template</span> <span class="a">is</span>="<span class="v">dom-if</span>" <span class="a">if</span>="<span class="v">{{!latitude}}</span>">
Location Unknown.
</<span class="i">template</span>>
<<span class="i">template</span> <span class="a">is</span>="<span class="v">dom-if</span>" <span class="a">if</span>="<span class="v">{{latitude}}</span>">
lat: <<span class="i">span</span>>{{latitude}}</<span class="i">span</span>>,
lng: <<span class="i">span</span>>{{longitude}}</<span class="i">span</span>>,
accuracy: <<span class="i">span</span>>{{accuracy}}</<span class="i">span</span>> meter
</<span class="i">template</span>>
<<span class="i">leaflet-map</span>>
<span class="c"><-- request geo-location information --></span>
<<span class="i">leaflet-geolocation</span> <span class="a">enable-high-accuracy</span>
<span class="a">latitude</span>="<span class="v">{{latitude}}</span>" <span class="a">longitude</span>="<span class="v">{{longitude}}</span>" <span class="a">accuracy</span>="<span class="v">{{accuracy}}</span>"
</<span class="i">leaflet-geolocation</span>>
<span class="c"><-- add marker, if location information is available --></span>
<<span class="i">template</span> <span class="a">is</span>="<span class="v">dom-if</span>" <span class="a">if</span>="<span class="v">{{latitude}}</span>">
<<span class="i">leaflet-marker</span> <span class="a">latitude</span>="<span class="v">{{latitude}}</span>" <span class="a">longitude</span>="<span class="v">{{longitude}}</span>">
I am within <<span class="i">span</span>>{{accuracy}}</<span class="i">span</span>> meters of this location.
</<span class="i">leaflet-marker</span>>
<<span class="i">leaflet-circle</span> <span class="a">latitude</span>="<span class="v">{{latitude}}</span>" <span class="a">longitude</span>="<span class="v">{{longitude}}</span>"
<span class="a">radius</span>="<span class="v">{{accuracy}}</span>"<span class="a">color</span>="<span class="v">#d00</span>">
</<span class="i">leaflet-circle</span>>
</<span class="i">template</span>>
</<span class="i">leaflet-map</span>>
</<span class="i">template</span>>
</<span class="i">dom-module</span>>
<<span class="i">script</span>>
Polymer({
is: "geolocation-sample"
});
</<span class="i">script</span>>
<span class="c"><-- use our component --></span>
<<span class="i">geolocation-sample</span>> </<span class="i">geolocation-sample</span>>
</code></pre>
</template>
<script>
document.getElementById("advanceddemo-button").addEventListener("click", function() {
document.getElementById("advanceddemo-button").style.display = "none";
var clone = document.importNode(document.getElementById("advanceddemo-template").content, true);
document.getElementById("advanceddemo-target").appendChild(clone);
});
</script>
</div>
</body>
</html>