Skip to content

Commit

Permalink
Fix Path.setStyle bug (replacing #6671) (#6941)
Browse files Browse the repository at this point in the history
* Fix issue #6662 and #6664

* Add unit test for Path weight set error

* Simplify Polyline weight set test case

* Alternative fix for setting weight after empty Polyline is added to the map

* Add unit test for setting weight after empty Polygon is added to the map

* Return when empty Polyline is being rendered

* More general formulation for test

* Minor refactoring to make tests more uniform

Co-authored-by: fodor0205 <fodor0205@gmail.com>
Co-authored-by: johndoe <johnd0e@mail.ua>
  • Loading branch information
3 people committed Oct 29, 2021
1 parent 3746690 commit 2eb73c4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
34 changes: 26 additions & 8 deletions spec/suites/layer/vector/PolygonSpec.js
@@ -1,4 +1,14 @@
describe('Polygon', function () {
var map;

before(function () {
map = new L.Map(document.createElement('div'), {center: [55.8, 37.6], zoom: 6});
});

after(function () {
map.remove();
});

describe("#initialize", function () {
it("should never be flat", function () {
var latLngs = [[1, 2], [3, 4]];
Expand Down Expand Up @@ -59,10 +69,8 @@ describe('Polygon', function () {
});

it("can be added to the map when empty", function () {
var map = new L.Map(document.createElement('div'));
var polygon = new L.Polygon([]).addTo(map);
var isAdded = map.hasLayer(polygon);
map.remove(); // clean up
expect(isAdded).to.be(true);
});

Expand Down Expand Up @@ -140,12 +148,6 @@ describe('Polygon', function () {
});

describe('#getCenter', function () {
var map = new L.Map(document.createElement('div'), {center: [55.8, 37.6], zoom: 6});

after(function () {
map.remove();
});

it('should compute center of a big simple polygon around equator', function () {
var latlngs = [
[[0, 0], [10, 0], [10, 10], [0, 10]]
Expand Down Expand Up @@ -322,4 +324,20 @@ describe('Polygon', function () {
expect(polygon._latlngs[1][1]).to.eql([L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4]), L.latLng([2, 2])]);
});
});

describe("#setStyle", function () {
it("succeeds for empty Polygon already added to the map", function () {
var style = {
weight: 3
};
var polygon = L.polygon([]);

polygon.addTo(map);
polygon.setStyle(style);

for (var prop in style) {
expect(polygon.options[prop]).to.be(style[prop]);
}
});
});
});
22 changes: 21 additions & 1 deletion spec/suites/layer/vector/PolylineSpec.js
@@ -1,5 +1,9 @@
describe('Polyline', function () {
var map = new L.Map(document.createElement('div'), {center: [55.8, 37.6], zoom: 6});
var map;

before(function () {
map = new L.Map(document.createElement('div'), {center: [55.8, 37.6], zoom: 6});
});

after(function () {
map.remove();
Expand Down Expand Up @@ -212,4 +216,20 @@ describe('Polyline', function () {
expect(polyline._latlngs).to.eql([L.latLng([1, 2])]);
});
});

describe("#setStyle", function () {
it("succeeds for empty Polyline already added to the map", function () {
var style = {
weight: 3
};
var polyline = L.polyline([]);

polyline.addTo(map);
polyline.setStyle(style);

for (var prop in style) {
expect(polyline.options[prop]).to.be(style[prop]);
}
});
});
});
5 changes: 5 additions & 0 deletions src/layer/vector/Polyline.js
Expand Up @@ -212,6 +212,11 @@ export var Polyline = Path.extend({
_updateBounds: function () {
var w = this._clickTolerance(),
p = new Point(w, w);

if (!this._rawPxBounds) {
return;
}

this._pxBounds = new Bounds([
this._rawPxBounds.min.subtract(p),
this._rawPxBounds.max.add(p)
Expand Down

0 comments on commit 2eb73c4

Please sign in to comment.