forked from eva-hafermalz/gn-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgn-map.html
238 lines (209 loc) · 6.59 KB
/
gn-map.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-map/google-map.html">
<link rel="import" href="../google-map/google-map-poly.html">
<link rel="import" href="../google-map/google-map-point.html">
<link rel="import" href="../google-map/google-map-marker.html">
<link rel="import" href="../osm-map/osm-map.html">
<link rel="import" href="../osm-map/osm-poly.html">
<link rel="import" href="../osm-map/osm-point.html">
<link rel="import" href="../osm-map/osm-marker.html">
<!--
The `gn-map` element provides a wrapper for different map types.
If attribute map-type change, the changes will apply to all child elements.
At this time `gn-map` supports `google-map` and `osm-map` and all
children like polygons, points and markers.
Examples:
<gn-map
longitude="9.45"
latitude="38.24"
zoom="13"
map-type="GoogleMap">
</gn-map>
<gn-map
longitude="9.45"
latitude="38.24"
zoom="13"
map-type="OpenStreetMap">
</gn-map>
By default `map-type="GoogleMap"`
@demo
-->
<dom-module id="gn-map">
<template>
<style>
:host {
display: block;
width: 100%;
height: 100%;
}
</style>
<template id="osmMap" is="dom-if" if="{{_typeIsOpenStreetMap(mapType)}}">
<osm-map longitude="{{longitude}}" latitude="{{latitude}}" zoom="{{zoom}}">
<template is="dom-repeat" items="{{polygons}}">
<osm-poly fill-opacity="{{item.fillOpacity}}" stroke-color$="{{item.strokeColor}}" width$="{{item.width}}" closed$="{{item.closed}}" fill-color$="{{item.fillColor}}">
<template is="dom-repeat" items="{{item.points}}">
<osm-point longitude$="{{item.longitude}}" latitude$="{{item.latitude}}"></osm-point>
</template>
</osm-poly>
</template>
<template is="dom-repeat" items="{{markers}}">
<osm-marker longitude$="{{item.longitude}}" latitude$="{{item.latitude}}"></osm-marker>
</template>
</osm-map>
</template>
<template id="googleMap" is="dom-if" if="{{_typeIsGoogleMap(mapType)}}">
<google-map longitude="{{longitude}}" latitude="{{latitude}}" zoom="{{zoom}}">
<template is="dom-repeat" items="{{polygons}}">
<google-map-poly fill-opacity="{{item.fillOpacity}}" stroke-color$="{{item.strokeColor}}" width$="{{item.width}}" closed$="{{item.closed}}" fill-color$="{{item.fillColor}}">
<template is="dom-repeat" items="{{item.points}}">
<google-map-point longitude$="{{item.longitude}}" latitude$="{{item.latitude}}"></google-map-point>
</template>
</google-map-poly>
</template>
<template is="dom-repeat" items="{{markers}}">
<google-map-marker longitude$="{{item.longitude}}" latitude$="{{item.latitude}}"></google-map-marker>
</template>
</google-map>
</template>
<content></content>
</template>
<script>
Polymer({
is: 'gn-map',
properties: {
/**
* A latitude to center the map on.
*/
latitude: {
type: Number,
notify: true,
value: 53.834089,
reflectToAttribute: true
},
/**
* A longitude to center the map on.
*/
longitude: {
type: Number,
notify: true,
value: 10.703718,
reflectToAttribute: true
},
/**
* A zoom level which will be applied to the map.
*/
zoom: {
type: Number,
value: 11,
notify: true,
reflectToAttribute: true
},
/**
* The map-type is bind by dom-if template to include different type of maps
* Possible values are "GoogleMap" or "OpenStreetMap".
*/
mapType: {
type: String,
value:"GoogleMap",
notify: true
},
/**
* Holds the map object and allows to modify values during runtime
*/
map: {
type: Object
},
/**
* Array of polygon objects
*/
polygons: {
type: Array,
notify: true,
value: function () {
return [];
}
},
/**
* Array of Marker objects
*/
markers: {
type: Array,
notify: true,
value: function () {
return [];
}
},
/**
* Array of user created Polygons
*/
_userPolygons: {
type: Array,
notify: true,
value: function () {
return [];
}
},
/**
* Array of user created Markers
*/
_userMarkers: {
type: Array,
notify: true,
value: function () {
return [];
}
}
},
attached: function () {
var self = this;
this.addEventListener('update-gn-map', function () {
self.splice('polygons', -1);
self.splice('markers', -1);
self.queryAllEffectiveChildren('gn-poly').forEach(function (polygon) {
self.push('polygons', polygon.asObject());
});
self._userPolygons.forEach(function (polygon) {
self.push('polygons', polygon);
});
self.queryAllEffectiveChildren('gn-marker').forEach(function (marker) {
self.push('markers', marker.asObject());
});
self._userMarkers.forEach(function (marker) {
self.push('markers', marker);
});
});
},
addPolygon: function (points, strokeColor, width, closed, fillColor, fillOpacity) {
points = (typeof points === 'undefined') ? [] : points;
strokeColor = (typeof strokeColor === 'undefined') ? '#0091ea' : strokeColor;
width = (typeof width === 'undefined') ? 4 : width;
closed = (typeof closed === 'undefined') ? false : closed;
fillColor = (typeof fillColor === 'undefined') ? '#00960a' : fillColor;
fillOpacity = (typeof fillOpacity === 'undefined') ? '0.5' : fillOpacity;
polygon = {
strokeColor: strokeColor,
width: width,
closed: closed,
fillColor: fillColor,
points : points,
fillOpacity : fillOpacity
}
this.push('_userPolygons', polygon);
this.fire('update-gn-map');
},
addMarker: function (latitude, longitude) {
this.push('_userMarkers', {
longitude: Number(longitude),
latitude: Number(latitude)
});
this.fire('update-gn-map');
},
_typeIsOpenStreetMap: function (mapType) {
return mapType === 'OpenStreetMap';
},
_typeIsGoogleMap: function (mapType) {
return mapType === 'GoogleMap';
}
});
</script>
</dom-module>