Skip to content

Commit d2de370

Browse files
authored
fix: allow negative anchor values for AdvancedMarker (#695)
Allow AdvancedMarkerElement anchor to take negative values, so the anchor point can be above or to the left of the marker.
1 parent d5f360d commit d2de370

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/advanced-marker.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,18 @@ const MarkerContent = ({
128128
const [xTranslation, yTranslation] =
129129
anchorPoint ?? AdvancedMarkerAnchorPoint['BOTTOM'];
130130

131+
let xTranslationFlipped = `-${xTranslation}`;
132+
let yTranslationFlipped = `-${yTranslation}`;
133+
if (xTranslation.trimStart().startsWith('-')) {
134+
xTranslationFlipped = xTranslation.substring(1);
135+
}
136+
if (yTranslation.trimStart().startsWith('-')) {
137+
yTranslationFlipped = yTranslation.substring(1);
138+
}
139+
131140
// The "translate(50%, 100%)" is here to counter and reset the default anchoring of the advanced marker element
132141
// that comes from the api
133-
const transformStyle = `translate(50%, 100%) translate(-${xTranslation}, -${yTranslation})`;
142+
const transformStyle = `translate(50%, 100%) translate(${xTranslationFlipped}, ${yTranslationFlipped})`;
134143

135144
return (
136145
// anchoring container

0 commit comments

Comments
 (0)