I want to be able to control which set of markers to show by using
checkboxes. Therefore I load them into different arrays using
markerOptions, attempting to place them on the map and add listener to
them one by one. Not sure if that's the way it should be done but it
seems logical to me. Nevertheless, I get the markers placed on the
map, but when click on the marker it doesn't open right. Can't seem
to retrieve the url from the array. Here's short chunk of my code.
Please help.
For some reasons, it only works in IE, not FF, Chrome or Safari.
Another thing I need to solve...
http://www.strathcona-health.ca/vsb/maps/ourschoolsmap0.7.html
....
for (var i = 0; i < locations.length; i++) {
var school = locations[i];
var myLatLng = new google.maps.LatLng(school[1], school[2]);
var myMarkerOptions = {
position: myLatLng,
map: map,
icon: image,
shape: shape,
zIndex: school[5],
optimized: false,
url: '../schoolmap/school.aspx?s=' + school[3],
title: school[0] + ' at ' + school[4],
contentinfo: school[0]
};
// select which array to push data into
if (schoollevel == 'e') {
ElementaryMarkerArray.push(myMarkerOptions);
}
....
// set markers
function setMarkers(locations) {
for (i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker(locations[i]);
// get
var url = $('#map_canvas').gmap('option', 'url');
google.maps.event.addListener(marker, 'click', function () {
window.open(url);
});
//
}; // end for statement
};// end function
as per your other thread, the usual way is to create and store the
marker objects themselves(not options) one time only. This allows you
to hide and show them ad infinitum, without recreating.
You can assign custom properties to marker objects, such as a url,
class or identifier, so long as you take care not to clash with an
existing Google property.
You can assign custom properties to marker objects, such as a url,
class or identifier, so long as you take care not to clash with an
existing Google property.
I add properties to API objects all the time. I feel quite confident
that Google are not about to come up with a property called
google.maps.Polygon.marcelo_index ;-)
--
Marcelo - http://maps.forum.nu
--
http://www.strathcona-health.ca/vsb/maps/ourschoolsmap0.7.1.html
Then I changed the scripts so that it checks the checkbox's checked
status before creating the markers. In the same scenario, the markers
will not be shown. But then they cannot be shown again because the
array for these markers is not filled.
http://www.strathcona-health.ca/vsb/maps/ourschoolsmap0.7.2.html
So I searched and tried to use MarkerOptions and store the markers
options in the arrays first and then show the markers later. I have
changed the property from url to MyUrl in my revised code. Same
issue. I used FireBug to confirm the value of MyUrl's are in the
array. But how do I get them out?
http://www.strathcona-health.ca/vsb/maps/ourschoolsmap0.7.html
I'm not sure if I'm going the wrong way by trying to work my way thru
js. Or there is something else in Map API that I should look into...
Any help would be appreciated. Many many thanks.
On Dec 17, 8:46 am, Chad Killingsworth
So: create all the markers and *then* use the checkboxes to display them.
On Dec 17, 10:23 am, Andrew Leach <andrew.leac...@gmail.com> wrote:
Don't do that. Save your markers in an array.
var MyMarkerInfo = {
marker: new google.maps.Marker(opt_opts),
extraInfo: myExtraInformation }
how do i place the markers on the map and add listener for
window.open(myURL) then?
No: an array of markers is just that, an array containing markers.
var markers;
var marker = new google.maps.Marker(...);
marker.myAttribute = myAttributeValue; // if you need this
markers.push(marker);
If you want to add a listener to each marker, use a closure:
var marker = createMarker(...); // probably global
marker.myAttribute = myAttributeValue; // if you need this
markers.push(marker);
...
function createMarker(...)
var marker=new google.maps.Marker(...); // local variable
google.maps.event.addListener(marker, 'click', function() { ... });
return marker;
marker.myAttribute = myAttributeValue; // if you need this