From 72c4f986b10f70493bfc2b73b3776811857d2aea Mon Sep 17 00:00:00 2001 From: Ray Hammond Date: Wed, 1 Jun 2016 15:24:24 +0100 Subject: [PATCH] Icon size x can now be initialised with a number (#4608) Icon size x can now be initialised with a number. Fixes #3185 --- spec/suites/layer/marker/MarkerSpec.js | 34 ++++++++++++++++++++++++++ src/layer/marker/Icon.js | 10 ++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/spec/suites/layer/marker/MarkerSpec.js b/spec/suites/layer/marker/MarkerSpec.js index d91ad0d5..c99b288f 100644 --- a/spec/suites/layer/marker/MarkerSpec.js +++ b/spec/suites/layer/marker/MarkerSpec.js @@ -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); diff --git a/src/layer/marker/Icon.js b/src/layer/marker/Icon.js index 0b6c28a9..036beebc 100644 --- a/src/layer/marker/Icon.js +++ b/src/layer/marker/Icon.js @@ -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));