API Google map v3:在zoom_changed上更改标记的大小 [英] API Google map v3 : change markers' size on zoom_changed

查看:258
本文介绍了API Google map v3:在zoom_changed上更改标记的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Maps API v3上需要一些帮助。

我有一张带有标记(图片)的地图,来自数据库的信息。



我想在更改缩放比例时调整标记大小,但我的代码不会' t工作(图片消失,由默认图标取代)。你能帮我看看有什么不对吗?

这是我的代码:



//这部分

  var marker = new google.maps.Marker({
map:map,
icon:new google.maps.MarkerImage(../ images / installateurs /<?php echo $ row_artisans ['photo0'];?>,
new google.maps.Size(40 ,53.2),
new google.maps.Point(0,0),
new google.maps.Point(0,0),
google.maps.Size(40,53.2 )
),
position:new google.maps.LatLng(<?php echo $ row_artisans ['Lat'];?> ;,,<?php echo $ row_artisans ['Lng']; ?>)
});

//第二部分问题出在哪里(这个侦听器刚好在创建地图之后放置,在渲染之前)

  google.maps.event.addListener(map,'zoom_changed',function(){ 
var largeur = 20 +(5 *(map.getZoom() - 9));
var ratio = largeur / 40;
var hauteur = 26.6 * ratio;

for(i = 0; i< markers.length; i ++){
var icon = markers [i] .getIcon();
markers [i] .setIcon(
icon .url,
new google.maps.Size(largeur,hauteur),
new google.maps.Point(0,0),
new google.maps.Point(0,0) ,
new google.maps.Size(largeur,hauteur)
);
}
});

感谢您的帮助!

解决方案

根据文档

a>, setIcon 或者接受一个字符串或一个 MarkerImage 对象。最初你设置了一个 MarkerImage ,但是在你的监听器代码中,你不会构造 MarkerImage 。尝试这样的代替:

  for(i = 0; i< markers.length; i ++){
var icon = markers [i] .getIcon();
markers [i] .setIcon(new google.maps.MarkerImage(
icon.url,
google.maps.Size(largeur,hauteur),
google.maps .Point(0,0),
new google.maps.Point(0,0),
new google.maps.Size(largeur,hauteur))
);
}


I need some help on the Google Maps API v3.

I have a map with markers (which are pictures), informations from a database. The pictures and the map are ok at this time.

I would like to resize the markers when changing the zoom, but my code doesn't work (pictures disappear, replaced by the default icon). Could you help me to see what's wrong ?

Here's my code :

// This part is ok

var marker = new google.maps.Marker({
        map: map,
        icon: new google.maps.MarkerImage("../images/installateurs/<?php echo $row_artisans['photo0']; ?>",
            new google.maps.Size(40, 53.2),
            new google.maps.Point(0, 0),
            new google.maps.Point(0, 0),
            new google.maps.Size(40, 53.2)
        ),
        position: new google.maps.LatLng(<?php echo $row_artisans['Lat']; ?>, <?php echo $row_artisans['Lng']; ?>)
});

// Second part where's the problem (this listener is placed just after creating the map, before rendering it)

google.maps.event.addListener(map, 'zoom_changed', function() {
    var largeur = 20 + (5 *(map.getZoom() - 9));
    var ratio = largeur / 40;
    var hauteur = 26.6 * ratio;

    for(i=0; i< markers.length; i++ ) {
        var icon = markers[i].getIcon();
        markers[i].setIcon(
            icon.url,
            new google.maps.Size(largeur, hauteur),
            new google.maps.Point(0, 0),
            new google.maps.Point(0, 0),
            new google.maps.Size(largeur, hauteur)
        );
    }
});

Thanks for your help !

解决方案

According to the docs, setIcon either takes a string or a MarkerImage object. Initially you set a MarkerImage, but in your listener code, you do not construct a MarkerImage. Try something like this instead:

    for(i=0; i< markers.length; i++ ) {
    var icon = markers[i].getIcon();
    markers[i].setIcon(new google.maps.MarkerImage(
        icon.url,
        new google.maps.Size(largeur, hauteur),
        new google.maps.Point(0, 0),
        new google.maps.Point(0, 0),
        new google.maps.Size(largeur, hauteur))
    );
}

这篇关于API Google map v3:在zoom_changed上更改标记的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆