...

View Full Version : openInfoWindowHtml doesn't work



fikka
09-04-2007, 05:10 PM
Hi

I'm trying to do a very simple thing here: I have the map with the markers and clusters on it and I want to open an info window if user clicks on them. For some reason openInfoWindowHtml doesn't work, I cannot understand why.

So here is my java script, may be you'll see what's wrong here?
Thank you



var map;
var centerLatitude = 0;
var centerLongitude = 0;
var startZoom = 1;

//Create an icon for the clusters
skipped

//create an icon for the pins
skipped


function init() {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

updateMarkers();

GEvent.addListener(map,'moveend',function() {
updateMarkers();
});
}

function updateMarkers() {

//remove the existing points
map.clearOverlays();
//create the boundry for the data to provide
//initial filtering
skipped
//log the URL for testing
GLog.writeUrl('map_search.php?'+getVars);

//retrieve the points
var request = GXmlHttp.create();
request.open('GET', 'map_search.php?'+getVars, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var jscript = request.responseText;
var points;
eval(jscript);

//create each point from the list
for (i in points) {
var point = new GLatLng(points[i].lat,points[i].lng);
var marker = createMarker(point,points[i].type,points[i].description);

map.addOverlay(marker);
}
}
}
request.send(null);
}

function createMarker(point, type, description) {
//create the marker with the appropriate icon
if(type=='c') {
var marker = new GMarker(point,iconCluster,true);
} else {
var marker = new GMarker(point,iconSingle,true);
}

// open info window on click
GEvent.addListener(marker,'click',function() {
var markerHtml = description;
marker.openInfoWindowHtml(markerHtml);
});

return marker;
}
window.onload = init;

fikka
09-06-2007, 01:43 PM
Me again..

Just had a thought that may be the thing is that because I'm call createMarker function within the loop I need to put each marker in array to know for which particular marker openInfoWindowHtml method is called?
Sorry if it doesn't make sense, but I'm really lost here and can't go any further until resolve this problem.
Thanks again I'll appreciate if somebody has any ideas.

Kor
09-06-2007, 02:30 PM
Instead of:


var points;
eval(jscript);

I suspect that you wanted to code:


var points=eval(jscript);

in order to construct an object...Otherwise the variable points is undefined...

fikka
09-06-2007, 03:41 PM
Instead of:


var points;
eval(jscript);

I suspect that you wanted to code:


var points=eval(jscript);

in order to construct an object...Otherwise the variable points is undefined...


Thanks but it's not the case, since "The eval() function evaluates a string and executes it as if it was script code."(c)js tutorial

I have all the points and clusters on the map, it works fine. The only problem I'm having is with info windows.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum