Google 地图 v3 customMarker 锚点出现问题

发布于 2024-11-16 02:53:51 字数 1793 浏览 2 评论 0原文

我开发了带有自定义标记图标的地图。 lat lng 坐标是从 json 文件中引入的。但我的问题是,我们不是定义每个标记,而是将它们全部分组在横幅标记的 if 语句中。我的问题是我想在另一个横幅中使用 if 语句来使一个横幅显示不同。

代码如下:

     if (is_featured == true){
    if (ad_id == 93){
        var marker_icon = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark[93] + "m.png",
            new google.maps.Size(91, 64),
            new google.maps.Point(0, 0),
            new google.maps.Point(45.5, 64));
        info = get_sponsor_info(mark);   
        var shadow = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark[93] + "ms.png",
            new google.maps.Size(126, 64),
            new google.maps.Point(0,0),
            new google.maps.Point(45.5, 64));
    }
    else {
        var marker_icon = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark['ad_id'] + "m.png",
            new google.maps.Size(140, 63),
            new google.maps.Point(0, 0),
            new google.maps.Point(70, 63));
        info = get_sponsor_info(mark);   
        var shadow = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark['ad_id'] + "ms.png",
            new google.maps.Size(176, 63),
            new google.maps.Point(0,0),
            new google.maps.Point(70, 63));
            
        var banner_marker = new google.maps.Marker({
            position: pt,
            icon: marker_icon,
            map: map,
            zIndex: 100000000,
            shadow: shadow 
        
    
    })};

if (ad_id ==93) 中的锚点值不会影响横幅的实际锚点。

地图在这里:

http://www.noblood.org/transfusion -alternatives-blood-management-resources-map

您可以看到俄亥俄州的横幅应该位于哥伦布市的红色 x 处,但事实并非如此。

I have developed a map with custom marker Icons. The lat lng coordinates are brought in from a json file. My problem though is that instead defining each and every marker we grouped them all together in an if statement for banner markers. My problem is that I want to use an if statement inside another one to make one banner appear differently.

Here is the code:

     if (is_featured == true){
    if (ad_id == 93){
        var marker_icon = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark[93] + "m.png",
            new google.maps.Size(91, 64),
            new google.maps.Point(0, 0),
            new google.maps.Point(45.5, 64));
        info = get_sponsor_info(mark);   
        var shadow = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark[93] + "ms.png",
            new google.maps.Size(126, 64),
            new google.maps.Point(0,0),
            new google.maps.Point(45.5, 64));
    }
    else {
        var marker_icon = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark['ad_id'] + "m.png",
            new google.maps.Size(140, 63),
            new google.maps.Point(0, 0),
            new google.maps.Point(70, 63));
        info = get_sponsor_info(mark);   
        var shadow = new google.maps.MarkerImage(
            "_files/ads/70/" +  mark['ad_id'] + "ms.png",
            new google.maps.Size(176, 63),
            new google.maps.Point(0,0),
            new google.maps.Point(70, 63));
            
        var banner_marker = new google.maps.Marker({
            position: pt,
            icon: marker_icon,
            map: map,
            zIndex: 100000000,
            shadow: shadow 
        
    
    })};

The anchor value in the if (ad_id ==93) does not affect the actual anchor point of the banner.

The map is here:

http://www.noblood.org/transfusion-alternatives-blood-management-resources-map

And you can see that the banner in Ohio should be right at the red x in Columbus but it's not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文