Skip to content

Commit ee51b05

Browse files
committed
fix Logo没有链接时,不进行跳转
1 parent f528456 commit ee51b05

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

src/leaflet/control/Logo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export var Logo = L.Control.extend({
7676
}
7777
}
7878
var link = this.options.link;
79-
div.innerHTML = "<a href='" + link + "' target='_blank' style='border: none;display: block;'>" +
80-
"<img src=" + imgSrc + " alt='" + alt + "' style='border: none;" + styleSize + "margin-right:5px;margin-bottom:2px;white-space: nowrap'></a>";
79+
var imgElement = "<img src=" + imgSrc + " alt='" + alt + "' style='border: none;" + styleSize + "margin-right:5px;margin-bottom:2px;white-space: nowrap'>";
80+
div.innerHTML = link ? "<a href='" + link + "' target='_blank' style='border: none;display: block;'>" + imgElement + "</a>" : imgElement;
8181
return div;
8282
}
8383
});

src/mapboxgl/control/Logo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export class Logo {
7070
}
7171
}
7272
var link = this.link;
73-
this._container.innerHTML = "<a href='" + link + "' target='_blank'>" +
74-
"<img src=" + imgSrc + " alt='" + alt + "' style='" + styleSize + "margin-bottom: 2px'></a>";
73+
var imgElement = "<img src=" + imgSrc + " alt='" + alt + "' style='" + styleSize + "margin-bottom: 2px'>";
74+
this._container.innerHTML = link ? "<a href='" + link + "' target='_blank'>" + imgElement + "</a>" : imgElement;
7575
this._createStyleSheet();
7676
return this._container;
7777
}

src/maplibregl/control/Logo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
}
7070
}
7171
var link = this.link;
72-
this._container.innerHTML = "<a href='" + link + "' target='_blank'>" +
73-
"<img src=" + imgSrc + " alt='" + alt + "' style='" + styleSize + "margin-bottom: 2px'></a>";
72+
var imgElement = "<img src=" + imgSrc + " alt='" + alt + "' style='" + styleSize + "margin-bottom: 2px'>";
73+
this._container.innerHTML = link ? "<a href='" + link + "' target='_blank'>" + imgElement + "</a>" : imgElement;
7474
this._createStyleSheet();
7575
return this._container;
7676
}

src/openlayers/control/Logo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ export class Logo extends Control {
6363
styleSize = "";
6464
}
6565
}
66-
67-
68-
div.innerHTML = "<a href='" + link + "' target='_blank' style='border: none;display: block;'>" +
69-
"<img src=" + imgSrc + " alt='" + alt + "' style='border: none;" + styleSize + "white-space: nowrap;margin-bottom: 2px'></a>";
66+
var imgElement = "<img src=" + imgSrc + " alt='" + alt + "' style='border: none;" + styleSize + "white-space: nowrap;margin-bottom: 2px'>";
67+
div.innerHTML = link ? "<a href='" + link + "' target='_blank' style='border: none;display: block;'>" + imgElement + "</a>" : imgElement;
7068
return div;
7169
}
7270

test/mapboxgl/control/LogoSpec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ describe('mapboxgl_Logo', () => {
6363
var onAdd = logo1.onAdd(map);
6464
expect(onAdd).not.toBeNull();
6565
expect(onAdd.nodeName).toBe("DIV");
66+
expect(onAdd.querySelector('a')).toBeNull;
6667
// options2 - imageUrl,width
6768
var options2 = {
69+
link: "http://test.com",
6870
imageUrl: "http://test.com/test.png",
6971
width: 20
7072
};
@@ -75,5 +77,6 @@ describe('mapboxgl_Logo', () => {
7577
var onAdd2 = logo2.onAdd(map);
7678
expect(onAdd2).not.toBeNull();
7779
expect(onAdd2.nodeName).toBe("DIV");
80+
expect(onAdd2.querySelector('a')).not.toBeNull;
7881
});
7982
});

0 commit comments

Comments
 (0)