A map pin points to the right building at 16 px. You increase it to 24 px and the tip moves down. The map coordinate stayed put. What moved was the tip's position relative to the point used to place the SVG.
Here's a small experiment you can reproduce without a map library.
Put the center on the cross
Start with a square viewBox="0 0 24 24" and a pin whose tip is at (12, 22). Place the center of the SVG viewport on a fixed cross. The center corresponds to (12, 12) in the SVG, so the tip sits 10 SVG units below it.
At 16 CSS px, that gap becomes 6.67 px. At 24 CSS px, it becomes 10 px. Increasing the icon size moves the tip 3.33 px farther down, even though the cross stays in exactly the same place.
The screenshots magnify the shapes for readability. The labels report offsets in CSS pixels at the original marker sizes.
Try bottom center with two silhouettes
Bottom center puts (12, 24) on the cross. That helps with the first pin, but its tip is still two SVG units above the bottom of the box. Now swap in a silhouette whose tip is at (15, 21). Its tip also sits three SVG units to the right of center.
Here are the offsets at 24 CSS px, measured from the cross to the tip. Positive values go right and down.
| Anchor | Tip A at (12, 22)
|
Tip B at (15, 21)
|
|---|---|---|
| ViewBox center | (0, +10) px | (+3, +9) px |
| Bottom center | (0, −2) px | (+3, −3) px |
| Path tip | (0, 0) px | (0, 0) px |
Put the tip on the map coordinate
Store the tip alongside each pin's SVG. Convert that point to pixels at the current render size, then subtract the result from the fixed target to get the marker's top-left position.
function markerOrigin(target, tip, viewBox, size) {
const scale = size / viewBox.width;
const anchorX = (tip.x - viewBox.x) * scale;
const anchorY = (tip.y - viewBox.y) * scale;
return {
x: target.x - anchorX,
y: target.y - anchorY
};
}
This version assumes a square viewBox and square viewport. If their aspect ratios differ, convert the tip using the SVG's actual scaling and alignment, including any padding introduced by preserveAspectRatio.
The demo checks the rendered SVG transform. Both silhouettes land on the cross at both sizes with a measured offset of 0 px. Keep the tip with the SVG asset and update it when you change the silhouette. Then the marker can change size while continuing to point to the same place.


Top comments (0)