question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PolylineDecorator.getBounds() throws error

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bbecquetcommented, Jan 28, 2018

I had some time so I added it myself. It should be fixed in version 1.6.0. Thanks for your help!

0reactions
transducercommented, Aug 29, 2018

Same issue with getLatLng?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found