maplair
Version:
JavaScript library for mobile-friendly interactive maps
50 lines (49 loc) • 1.52 kB
JavaScript
import { create } from "../../dom/DomUtil.js";
import { Icon } from "./Icon.js";
//#region src/layer/marker/DefaultIcon.js
const URL_RE = /^url\((['"])?(.+)\1\)$/;
const MARKER_ICON_RE = /^(.*)marker-icon\.svg$/;
var DefaultIcon = class DefaultIcon extends Icon {
static {
this.setDefaultOptions({
iconUrl: "marker-icon.svg",
iconRetinaUrl: "marker-icon.svg",
shadowUrl: "marker-shadow.svg",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
});
}
constructor(...args) {
super(...args);
this.callInitHooks(DefaultIcon);
}
_getIconUrl(name) {
if (!DefaultIcon.imagePath) DefaultIcon.imagePath = this._detectIconPath();
const url = super._getIconUrl(name);
if (!url) return null;
return (this.options.imagePath ?? DefaultIcon.imagePath) + url;
}
_stripUrl(path) {
const strip = function(str, re, idx) {
const match = re.exec(str);
return match && match[idx];
};
path = strip(path, URL_RE, 2);
return path && strip(path, MARKER_ICON_RE, 1);
}
_detectIconPath() {
const el = create("div", "maplair-default-icon-path", document.body);
const path = this._stripUrl(getComputedStyle(el).backgroundImage);
document.body.removeChild(el);
if (path) return path;
const link = document.querySelector("link[href$=\"maplair.css\"]");
if (!link) return "";
return link.href.substring(0, link.href.length - 11 - 1);
}
};
//#endregion
export { DefaultIcon };
//# sourceMappingURL=DefaultIcon.js.map