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 Path.setStyle bug (replacing #6671) #6941

Merged
merged 13 commits into from Oct 29, 2021
Merged
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