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:
parent
3ecd4273f3
commit
72c4f986b1
@ -23,6 +23,40 @@ describe("Marker", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#setIcon", 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 () {
|
it("changes the icon to another image", function () {
|
||||||
var marker = new L.Marker([0, 0], {icon: icon1});
|
var marker = new L.Marker([0, 0], {icon: icon1});
|
||||||
map.addLayer(marker);
|
map.addLayer(marker);
|
||||||
|
@ -100,8 +100,14 @@ L.Icon = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setIconStyles: function (img, name) {
|
_setIconStyles: function (img, name) {
|
||||||
var options = this.options,
|
var options = this.options;
|
||||||
size = L.point(options[name + 'Size']),
|
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 ||
|
anchor = L.point(name === 'shadow' && options.shadowAnchor || options.iconAnchor ||
|
||||||
size && size.divideBy(2, true));
|
size && size.divideBy(2, true));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user