PolylineDecorator.getBounds() throws error
See original GitHub issueI’ve run into an issue when trying to find the bounds of a PolylineDecorator
.
Since PolylineDecorator
is a FeatureGroup
, it has getBounds
method.
That method will try to iterate all of its layers and call getBounds
or getLatLng
on those.
But because the child layers are instances of LayerGroup
, they do not have either method, and so a TypeError: e.getLatLng is not a function
error is thrown.
Since the 1.3.0 release the bounds of the child layers would not even be the real bounds of a PolylineDecorator
- the closest we could get now is the bound of its paths.
These changes work for my use-case, I could make a PR of them, if it would get merged:
L.PolylineDecorator = L.FeatureGroup.extend({
/* ... */
setPaths: function(paths) {
/* ... */
this._bounds = this._initBounds();
},
initialize: function(paths, options) {
/* ... */
this._bounds = this._initBounds();
},
_initBounds: function () {
var bounds = L.latLngBounds(this._paths[0]);
for (var i = 1; i < this._paths.length; ++i) {
bounds.extends(L.latLngBounds(this._paths[i]))
}
return bounds;
},
getBounds: function () {
return this._bounds;
}
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
leaflet getBounds() errors - Stack Overflow
I created a featuregroup with var group = new L.featureGroup(); then added markers to it in the loop by using marker.addTo(group); this pushed ......
Read more >Plugins - Leaflet - a JavaScript library for ... - GitHub Pages
A modest library for translating between Well-Known Text (WKT) and Leaflet geometry objects (e.g. between L.marker() instances and "POINT()" strings). K. Arthur ...
Read more >Plugins - Leaflet - a JavaScript library for interactive maps
A modest library for translating between Well-Known Text (WKT) and Leaflet geometry objects (e.g. between L.marker() instances and “POINT()” strings).
Read more >Mappls Interactive Map JavaScript API Documentation for ...
In the JavaScript of Map Initialization section of getting started you would ... 9, getBounds(), Gets the Bounds of the current viewing section...
Read more >2fb5fde367cd583b5487544aa52...
linkFile, function(error, links) { if (error) throw error; var valueMin ... var weightColors = d3.scale.ordinal() .domain([vizConfig.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had some time so I added it myself. It should be fixed in version 1.6.0. Thanks for your help!
Same issue with
getLatLng
?