Skip to content

Commit

Permalink
changes not work
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocudini committed Sep 24, 2018
1 parent 2698e6c commit 6034a16
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 40 deletions.
4 changes: 2 additions & 2 deletions examples/reload-layer.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h4>Reload Layer Example: reload GeoJSON layer at runtime</h4>
<pre id="selection">&nbsp;</pre>

<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../node_modules/leaflet/dist/leaflet.js"></script>
<script src="../node_modules/leaflet/dist/leaflet-src.js"></script>
<script src="../src/leaflet-geojson-selector.js"></script>
<script>

Expand All @@ -75,10 +75,10 @@ <h4>Reload Layer Example: reload GeoJSON layer at runtime</h4>
map.removeLayer(geoLayer);

geoLayer = L.geoJson(json).addTo(map);
map.fitBounds( geoLayer.getBounds() );

geoList.reload( geoLayer );
});

}).trigger('change');

</script>
Expand Down
5 changes: 1 addition & 4 deletions examples/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ <h4>Simple Example: <em>Italian regions</em></h4>

geoLayer = L.geoJson(json).addTo(map);

map.fitBounds( geoLayer.getBounds() )
.setMaxBounds( geoLayer.getBounds().pad(0.5) );

geoList = new L.Control.GeoJSONSelector(geoLayer, {
//zoomToLayer: true,
zoomToLayer: true,
activeListFromLayer: true,
activeLayerFromList: true,
listOnlyVisibleLayers: true
Expand Down
83 changes: 49 additions & 34 deletions src/leaflet-geojson-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ L.Control.GeoJSONSelector = L.Control.extend({
},

onRemove: function(map) {
map.off('moveend', this._updateList, this);
map.off('moveend', this._updateListVisible, this);
},

reload: function(layer) {
Expand Down Expand Up @@ -258,10 +258,9 @@ L.Control.GeoJSONSelector = L.Control.extend({
_updateList: function() {

var self = this,
layers = [],
sortProp = this.options.listSortBy;
layers = [];

//TODO SORTby
if(!this._layer) return;

//this._list.style.minWidth = '';
this._list.innerHTML = '';
Expand All @@ -272,47 +271,63 @@ L.Control.GeoJSONSelector = L.Control.extend({
if(layer.setStyle)
layer.setStyle( self.options.style );


layer
.on('click', L.DomEvent.stop)
.on('click', function(e) {
e.target.itemLabel.click();
})
.on('mouseover', function(e) {
e.target.setStyle( self.options.activeStyle );

if(self.options.activeListFromLayer)
L.DomUtil.addClass(e.target.itemList, self.options.activeClass);
})
.on('mouseout', function(e) {
e.target.setStyle(e.target.itemList.selected ? self.options.selectStyle : self.options.style );

if(self.options.activeListFromLayer)
L.DomUtil.removeClass(e.target.itemList, self.options.activeClass);
});
layer
.on('click', L.DomEvent.stop)
.on('click', function(e) {
e.target.itemLabel.click();
})
.on('mouseover', function(e) {
e.target.setStyle( self.options.activeStyle );

if(self.options.activeListFromLayer)
L.DomUtil.addClass(e.target.itemList, self.options.activeClass);
})
.on('mouseout', function(e) {
e.target.setStyle(e.target.itemList.selected ? self.options.selectStyle : self.options.style );

if(self.options.activeListFromLayer)
L.DomUtil.removeClass(e.target.itemList, self.options.activeClass);
});

});

layers.sort(function(a, b) {
var ap = self._getPath(a.feature, sortProp),
bp = self._getPath(b.feature, sortProp);

if(ap < bp)
return -1;
if(ap > bp)
return 1;
return 0;
});
if(this.options.listSortBy) {
layers.sort(function(a, b) {
var sortProp = self.options.listSortBy,
ap = self._getPath(a.feature, sortProp),
bp = self._getPath(b.feature, sortProp);

if(ap < bp)
return -1;
if(ap > bp)
return 1;
return 0;
});
}

for (var i=0; i<layers.length; i++)
for(var i=0; i<layers.length; i++) {
this._list.appendChild( this._createItem( layers[i] ) );
}


if(this._map.hasLayer(this._layer)) {

this._layerbb = this._layer.getBounds();

console.log('_updateList map has layer', this._layer, this._layerbb)

this._map.setMaxBounds( this._layerbb.pad(0.5) );
this._map.fitBounds(this._layerbb);
}
},

_updateListVisible: function() {

var self = this,
layerbb, visible;


if(!this._layer) return;

this._layer.eachLayer(function(layer) {

if(layer.getBounds)
Expand Down

0 comments on commit 6034a16

Please sign in to comment.