使用 HERE JavaScript 3.1 API 创建 map 标记时,标记会使用图像的底部中心将自身 anchor 定在其位置上。这反射(reflect)了向下指向的默认标记。
但是,我使用的是自定义标记图像并且我想更改 anchor (例如位于图像的中间)。我在 H.map.Marker 中找不到任何更改 anchor 的选项。我如何更改 anchor ?
最佳答案
anchor 未设置在 H.map.Marker
,但在 H.map.Icon
反而。 Icon
是包装标记中使用的图像的类。您可以在构建过程中传递的选项中设置 anchor 。 anchor 以图像的像素坐标给出,并使用 H.math.Point
设置。目的。请参阅下面的示例以创建带有自定义图像和设置在像素坐标 10,10 处的 anchor 的 map 标记。
let markerIcon = new H.map.Icon('./marker.png', { anchor: new H.math.Point(10, 10) });
let marker = new H.map.Marker(coordinates, { icon: markerIcon });
关于javascript - 如何在 HERE JS 3.1 API 中更改 map 标记的 anchor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63051081/