gpt4 book ai didi

google-maps-api-3 - 更改 Google map V3 中的标记大小

转载 作者:行者123 更新时间:2023-12-03 07:07:17 25 4
gpt4 key购买 nike

我正在使用this explanation如何通过使用 MarkerImage 设置图标来为谷歌地图标记着色,并且着色效果很好。但我无法使scaledSize 参数改变标记的大小。

    var pinColor = 'FFFF00';
var pinIcon = new google.maps.MarkerImage(
"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34),
new google.maps.Size(2, 4));
marker.setIcon(pinIcon);

使用scaledSize参数来更改标记大小的正确用法是什么?例如,如何将标记大小加倍?

最佳答案

这个答案阐述了 John Black's helpful answer ,所以我会在我的回答中重复他的一些回答内容。

调整标记大小的最简单方法似乎是将参数 2、3 和 4 保留为空,并缩放参数 5 中的大小。

var pinIcon = new google.maps.MarkerImage(
"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|FFFF00",
null, /* size is determined at runtime */
null, /* origin is 0,0 */
null, /* anchor is bottom center of the scaled image */
new google.maps.Size(42, 68)
);

顺便说一句,this answer对于类似的问题,断言在第二个参数中定义标记大小比在第​​五个参数中缩放更好。不知道这是否属实。

将参数 2-4 保留为空对于默认 google pin 图像非常有效,但您必须为默认 google pin 阴影图像显式设置 anchor ,否则它将如下所示:

what happens when you leave anchor null on an enlarged shadow

当您在 map 上查看图形时,图钉图像的底部中心恰好与图钉的尖端位于同一位置。这很重要,因为当您离开 anchor (第四个参数)null 时,标记的位置属性(标记在 map 上的 LatLng 位置)将自动与图钉的视觉提示并置。换句话说,将 anchor 保留为空可以确保尖端指向它应该指向的位置。

但是,阴影的尖端并不位于底部中心。因此,您需要显式设置第四个参数来偏移图钉阴影的​​尖端,以便阴影的尖端与图钉图像的尖端位于同一位置。

通过实验,我发现阴影的尖端应该这样设置:x 是大小的 1/3,y 是大小的 100%。

var pinShadow = new google.maps.MarkerImage(
"http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
null,
null,
/* Offset x axis 33% of overall size, Offset y axis 100% of overall size */
new google.maps.Point(40, 110),
new google.maps.Size(120, 110));

给出这个:

offset the enlarged shadow anchor explicitly

关于google-maps-api-3 - 更改 Google map V3 中的标记大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7842730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com