forked from leaflet-extras/leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-layer-group.html
64 lines (51 loc) · 1.43 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
<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>
</dom-module>
<script>
"use strict";
Polymer({
is: 'leaflet-layer-group',
properties: {
container: {
type: Object,
observer: '_containerChanged'
}
},
ready: function() {
this._mutationObserver = new MutationObserver(this.registerContainerOnChildren.bind(this));
this._mutationObserver.observe(this, {childList: true});
},
_containerChanged: function() {
if (this.container) {
var feature = L.layerGroup()
this.feature = feature;
this.feature.addTo(this.container);
this.registerContainerOnChildren();
}
},
registerContainerOnChildren: function() {
for (var i = 0; i < this.children.length; i++) {
this.children[i].container = this.feature;
}
},
detached: function() {
if (this.container && this.feature) {
this.container.removeLayer(this.feature);
}
this._mutationObserver.disconnect();
}
});
</script>