0

如何使用 Google Maps 3 为自定义标记制作类似的脚本?就像 v.2 一样:

var iconBlue = new GIcon(); 
iconBlue.image = 'images/cell1.png';
iconBlue.shadow = '';
iconBlue.iconSize = new GSize(32, 32);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(3, 16);
iconBlue.infoWindowAnchor = new GPoint(15, 15);

var iconRed = new GIcon(); 
iconRed.image = 'images/cell3.png';
iconRed.shadow = '';
iconRed.iconSize = new GSize(32, 32);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(15, 2);
iconRed.infoWindowAnchor = new GPoint(15, 15);

var iconGreen = new GIcon(); 
iconGreen.image = 'images/cell2.png';
iconGreen.shadow = '';
iconGreen.iconSize = new GSize(32, 32);
iconGreen.shadowSize = new GSize(22, 20);
iconGreen.iconAnchor = new GPoint(-9, 2);
iconGreen.infoWindowAnchor = new GPoint(20, 15);

var customIcons = [];
customIcons["60"] = iconBlue;
customIcons["240"] = iconRed;
customIcons["350"] = iconGreen;

我在第 3 版中写了以下内容,但未显示标记。

var cellone = new google.maps.MarkerImage("images/cell1.png", 
    new google.maps.Size(20, 34), new google.maps.Point(0,0), 
    new google.maps.Point(3, 16));
var celltwo = new google.maps.MarkerImage("images/cell2.png",
    new google.maps.Size(20, 34), new google.maps.Point(0,0), 
    new google.maps.Point(-9, 2));
var cellthree = new google.maps.MarkerImage("images/cell3.png", 
    new google.maps.Size(20, 34), new google.maps.Point(0,0), 
    new google.maps.Point(15, 2));

var customIcons = [];
customIcons["60"] = cellone;
customIcons["240"] = celltwo;
customIcons["350"] = cellthree;
4

2 回答 2

0

Mike Williams 的 v2“类别”示例的翻译版本

于 2012-06-26T12:44:38.723 回答
0

我最近自己做了这个图标的东西。而且我最初使用的代码类型与您使用的相同,但这不起作用。显然 new GIcon() 无法正常运行。

有一种非常简单的方法可以更改图标,它不使用变量。这就是我所做的。

将 markerVariable 声明为全局变量。当您创建新标记时,其中一行应该是 icon : ...

这是我的代码示例。当然,您必须更改某些行以使其适用于您的程序(除非您更改某些功能,否则您不能使用带有标签的标记)。

最后,图标 : ... 可以是您计算机上的链接或位置。

var iconArray = [
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/yellow-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/purple-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/pink-dot.png"],
                 ["http://www.google.com/intl/en_us/mapfiles/ms/micons/ltblue-dot.png"]

                 ]; 


function getMarkers() {
    for (i = 0; i < locations.length; i++) { 
            marker[i] = new MarkerWithLabel({
                position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                draggable: false,
                map: map,
                icon: new google.maps.MarkerImage(iconArray[i]),
                //icon: new google.maps.MarkerImage("http://www.google.com/intl/en_us/mapfiles/ms/micons/pink-dot.png"),
                //labelContent: locations[i][3],
                labelAnchor: new google.maps.Point(30, 0),
                labelClass: "labels", // the CSS class for the label
                 labelStyle: {opacity: 0.75}
            });



        }
}

function initialize() {
  getMarkers();
}
于 2012-06-26T07:48:54.090 回答