Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2010, 08:02 PM   PM User | #1
GazK
New to the CF scene

 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
GazK is an unknown quantity at this point
OSMap / GMap switch failing - only on IE

I'm not sure whether this is best posted here, or on a google maps api forum, but here goes:

I have a site which uses a google map, and works well, like this:

http://www.railwaysarchive.co.uk/eve...p?eventID=6684

I have built a version of that page which uses an OS map by default, but allows switching to a google map. It is here:

http://www.railwaysarchive.co.uk/osm...p?eventID=6684

The script uses a simple toggle as follows:

Code:
function toggleMap() {
// toggle map div visibility

	var		googlemap = document.getElementById("googlemap");
	var		OSmap = document.getElementById("OSmap");
	
	if (OSmap.style.display!="block") {
	//	currently hidden, show
		OSmap.style.display="block";
		googlemap.style.display="none";
		document.getElementById("maplink").innerHTML= "Switch to Google Map";
	} else {
		OSmap.style.display="none";
		googlemap.style.display="block";
		document.getElementById("maplink").innerHTML= "Switch to OS Map";
	}
	
}
I was having trouble getting both maps to load their respective data when one was hidden, so both maps start out with display:block and then the gmap is hidden during the <body onload>. This system works great with Firefox and with Chrome, but in IE if you switch to the google map the tiles don't load. Can anyone help?

Relevant code snippets are as follows:

Code:
<body onload="createOSAccidentSummaryMap(52.6566359591919, -3.14070984721184, 7); createAccidentSummaryMap(52.6566359591919, -3.14070984721184, 'accident', 13); toggleMap();">

function createAccidentSummaryMap(dblLatitude, dblLongitude, enumType, lngZoom) {
// creates a map with a single event marker, map type controls and full zoom controls
// and centers it on the event coordinates
	if (GBrowserIsCompatible()) {
	// checks for compatible browser
		map = new GMap2(document.getElementById("googlemap"));
		map.addControl(new GSmallZoomControl());
        map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.setCenter(new GLatLng(dblLatitude, dblLongitude), lngZoom);
		map.enableDoubleClickZoom();
		map.setMapType(G_HYBRID_MAP);
		var icon = createEventIcon(enumType);
		var point = new GLatLng(dblLatitude, dblLongitude);
        var marker = new GMarker(point, icon);
		map.addOverlay(marker);
	}
}
GazK is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:38 PM.


Advertisement
Log in to turn off these ads.