/    Sign up×
Community /Pin to ProfileBookmark

javascript eval() problems

Hi there,

I’m using new to this forum, so first of all: hello!

I got a problem in the piece of javascript code below.
A for loop reads an XML file and creates an object (marker)
for each XML item. Now all objects have the name/id ‘marker’
and so only the last create is called by my javascript.

How can I make this code work so it creates: marker1 = new GMarker, marker2 = new GMarker ect.
and use them in het GEvent.addListener function and in the last 2 lines of code?

_j

[CODE]
for (i=0;i<x.length;i++) {
var redIcon = new GIcon(G_DEFAULT_ICON);

redIcon.image = “images/” + x[i].getElementsByTagName(“TYPE”)[0].childNodes[0].nodeValue + “.png”;
redIcon.shadow = “images/shadow.png”;
redIcon.iconSize = new GSize(25,31);
redIcon.shadowSize = new GSize(1,1);
redIcon.iconAnchor = new GPoint(0, 0);
redIcon.infoWindowAnchor = new GPoint(135,20);

marker = new GMarker( new GLatLng(x[i].getElementsByTagName(“LATITUDE”)[0].childNodes[0].nodeValue,x[i].getElementsByTagName(“LONGITUDE”)[0].childNodes[0].nodeValue),{icon:redIcon,zIndexProcess:importanceOrder});

var icon_type = x[i].getElementsByTagName(“TITLE”)[0].childNodes[0].nodeValue;
var icon_description = x[i].getElementsByTagName(“DESCRIPTION”)[0].childNodes[0].nodeValue;
var icon_image = x[i].getElementsByTagName(“IMAGE”)[0].childNodes[0].nodeValue;
var icon_link = x[i].getElementsByTagName(“LINK”)[0].childNodes[0].nodeValue;

GEvent.addListener(marker, “mouseover”, function(){
marker.openExtInfoWindow(
map,
“opacity_window”,
“<div class=’title’>”+icon_type+”</div>”+
“<div class=’section2′><p><img src='”+icon_image+”‘>”+icon_description+”</p></div>”+
“<div class=’section3′><p><img src=’images/link.png’><a href='”+icon_link+”‘> Meer info en boeken</a></p>”,
{ beakOffset: 18 }
);
});

marker.importance = 2;
map.addOverlay(marker);
}
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 08.2011 — If [B]marker[/B] is a Global variable, you may use the fact that a global variable belongs to the Global Object [B]window[/B], so that you may write it dynamically:
<i>
</i>window['marker'+(i+1)]
×

Success!

Help @jonnekke spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...