forked from unicef-polymer/etools-leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-layer-group.html
67 lines (54 loc) · 1.5 KB
/
leaflet-layer-group.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
<link rel="import" href="leaflet-core.html">
<!--
A Layer group (<a href="http://leafletjs.com/reference.html#layergroup">Leaflet Reference</a>).
##### Example
<leaflet-layer-group>
<leaflet-marker latitude="51.505" longitude="-0.09"> </leaflet-marker>
</leaflet-layer-group>
@element leaflet-layer-group
@blurb an element which represents a layer group
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-layer-group">
<template>
</template>
<script>
'use strict';
class LeafletLayerGroup extends Polymer.Element {
static get is() { return 'leaflet-layer-group'; }
static get properties() {
return {
container: {
type: Object,
observer: '_containerChanged'
}
};
}
ready() {
super.ready();
this._mutationObserver = new MutationObserver(this.registerContainerOnChildren.bind(this));
this._mutationObserver.observe(this, { childList: true });
}
_containerChanged() {
if (this.container) {
var feature = L.layerGroup();
this.feature = feature;
this.feature.addTo(this.container);
this.registerContaierOnChildren();
}
}
registerContaierOnChildren() {
for (var i = 0; i < this.children.length; i++) {
this.children[i].container = this.feature;
}
}
disconnectedCallback() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
this._mutationObserver.disconnect();
}
}
</script>
</dom-module>