forked from prtksxna/leaflet-map-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet-rectangle-component.html
106 lines (92 loc) · 2.38 KB
/
leaflet-rectangle-component.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
<!--
The `leaflet-rectangle` element represents a rectangle on the map and is used as
a child element of the `leaflet-map` element.
##### Example: Add Rectangles
<leaflet-map longitude="77.2" latitude="28.4" zoom="12">
<leaflet-rectangle topleft="[54.559322, -5.767822]" bottomright="[56.1210604, -3.021240]">
Rectangle
</leaflet-rectangle>
</leaflet-map>
@element leaflet-rectangle
@blurb Element for putting a rectangle on the map
@status alpha
@homepage http://prtksxna.github.io/leaflet-map-component/components/leaflet-map-component/
-->
<link rel="import" href="leaflet-import.html">
<polymer-element name="leaflet-rectangle" attributes="topleft bottomright">
<template>
<style>
:host{ display: none; }
</style>
</template>
<script>
Polymer( 'leaflet-rectangle', {
/**
* A Leaflet rectangle object
*
* @property feature
* @type L.rectangle
* @default null
*/
feature: null,
/**
* A Leaflet map object
*
* @property map
* @type L.map
* @default null
*/
map: null,
publish: {
/**
* The rectangle's top-left bound
*
* @attribute topleft
* @type Array
* @default null
*/
topleft: { value: [], reflect: true },
/**
* The rectangle's bottom-right bound
*
* @attribute bottomright
* @type Array
* @default null
*/
bottomright: { value: [], reflect: true },
},
observe: {
toplet: 'updatePosition',
bottomright: 'updatePosition',
},
ready: function () {
this.mapReady();
},
mapChanged: function () {
this.mapReady();
},
mapReady: function () {
if ( this.topleft && this.bottomright && this.map ) {
this.feature = L.rectangle( [ this.topleft, this.bottomright ] );
this.feature.addTo( this.map );
this.contentChanged();
}
},
updatePosition: function () {
if ( this.feature && this.topleft != null && this.bottomright != null ) {
this.feature.setBounds(
L.latLngBounds(
L.latLng( this.topleft ),
L.latLng( this.bottomright )
)
);
}
},
contentChanged: function () {
this.onMutation( this, this.contentChanged );
var content = this.innerHTML;
this.feature.bindPopup( content );
}
} );
</script>
</polymer-element>