forked from unicef-polymer/etools-leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-geojson.html
196 lines (173 loc) · 4.06 KB
/
leaflet-geojson.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
<link rel="import"
href="../polymer/polymer.html">
<link rel="import"
href="leaflet-import.html">
<link rel="import"
href="leaflet-layer.html">
<!--
A GeoJson layer (<a href="http://leafletjs.com/reference.html#geojson">Leaflet Reference</a>).
##### Example
<leaflet-map longitude="-104.99404" latitude="39.75621" zoom="12">
<leaflet-geojson
data="{{ {'type': 'Feature', 'properties': {'name': 'Coors Field','popupContent': 'Yo popup'},'geometry': {'type': 'Point','coordinates': [-104.99404, 39.75621]}}}}">
</leaflet-geojson>
</leaflet-map>
@element leaflet-geojson
@blurb an element which represents a geojson layer
@status beta
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-element name="leaflet-geojson">
<template>
<style>
:host {
display: none;
}
</style>
</template>
<script>
'use strict';
class LeafletGeojson extends leafletMap.Mixins.LeafletILayer(Polymer.Element) {
static get is() { return 'leaflet-geojson'; }
static get properties() {
return {
/**
* data as geojson object
*
* @property data
* @type Object
*/
data: {
type: Object,
observer: '_dataChanged'
},
container: {
type: Object,
observer: '_containerChanged'
},
/**
/**
* 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
}
};
}
_containerChanged() {
if (this.container && this.data) {
this._dataChanged();
}
}
_dataChanged() {
if (this.container && this.data) {
if (this.feature) {
this.container.removeLayer(this.feature);
}
this.feature = L.geoJson(this.data);
this.feature.addTo(this.container)
.setStyle({
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
});
}
}
disconnectedCallback() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
}
}
</script>
</dom-element>