arthur-e / Wicket

A modest library for moving between Well-Known Text (WKT) and various framework geometries
https://arthur-e.github.io/Wicket/
Other
586 stars 226 forks source link

MULTIPOLYGON creation not working in Leaflet 1.0 #95

Closed ekbarber closed 7 years ago

ekbarber commented 7 years ago

With the release of Leaflet 1.0, L.multiPolygon is no longer a function, and therefore an error is thrown when Wicket is parsing a MULTIPOLYGON (L.multiPolygon is not a function).

It appears the new way to create a Multipolygon is to pass a multidimensional array to L.polygon (http://leafletjs.com/reference-1.0.0.html#polygon).

arthur-e commented 7 years ago

Thanks for reporting this. Can you recommend a solution that is also backwards compatible? Or is object/ feature detection the way to go here?

ekbarber commented 7 years ago

@arthur-e Depends on how backwards compatible you'd like to be. If it's just with 0.7.7, you could use L.version to check if it's 0.7.7 or not. But that'll get complicated if you want to allow for versions prior to 0.7.7.

or you could, as you suggested, simply check if L.multiPolygon exists first, and if so, use that, otherwise use L.polygon.

Note that we'll likely have to take a similar approach for multiPolyline, as it looks like it too has been removed in 1.0.0

crash-dive commented 7 years ago

I can confirm that the fixes above work. I have just monkey patched our install until a fix is ready by doing:

Wkt.Wkt.prototype.construct.multipolygon = function (config) {
    // Truncate the coordinates to remove the closing coordinate
    var coords = this.trunc(this.components),
        latlngs = this.coordsToLatLngs(coords, 2);

    if (L.multiPolyline)
    {
        return L.multiPolyline(latlngs, config);
    }
    else
    {
        return L.polygon(latlngs, config);
    }
};

Wkt.Wkt.prototype.construct.multilinestring = function (config) {
    var coords = this.components,
        latlngs = this.coordsToLatLngs(coords, 1);

    if (L.multiPolygon)
    {
        return L.multiPolygon(latlngs, config);
    }
    else
    {
        return L.polygon(latlngs, config);
    }
};

If you want I can send a pull request for it or you can just copy the above :)

arthur-e commented 7 years ago

@crash-dive Could you send a pull request, please?