Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion leaflet-core.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@
},

detached: function() {
this._mutationObserver.disconnect();
if(this._mutationObserver)
this._mutationObserver.disconnect();
},

_viewChanged: function(newValue, oldValue) {
Expand Down
28 changes: 19 additions & 9 deletions leaflet-layer-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

##### Example

<leaflet-layer-group>
<leaflet-marker latitude="51.505" longitude="-0.09"> </leaflet-marker>
</leaflet-layer-group>
<leaflet-layer-group>
<leaflet-marker latitude="51.505" longitude="-0.09"> </leaflet-marker>
</leaflet-layer-group>


@element leaflet-layer-group
Expand All @@ -17,7 +17,7 @@
-->

<dom-module id="leaflet-layer-group">
<template>
<template><content></content>
</template>
</dom-module>

Expand All @@ -31,27 +31,37 @@
container: {
type: Object,
observer: '_containerChanged'
}
},
fitMapToBounds : {
type: Boolean,
value: false
}
},

ready: function() {
resetMutationObserver : function() {
this._mutationObserver = new MutationObserver(this.registerContainerOnChildren.bind(this));
this._mutationObserver.observe(this, {childList: true});
},

_containerChanged: function() {
if (this.container) {
var feature = L.layerGroup()
var feature = L.layerGroup();
this.feature = feature;
this.feature.addTo(this.container);
this.registerContaierOnChildren();
this.registerContainerOnChildren();
}
},

registerContaierOnChildren: function() {
registerContainerOnChildren: function() {
this.resetMutationObserver();
for (var i = 0; i < this.children.length; i++) {
this.children[i].container = this.feature;
}
if(this.fitMapToBounds && this.container!=null && this.feature!=null) {
var layers = this.feature.getLayers();
if(layers.length>0)
this.container.fitBounds(L.featureGroup(layers).getBounds());
}
},

detached: function() {
Expand Down