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

Fix 59 #60

Merged
merged 2 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions spec/test.closest.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ describe('Closest on path with precision', function() {
done();
});

it('It should not alterate the latLngs of a polygon', function(done) {
var polygon = L.polygon([[0, 0], [10, 10], [0, 10]])/*.addTo(map)*/,
ll = [0, 5],
marker = L.marker(ll),
latlngs;

latlngs = polygon.getLatLngs();
if (L.Polyline._flat(latlngs)) {
assert.equal(latlngs.length, 3)
} else {
assert.equal(latlngs.length, 1)
assert.equal(latlngs[0].length, 3)
}

closest = L.GeometryUtil.closest(map, polygon, ll);

latlngs = polygon.getLatLngs();
if (L.Polyline._flat(latlngs)) {
assert.equal(latlngs.length, 3)
} else {
assert.equal(latlngs.length, 1)
assert.equal(latlngs[0].length, 3)
}

done();
});

it('It should return null if layer param is not instance of Array|L.Polygon|L.Polyline (Leaflet 0.7.7 only)', function(done) {
var campus = {
"type": "Feature",
Expand Down
7 changes: 5 additions & 2 deletions src/leaflet.geometryutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, {
}
}
return result;
} else if (layer[0] instanceof L.LatLng || typeof layer[0][0] === 'number') { // we could have a latlng as [x,y] with x & y numbers
} else if (layer[0] instanceof L.LatLng
|| typeof layer[0][0] === 'number'
|| typeof layer[0].lat === 'number') { // we could have a latlng as [x,y] with x & y numbers or {lat, lng}
layer = L.polyline(layer);
} else {
return result;
Expand All @@ -202,7 +204,8 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, {
if (! ( layer instanceof L.Polyline ) )
return result;

latlngs = layer.getLatLngs().slice(0);
// deep copy of latlngs
latlngs = JSON.parse(JSON.stringify(layer.getLatLngs().slice(0)));

// add the last segment for L.Polygon
if (layer instanceof L.Polygon) {
Expand Down