1
我曾經有過這樣的事情 -問題創建自定義GICON
var gicons = [];
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.iconAnchor = new GPoint(9,34);
baseIcon.iconSize = new GSize(20,34);
baseIcon.infoWindowAnchor = new GPoint(9,2);
gicons["home"] = new GIcon(baseIcon,"yellow.png");
gicons["red"] = new GIcon(baseIcon,"red.png");
gicons["green"] = new GIcon(baseIcon,"green.png");
gicons["blue"] = new GIcon(baseIcon,"blue.png");`
它工作正常。
取而代之的是,我想是這樣 -
var tags = ["home", "red","green", "blue"];
var tags_colors = ["yellow.png", "red.png", "green.png", "blue.png"];
for(var i=0; i<tags.length; i++){
if(tags[i]!=null){
gicons[tags[i]] = new GIcon(baseIcon,tags_colors[i]);
}
}
::::::編輯::::
'的GDownloadUrl( 「genxml.php」 功能(DOC){VAR xmlDoc中= GXml.parse(DOC); VAR標記= xmlDoc.documentElement.getElementsByTagName( 「標記」);?
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var address = markers[i].getAttribute("area");
var name = markers[i].getAttribute("street");
var html = "<b>"+name+"<\/b><p>"+address;
var category = markers[i].getAttribute("tag");
// create the marker
var marker = createMarker(point,name,html,category);
map.addOverlay(marker);
tags[i] = markers[i].getAttribute('tag');
}
// hadnling the tags dynamically, to make it unique
for (var i=0; i<tags.length-1 ; i++){
var temp = tags[i];
for(var j=i+1; j<tags.length; j++){
if(temp == tags[j]){
tags[j] = null;
}
}`
它不工作不知道爲什麼有人可以幫我請
哦,我很抱歉。在我的實際代碼中沒有錯別字。仍然沒有工作:(我編輯。 – Pow
沒有進一步的錯誤,你可以請''var gicons = [];' –
實際上我從自動生成的XML文件中獲取標記的值。所以,它是動態的。下面是大塊的代碼 - – Pow