This repository has been archived by the owner on Dec 11, 2017. It is now read-only.
forked from GNURub/mapbox-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-marker.html
281 lines (240 loc) · 6.38 KB
/
open-marker.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
<!--
The `open-marker` element represents a marker on the map and is used as
a child element of the `open-map` element.
##### Example: Add marker
<style>
open-map {
display: block;
height: 100vh;
}
</style>
<open-map latitude="38.867847"
longitude="1.310977"
geolocationUI
zoom="15"
mapID="examples.map-i875kd35">
<open-marker
icon="{
'iconUrl': 'my-icon.png',
'iconRetinaUrl': '[email protected]',
'iconSize': [38, 95],
'iconAnchor': [22, 94],
'popupAnchor': [-3, -76],
'shadowUrl': 'my-icon-shadow.png',
'shadowRetinaUrl': '[email protected]',
'shadowSize': [68, 95],
'shadowAnchor': [22, 94]
}"
latitude="0"
longitude="0">
</open-marker>
</open-map>
@element open-marker
@blurb Element for putting a marker on the map
@status alpha
@homepage https://ruben96.github.io/open-map/components/open-map/
-->
<polymer-element name="open-marker" attributes="icon title">
<template>
<link
href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"
rel="stylesheet">
<style>
:host {
display: none;
}
</style>
</template>
<script>
(function(){
'use strict';
Polymer( 'open-marker', {
/**
* A Mapbox map object
*
* @property map
* @type L.mapbox.map
* @default null
*/
map: null,
/**
* A Mapbox marker object
*
* @property marker
* @type L.marker
* @default null
*/
marker: null,
/**
* A Mapbox marker object
*
* @attribute title
* @type String
* @default null
*/
title: '',
publish:{
/**
* Latitude marker
*
* @attribute latitude
* @type float
* @default null
*/
latitude: {
value: null,
reflect: true
},
/**
* Longitude marker
*
* @attribute longitude
* @type float
* @default null
*/
longitude: {
value: null,
reflect: true
}
},
observe:{
latitude: 'updateMarker',
longitude: 'updateMarker'
},
created: function () {
this.icon = {};
},
mapReady: function () {
var canUpdate = ( this.map &&
this.latitude &&
this.longitude );
if( canUpdate ) {
if( this.marker ) {
this.map.removeLayer(this.marker);
}
this.marker = L.marker( [ this.latitude, this.longitude ], {
draggable: !!this.getAttribute("draggable"),
title: this.title,
alt: this.title,
icon: this.createIcon()
} ).addTo( this.map );
/**
* Fired when user clicks (or tabs) the marker.
*
* @event click-marker
*/
this.marker.on( 'click', this.sendEvent.bind( this ))
/**
* Fired when user dobleclicks (or doble-tabs) the marker
*
* @event dblclick-marker
*/
.on( 'dblclick', this.sendEvent.bind( this ))
/**
* Fired when the marker is moved via latitude/longitude.
*
* @event move-marker
*/
.on( 'move', this.sendEvent.bind( this ))
/**
* Fired when user starts dragging the marker.
*
* @event dragstart-marker
*/
.on( 'dragstart', this.sendEvent.bind( this ))
/**
* Fired reapetedly while the user drags the marker.
*
* @event drag-marker
*/
.on( 'drag', this.sendEvent.bind( this ))
/**
* Fired when user stops dragging the marker.
*
* @event dragend-marker
*/
.on( 'dragend', this.sendEvent.bind( this ))
/**
* Fired when the marker is added from the map.
*
* @event add-marker
*/
.on( 'add', this.sendEvent.bind( this ))
/**
* Fired when the marker is removed from the map.
*
* @event remove-marker
*/
.on( 'remove', this.sendEvent.bind( this ))
/**
* Fired when popup bound to the marker is open.
*
* @event popupopen-marker
*/
.on( 'popupopen', this.sendEvent.bind( this ))
/**
* Fired when popup bound to the marker is close.
*
* @event popupclose-marker
*/
.on( 'popupclose', this.sendEvent.bind( this ));
}
},
sendEvent: function (e){
this.fire(e.type + '-marker', { data: e } );
},
updateMarker:function(){
var canUpdate = ( this.map &&
this.marker &&
this.latitude &&
this.longitude );
if( canUpdate ){
this.marker.setLatLng( [ this.latitude, this.longitude ] );
}else if( !this.marker ){
this.mapReady();
}
},
iconChanged:function(){
if( !!this.marker ) {
this.marker.setIcon(this.createIcon());
}else{
this.mapReady();
}
},
createIcon:function () {
this.icon['marker-symbol'] ||
(this.icon['marker-symbol'] = this.icon.icon);
this.icon['marker-size'] ||
(this.icon['marker-size'] = this.icon.size);
this.icon['marker-color'] ||
(this.icon['marker-color'] = this.icon.markerColor);
return L.mapbox.marker.icon( this.icon );
},
mapChanged: function () {
this.mapReady();
},
contentChanged: function () {
this.onMutation( this, this.contentChanged );
var content = this.innerHTML;
if( content ){
this.marker.bindPopup( content );
}
},
attributeChanged: function() {
if (!this.marker) {
return;
}
},
/**
* Delete the layer.
*
* @method removeLayer
*/
removeLayer: function() {
this.map.removeLayer(this.marker);
this.remove();
}
} );
})();
</script>
</polymer-element>