Built-in markers seems to be aligned so that they point to their location, but is there a way of specifying which part of an icon should be at the precise location of the marker?
Some image icons might need to be centred at the location, but others might need to have the bottom middle of the image at the location. As far as I can tell, if you provide an image as a marker, the default positioning has the top left corner at the location.
I was looking for something like an iconAlign or iconPosition property, which would have a value like bottom (meaning bottom middle) or top right.
I've managed to do this using left and right CSS properties for .leaflet-marker-icon but this only works because my icons are all the same size. And because I'm using worldmap in a dashboard, it's a bit of a palaver to add the CSS. Perhaps there's an easier way, but here's what I've got at the moment, which I've included in a dashboard template node that is "Added to site <head> section":
My icons are 23px wide and 32px high, and the "point" is at the bottom in the middle. The closure is to avoid const clashes.
UPDATED UPDATE:
More reliable version, which makes sure the IFRAME is definitely there before continuing:
(() => {
const interval = setInterval(() => {
const iframe = document.querySelector("iframe");
if (iframe) {
clearInterval(interval);
const doc = iframe.contentDocument;
const style = doc.createElement("style");
// Icons are 23px wide and 32px high, so shift it left by half the width and up by the full height
style.textContent = ".leaflet-marker-icon { left: -11.5px; top: -32px; }";
doc.head.append(style);
}
}, 500);
})();
no - the closest is msg.payload.iconSize where you can set the size of the icon in pixels - but a) it assumes it is square and b) assumes the middle to be the location.
If I don't specify an iconSize, it stretches my image to be 32×32 pixels. Does a zero iconSize mean that the icon won't be (re)sized? Is that what I should use instead of the string I've got, then?
UPDATE:
After a little experimentation...
0 means no icon is shown!
null means the icon is stretched to 32×32 pixels.
"" (any string, I guess) means the icon is not (re)sized.