Icon size x can now be initialised with a number (#4608)

Icon size x can now be initialised with a number. Fixes #3185
This commit is contained in:
Ray Hammond 2016-06-01 15:24:24 +01:00 committed by Vladimir Agafonkin
parent 3ecd4273f3
commit 72c4f986b1
2 changed files with 42 additions and 2 deletions

View File

@ -23,6 +23,40 @@ describe("Marker", function () {
});
describe("#setIcon", function () {
it("set the correct x and y size attributes", function () {
var expectedX = 96;
var expectedY = 100;
var sizedIcon = new L.Icon.Default({
iconUrl: icon1._getIconUrl('icon') + '?3',
iconSize: [expectedX, expectedY]
});
var marker = new L.Marker([0, 0], {icon: sizedIcon});
map.addLayer(marker);
var icon = marker._icon;
expect(icon.style.width).to.be(expectedX + 'px');
expect(icon.style.height).to.be(expectedY + 'px');
});
it("set the correct x and y size attributes passing only one value", function () {
var expectedXY = 96;
var sizedIcon = new L.Icon.Default({
iconUrl: icon1._getIconUrl('icon') + '?3',
iconSize: expectedXY
});
var marker = new L.Marker([0, 0], {icon: sizedIcon});
map.addLayer(marker);
var icon = marker._icon;
expect(icon.style.width).to.be(expectedXY + 'px');
expect(icon.style.height).to.be(expectedXY + 'px');
});
it("changes the icon to another image", function () {
var marker = new L.Marker([0, 0], {icon: icon1});
map.addLayer(marker);

View File

@ -100,8 +100,14 @@ L.Icon = L.Class.extend({
},
_setIconStyles: function (img, name) {
var options = this.options,
size = L.point(options[name + 'Size']),
var options = this.options;
var sizeOption = options[name + 'Size'];
if (!L.Util.isArray(sizeOption)) {
sizeOption = [sizeOption, sizeOption];
}
var size = L.point(sizeOption),
anchor = L.point(name === 'shadow' && options.shadowAnchor || options.iconAnchor ||
size && size.divideBy(2, true));