Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLatLngs used with polygon does not return array #5212

Closed
walterfn2 opened this issue Dec 23, 2016 · 4 comments
Closed

getLatLngs used with polygon does not return array #5212

walterfn2 opened this issue Dec 23, 2016 · 4 comments

Comments

@walterfn2
Copy link

How to reproduce

Leaflet version I'm using: 1.0.2
Browser (with version) I'm using: Chrome & FF
OS/Platform (with version) I'm using: Windows 10

What behaviour I'm expecting and which behaviour I'm seeing

getLatLngs used with polygon does not return array, but LatLngs as string. If used with polyline array of LatLng is returned. This worked fine with 0.7.7 version.

Minimal example reproducing the issue

var latlngs = [
	[45.51, -122.68],
	[37.77, -122.43],
	[34.04, -118.2]
	];
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
alert(polyline.getLatLngs().length);

var polygon = L.polygon([
	[51.509, -0.08],
	[51.503, -0.06],
	[51.51, -0.047]
	]).addTo(map);
alert(polygon.getLatLngs().length);

Using http://playground-leaflet.rhcloud.com/ or any other jsfiddle like site.

@walterfn2
Copy link
Author

jsfiddle is here https://jsfiddle.net/qccxwp64/2/

@IvanSanchez
Copy link
Member

The return value of L.Polygon.getLatLngs() is, in fact, an array of one element.

This is done in

this._latlngs = [this._latlngs];
since #3279 , to ensure that there is a list of rings, not a list of LatLngs. Simply use polygon.getLatLngs()[0] to get the LatLngs of the outer (and only) ring.

@walterfn2
Copy link
Author

This explains everything, thank you very much!

@olivergg
Copy link

olivergg commented May 17, 2017

Shouldn't the official documentation http://leafletjs.com/reference-1.0.3.html#polyline-getlatlngs be changed to indicate something else than LatLng[] ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants