forked from leaflet-extras/leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-draw.html
624 lines (541 loc) · 15.1 KB
/
leaflet-draw.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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<link rel="import" href="leaflet-core.html">
<link rel="import" href="leaflet-popup.html">
<!--
element which defines am abstract leaflet path (<a href="http://leafletjs.com/reference.html#path">Leaflet Reference</a>).
Do not use this element directly.
@element leaflet-path
@blurb element which defines am abstract leaflet path. Do not use directly. Most options are supported as attributes.
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<script>
"use strict";
var leafletMap = leafletMap || {};
window.leafletMap.LeafletPath = {
/**
* Fired when the user clicks (or taps) the object.
*
* @event click
* @type MouseEvent
* @param {LatLng} latlng The geographical point where the mouse event occured.
* @param {Point} layerPoint Pixel coordinates of the point where the mouse event occured relative to the map layer.
* @param {Point} containerPoint Pixel coordinates of the point where the mouse event occured relative to the map сontainer.
* @param {DOMMouseEvent} originalEvent The original DOM mouse event fired by the browser.
*/
/**
* Fired when the user double-clicks (or double-taps) the object.
*
* @event dblclick
* @type MouseEvent
* @param {LatLng} latlng The geographical point where the mouse event occured.
* @param {Point} layerPoint Pixel coordinates of the point where the mouse event occured relative to the map layer.
* @param {Point} containerPoint Pixel coordinates of the point where the mouse event occured relative to the map сontainer.
* @param {DOMMouseEvent} originalEvent The original DOM mouse event fired by the browser.
*/
/**
* Fired when the user pushes the mouse button on the object.
*
* @event mousedown
* @type MouseEvent
* @param {LatLng} latlng The geographical point where the mouse event occured.
* @param {Point} layerPoint Pixel coordinates of the point where the mouse event occured relative to the map layer.
* @param {Point} containerPoint Pixel coordinates of the point where the mouse event occured relative to the map сontainer.
* @param {DOMMouseEvent} originalEvent The original DOM mouse event fired by the browser.
*/
/**
* Fired when the mouse enters the object.
*
* @event mouseover
* @type MouseEvent
* @param {LatLng} latlng The geographical point where the mouse event occured.
* @param {Point} layerPoint Pixel coordinates of the point where the mouse event occured relative to the map layer.
* @param {Point} containerPoint Pixel coordinates of the point where the mouse event occured relative to the map сontainer.
* @param {DOMMouseEvent} originalEvent The original DOM mouse event fired by the browser.
*/
/**
* Fired when the mouse leaves the object.
*
* @event mouseout
* @type MouseEvent
* @param {LatLng} latlng The geographical point where the mouse event occured.
* @param {Point} layerPoint Pixel coordinates of the point where the mouse event occured relative to the map layer.
* @param {Point} containerPoint Pixel coordinates of the point where the mouse event occured relative to the map сontainer.
* @param {DOMMouseEvent} originalEvent The original DOM mouse event fired by the browser.
*/
/**
* Fired when the user right-clicks on the object.
*
* @event contextmenu
* @type MouseEvent
*/
/**
* Fired when the object is added to the map.
*
* @event add
* @type
*/
/**
* Fired when the object is removed from the map.
*
* @event remove
*/
/**
* Fired when a popup bound to the object is open.
*
* @event popupopen
* @type PopupEvent
* @param {Popup} popup The popup that was opened or closed.
*/
/**
* Fired when a popup bound to the object is closed.
*
* @event popupclose
* @type PopupEvent
* @param {Popup} popup The popup that was opened or closed.
*/
properties: {
/**
* The attribute `stroke` sets whether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
*
* @attribute stroke
* @type boolean
*/
noStroke: {
type: Boolean,
value: false
},
/**
* The attribute `color` sets the stroke color.
*
* @attribute color
* @type string
*/
color: {
type: String,
value: "#03f"
},
/**
* The attribute `weight` sets the stroke width in pixels.
*
* @attribute weight
* @type number
*/
weight: {
type: Number,
value: 5
},
/**
* The attribute `opacity` sets the stroke opacity.
*
* @attribute opacity
* @type number
*/
opacity: {
type: Number,
value: 0.5
},
/**
* The attribute `fill` sets the whether to fill the path with color. Set it to false to disable filling on polygons or circles.
*
* @attribute fill
* @type boolean
*/
fill: {
type: Boolean,
value: null
},
/**
* The attribute `fill-color` sets the fill color.
*
* @attribute fill-color
* @type string
*/
fillColor: {
type: String,
value: null
},
/**
* The attribute `fill-opacity` sets the fill opacity.
*
* @attribute fill-opacity
* @type number
*/
fillOpacity: {
type: Number,
value: 0.2
},
/**
* The attribute `dash-array` sets a string that defines the stroke dash pattern. Doesn't work on canvas-powered layers (e.g. Android 2).
*
* @attribute dash-array
* @type string
*/
dashArray: {
type: String,
value: null
},
/**
* The attribute `line-cap` defines the shape to be used at the end of the stroke.
*
* @attribute line-cap
* @type string
*/
lineCap: {
type: String,
value: null
},
/**
* The attribute `line-join` sets the string that defines shape to be used at the corners of the stroke.
*
* @attribute line-join
* @type string
*/
lineJoin: {
type: String,
value: null
},
/**
* The attribute `clickable` sets whether the vector will emit mouse events or will act as a part of the underlying map.
*
* @attribute clickable
* @type boolean
*/
noClickable: {
type: Boolean,
value: false
},
/**
* The attribute `pointer-events` sets the pointer-events attribute on the path if SVG backend is used.
*
* @attribute pointer-events
* @type string
*/
pointerEvents: {
type: String,
value: null
},
/**
* The attribute `class-name` sets the custom class name set on an element.
*
* @attribute class-name
* @type string
*/
className: {
type: String,
value: ""
}
},
getPathOptions: function() {
return {
stroke: !this.noStroke,
color: this.color,
weight: this.weight,
opacity: this.opacity,
fill: this.fill,
fillColor: this.fillColor,
fillOpacity: this.fillOpacity,
dashArray: this.dashArray,
lineCap: this.lineCap,
lineJoin: this.lineJoin,
clickable: !this.noClickable,
pointerEvents: this.pointerEvents,
className: this.className,
};
}
};
window.leafletMap.LeafletPointContent = {
attached: function() {
if (MutationObserver && !this.observer_) {
this.observer_ = new MutationObserver(this.updatePointContent.bind(this));
this.observer_.observe(this, {childList: true, characterData: true, attributes: true, subtree: true});
}
},
updatePointContent: function() {
if (!this.feature) {
return;
}
var temp = [];
var i;
var nodes = this.children;
for (i = 0; i < nodes.length; i++) {
if (nodes[i].localName == "leaflet-point") {
temp.push(L.latLng(
nodes[i].getAttribute('latitude'),
nodes[i].getAttribute('longitude')
));
}
}
this.feature.setLatLngs(temp);
},
detached: function() {
if (this.observer_) {
this.observer_.disconnect();
}
}
}
</script>
<!--
The `leaflet-circle` element represents a circle on the map and is used as
a child element of the `leaflet-map` element.
##### Example: Add circles
<leaflet-map longitude="77.2" latitude="28.4" zoom="12">
<leaflet-circle longitude="77.2" latitude="28.4" radius="300">
Circle
</leaflet-circle>
</leaflet-map>
@element leaflet-circle
@blurb Element for putting a circle on the map
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-circle">
<style>
:host{ display: none; }
</style>
<template>
</template>
</dom-module>
<script>
"use strict";
Polymer({
is: 'leaflet-circle',
/**
* A Leaflet circle object
*
* @property feature
* @type L.circle
* @default null
*/
feature: null,
behaviors: [leafletMap.LeafletPath, leafletMap.LeafletPopupContent],
properties: {
/**
* The circle's longitude coordinate
*
* @attribute longitude
* @type number
* @default null
*/
longitude: {
type: Number,
observer: '_updatePosition'
},
/**
* The circle's latitude coordinate
*
* @attribute latitude
* @type number
* @default null
*/
latitude: {
type: Number,
observer: '_updatePosition'
},
/**
* The circle's radius is metres
*
* @attribute radius
* @type number
* @default 100
*/
radius: {
type: Number,
value: 100,
observer: '_updateRadius'
},
container: {
type: Object,
observer: '_containerChanged'
}
},
_containerChanged: function() {
if (this.latitude && this.longitude && this.container) {
this.feature = L.circle([this.latitude, this.longitude], this.radius, this.getPathOptions());
this.feature.addTo(this.container);
this.updatePopupContent();
// forward events
this.feature.on('click dblclick mousedown mouseover mouseout contextmenu add remove popupopen popupclose', function(e) {
this.fire(e.type, e);
}, this);
}
},
_updatePosition: function () {
if (this.feature && this.latitude != null && this.longitude != null) {
this.feature.setLatLng(L.latLng( this.latitude, this.longitude) );
}
},
_updateRadius: function () {
if (this.feature && this.radius != null) {
this.feature.setRadius(this.radius);
}
},
detached: function() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
}
});
</script>
<!--
The `leaflet-point` element represents one point in an polyline on the map and is used as
a child element of the `leaflet-polyline` element.
##### Example: Add polylines
<leaflet-map longitude="77.2" latitude="28.4" zoom="12">
<leaflet-polyline>
<leaflet-point longitude="77.22" latitude="28.44"></leaflet-point>
<leaflet-point longitude="77.44" latitude="28.66"></leaflet-point>
</leaflet-polyline>
</leaflet-map>
@element leaflet-point
@blurb Element for adding a point to a polyline
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-point">
<script>
Polymer({
is: "leaflet-point",
properties: {
latitude: {
type: Number,
value: 0,
reflectToAttribute:true
},
longitude: {
type: Number,
value: 0,
reflectToAttribute:true
}
}
});
</script>
</dom-module>
<!--
The `leaflet-polyline` element represents a polyline on the map and is used as
a child element of the `leaflet-map` element. To compose the line one needs to
add `leaflet-point` elements inside it.
##### Example: Add polylines
<leaflet-map longitude="77.2" latitude="28.4" zoom="12">
<leaflet-polyline>
<leaflet-point longitude="77.22" latitude="28.44"></leaflet-point>
<leaflet-point longitude="77.44" latitude="28.66"></leaflet-point>
</leaflet-polyline>
</leaflet-map>
@element leaflet-polyline
@blurb Element for putting a polyline on the map
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-polyline">
<style>
:host{ display: none; }
</style>
<template>
<content id="points" select="leaflet-point"></content>
</template>
</dom-module>
<script>
"use strict";
Polymer({
is: 'leaflet-polyline',
behaviors: [leafletMap.LeafletPath, leafletMap.LeafletPointContent, leafletMap.LeafletPopupContent],
/**
* A Leaflet [Polyline](http://leafletjs.com/reference.html#polyline) object
*
* @property feature
* @type L.polyline
* @default null
*/
feature: null,
properties: {
container: {
type: Object,
observer: '_containerChanged'
}
},
_containerChanged: function() {
if (this.container) {
this.feature = L.polyline([], this.getPathOptions());
this.feature.addTo( this.container );
this.updatePointContent();
this.updatePopupContent();
// forward events
this.feature.on('click dblclick mousedown mouseover mouseout contextmenu add remove popupopen popupclose', function(e) {
this.fire(e.type, e);
}, this);
}
},
detached: function() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
}
});
</script>
<!--
The `leaflet-polygon` element represents a polygon on the map and is used as
a child element of the `leaflet-map` element. To compose the line one needs to
add `leaflet-point` elements inside it.
##### Example: Add polygona
<leaflet-map longitude="77.2" latitude="28.4" zoom="12">
<leaflet-polygon>
<leaflet-point longitude="77.1000" latitude="13.3400"></leaflet-point>
<leaflet-point longitude="77.5000" latitude="13.5500"></leaflet-point>
<leaflet-point longitude="77.7200" latitude="12.7200"></leaflet-point>
</leaflet-polygon>
</leaflet-map>
@element leaflet-polygon
@blurb Element for putting a polygon on the map
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-polygon">
<style>
:host {display: none;}
</style>
<template>
<content id="points" select="leaflet-point"></content>
</template>
</dom-module>
<script>
"use strict";
Polymer({
is: 'leaflet-polygon',
behaviors: [leafletMap.LeafletPath, leafletMap.LeafletPointContent, leafletMap.LeafletPopupContent],
properties: {
container: {
type: Object,
observer: '_containerChanged'
}
},
/**
* A Leaflet [Polygon](http://leafletjs.com/reference.html#polygon) object
*
* @property feature
* @type L.polygon
* @default null
*/
feature: null,
_containerChanged: function() {
if (this.container) {
var opt = this.getPathOptions();
if (typeof opt.fill === "undefined" || opt.fill === null) {
opt.fill = true;
}
this.feature = L.polygon([], opt);
this.feature.addTo(this.container);
this.updatePointContent();
this.updatePopupContent();
// forward events
this.feature.on('click dblclick mousedown mouseover mouseout contextmenu add remove popupopen popupclose', function(e) {
this.fire(e.type, e);
}, this);
}
},
detached: function() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
}
});
</script>