Skip to content

_convertLatLngs overwrites arrays (pass by reference) #1092

@KeithTurkowski

Description

@KeithTurkowski

I have an object that maintains and manipulates its own set of verts, I am currently doing: "L.Polygon(region.verts.slice(0), style)" using .slice(0) to duplicate the array, since if I pass in region.verts directly, the array gets modified by the _convertLatLngs function.

_convertLatLngs: function (latlngs) {
    var i, len;
    for (i = 0, len = latlngs.length; i < len; i++) {
        if (latlngs[i] instanceof Array && typeof latlngs[i][0] !== 'number') {
            return;
        }
        latlngs[i] = L.latLng(latlngs[i]);
    }
    return latlngs;
}

It seems like it would be nice if we could have something like "var new_latlngs", "new_latlngs[i] = L.latLng(latlngs[i]);" so people wouldn't have to worry about this.

If people are considering the overwrite to be a feature, if so maybe we could have an option to toggle this behavior off?

Thanks for your attention.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions