Skip to content

Commit

Permalink
Merge pull request #60 from makinacorpus/fix_59
Browse files Browse the repository at this point in the history
Fix 59
  • Loading branch information
mdartic authored Sep 19, 2016
2 parents 4836709 + e2e9c8f commit 7907716
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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

0 comments on commit 7907716

Please sign in to comment.