var centreLat=0.0; var centreLon=0.0; var initialZoom=1; var imageWraps=false; //SET THIS TO false TO PREVENT THE IMAGE WRAPPING AROUND var map; //the GMap3 itself var gmicMapType; var allowedBounds = new google.maps.LatLng(centreLat, centreLon);; var boundLimits; var currentZoom = initialZoom; function GMICMapType() { this.Cache = Array(); this.opacity = 1.0; } GMICMapType.prototype.tileSize = new google.maps.Size(256, 256); GMICMapType.prototype.maxZoom = 19; GMICMapType.prototype.getTile = function(coord, zoom, ownerDocument) { var c = Math.pow(2, zoom); var c = Math.pow(2, zoom); var tilex=coord.x,tiley=coord.y; if (imageWraps) { if (tilex<0) tilex=c+tilex%c; if (tilex>=c) tilex=tilex%c; if (tiley<0) tiley=c+tiley%c; if (tiley>=c) tiley=tiley%c; } else { if ((tilex<0)||(tilex>=c)||(tiley<0)||(tiley>=c)) { var blank = ownerDocument.createElement('DIV'); blank.style.width = this.tileSize.width + 'px'; blank.style.height = this.tileSize.height + 'px'; return blank; } } var img = ownerDocument.createElement('IMG'); var d = tilex; var e = tiley; var f = "t"; for (var g = 0; g < zoom; g++) { c /= 2; if (e < c) { if (d < c) { f += "q" } else { f += "r"; d -= c } } else { if (d < c) { f += "t"; e -= c } else { f += "s"; d -= c; e -= c } } } img.id = "t_" + f; img.style.width = this.tileSize.width + 'px'; img.style.height = this.tileSize.height + 'px'; img.src = "worldmap/black/"+f+".jpg"; this.Cache.push(img); return img; } GMICMapType.prototype.realeaseTile = function(tile) { var idx = this.Cache.indexOf(tile); if(idx!=-1) this.Cache.splice(idx, 1); tile=null; } /*GMICMapType.prototype.name = "Image Cutter"; GMICMapType.prototype.alt = "Image Cutter Tiles"; GMICMapType.prototype.setOpacity = function(newOpacity) { this.opacity = newOpacity; for (var i = 0; i < this.Cache.length; i++) { this.Cache[i].style.opacity = newOpacity; //mozilla this.Cache[i].style.filter = "alpha(opacity=" + newOpacity * 100 + ")"; //ie } }*/ function getWindowHeight() { if (window.self&&self.innerHeight) { return self.innerHeight; } if (document.documentElement&&document.documentElement.clientHeight) { return document.documentElement.clientHeight; } return 0; } function resizeMapDiv() { //Resize the height of the div containing the map. //Do not call any map methods here as the resize is called before the map is created. var d=document.getElementById("map"); var offsetTop=0; for (var elem=d; elem!=null; elem=elem.offsetParent) { offsetTop+=elem.offsetTop; } /*var height=getWindowHeight()-offsetTop-64; if (height>=0) { d.style.height=height+"px"; }*/ d.style.minHeight = "384px"; } /* Disable and enable dragging based on zoom level. */ function draggingManager(map, curr_zoom, old_zoom) { if (curr_zoom < 2) { if (old_zoom > 2) { map.setCenter(new google.maps.LatLng(centreLat, centreLon)); } map.draggable = false; } else { map.draggable = true; } currentZoom = curr_zoom; return; } /* These are for drag and drop markers. function updateMarkerStatus(str) { document.getElementById('markerStatus').innerHTML = str; } function updateMarkerPosition(latlng) { document.getElementById('info').innerHTML = [ latlng.lat(), latlng.lng() ].join(', '); } /* End D&D Marker */ function init_map() { resizeMapDiv(); var latlng = new google.maps.LatLng(centreLat, centreLon); var myOptions = { zoom: initialZoom, backgroundColor: 'transparent', minZoom: 1, maxZoom: 3, draggable: true, center: latlng, panControl: true, zoomControl: true, mapTypeControl: true, scaleControl: false, streetViewControl: false, overviewMapControl: true, mapTypeControlOptions: { mapTypeIds: ["CoNmap"] }, mapTypeId: "CoNmap" } map = new google.maps.Map(document.getElementById("map"), myOptions); gmicMapType = new GMICMapType(); map.mapTypes.set("CoNmap",gmicMapType); ///////////////////////////////////////////////////////////////////////////////////// //Add any markers here e.g. // var marker = new google.maps.Marker({ // map:map, // position: new google.maps.LatLng(x,y), // title: "My Marker" // }); ///////////////////////////////////////////////////////////////////////////////////// var iconBase = "excalibur/"; markers = []; marker_listeners = []; locations = []; locationsDiv = []; marker_counter = 0; function createLocationMarker(latlng, id_text, div_id, shop_marker) { marker_icon = iconBase + 'excalibur.png'; marker_shadow = iconBase + 'excalibur_shadow.png'; var marker = new MarkerWithLabel({ map: map, position: latlng, labelContent: id_text, labelVisible: false, zIndex: 1, labelClass: 'locationName', labelAnchor: new google.maps.Point(20, 0), icon: { url: marker_icon, size: new google.maps.Size(30,30), anchor: new google.maps.Point(0,30) }, shadow: marker_shadow, visible: false }); marker.set('div_id', div_id); //if (shop_marker == "sword") { marker_listeners[marker_counter] = google.maps.event.addListener(marker, "click", function() { var div_id = marker.get('div_id'); show(div_id); }); marker_counter += 1; //} google.maps.event.addListener(marker, "mouseover", function() { marker.set('labelVisible',true); }); google.maps.event.addListener(marker, "mouseout", function() { marker.set('labelVisible',false); }); return marker; } markers[0] = createLocationMarker(new google.maps.LatLng(2.81137,-7.03125), "Araguay Woods", "araguay", ''); locations[0] = "Araguay Woods"; locationsDiv[0] = "araguay"; markers[1] = createLocationMarker(new google.maps.LatLng(-43.5804,19.6875), "Bariaus Hill", "bariaushill", ''); locations[1] = "Bariaus Hill"; locationsDiv[1] = "bariaushill"; markers[2] = createLocationMarker(new google.maps.LatLng(-61.2702,32.3438), "Bariaus Valley", "bariausvalley", ''); locations[2] = "Bariaus Valley"; locationsDiv[2] = "bariausvalley"; markers[3] = createLocationMarker(new google.maps.LatLng(11.8674,40.7812), "Bed Desert", "bed", ''); locations[3] = "Bed Desert"; locationsDiv[3] = "bed"; markers[4] = createLocationMarker(new google.maps.LatLng(35.4607,39.375), "Bervenia Free City", "berveniacity", ''); locations[4] = "Bervenia Free City"; locationsDiv[4] = "berveniacity"; markers[5] = createLocationMarker(new google.maps.LatLng(43.0689,-42.1875), "Bervenia Volcano", "berveniavolcano", ''); locations[5] = "Bervenia Volcano"; locationsDiv[5] = "berveniavolcano"; markers[6] = createLocationMarker(new google.maps.LatLng(-10.4878,28.8281), "Bethla Garrison", "bethla", ''); locations[6] = "Bethla Garrison"; locationsDiv[6] = "bethla"; markers[7] = createLocationMarker(new google.maps.LatLng(-64.4728,96.3281), "Deep Dungeon", "deepdungeon", ''); locations[7] = "Deep Dungeon"; locationsDiv[7] = "deepdungeon"; markers[8] = createLocationMarker(new google.maps.LatLng(49.838,27.4219), "Doguola Pass", "doguola", ''); locations[8] = "Doguola Pass"; locationsDiv[8] = "doguola"; markers[9] = createLocationMarker(new google.maps.LatLng(-14.6048,59.0625), "Doldobar Swamp", "doldobar", ''); locations[9] = "Doldobar Swamp"; locationsDiv[9] = "doldobar"; markers[10] = createLocationMarker(new google.maps.LatLng(-2.1089,-34.4531), "Dorter Trade City", "dorter", ''); locations[10] = "Dorter Trade City"; locationsDiv[10] = "dorter"; markers[11] = createLocationMarker(new google.maps.LatLng(29.5352,77.3438), "Finath River", "finath", ''); locations[11] = "Finath River"; locationsDiv[11] = "finath"; markers[12] = createLocationMarker(new google.maps.LatLng(51.618,-80.8594), "Fovoham Plains", "fovoham", ''); locations[12] = "Fovoham Plains"; locationsDiv[12] = "fovoham"; markers[13] = createLocationMarker(new google.maps.LatLng(7.71099,-85.7812), "Gariland Magic
City", "gariland", ''); locations[13] = "Gariland Magic
City"; locationsDiv[13] = "gariland"; markers[14] = createLocationMarker(new google.maps.LatLng(11.1784,109.688), "Germinas Peak", "germinas", ''); locations[14] = "Germinas Peak"; locationsDiv[14] = "germinas"; markers[15] = createLocationMarker(new google.maps.LatLng(24.5271,-2.8125), "Goland Coal City", "goland", ''); locations[15] = "Goland Coal City"; locationsDiv[15] = "goland"; markers[16] = createLocationMarker(new google.maps.LatLng(-67.0674,4.21875), "Golgorand
Execution Site", "golgorand", ''); locations[16] = "Golgorand
Execution Site"; locationsDiv[16] = "golgorand"; markers[17] = createLocationMarker(new google.maps.LatLng(-60.587,-68.9062), "Goug Machine City", "goug", ''); locations[17] = "Goug Machine City"; locationsDiv[17] = "goug"; markers[18] = createLocationMarker(new google.maps.LatLng(55.7766,-5.625), "Grog Hill", "grog", ''); locations[18] = "Grog Hill"; locationsDiv[18] = "grog"; markers[19] = createLocationMarker(new google.maps.LatLng(37.1603,-130.781), "Igros Castle", "igros", ''); locations[19] = "Igros Castle"; locationsDiv[19] = "igros"; markers[20] = createLocationMarker(new google.maps.LatLng(31.3536,-73.8281), "Lenalia Plateau", "lenaliaplateau", ''); locations[20] = "Lenalia Plateau"; locationsDiv[20] = "lenaliaplateau"; markers[21] = createLocationMarker(new google.maps.LatLng(43.0689,0.703125), "Lesalia Imperial
Capital", "lesaliaimperial", ''); locations[21] = "Lesalia Imperial
Capital"; locationsDiv[21] = "lesaliaimperial"; markers[22] = createLocationMarker(new google.maps.LatLng(-30.1451,72.4219), "Limberry Castle", "limberry", ''); locations[22] = "Limberry Castle"; locationsDiv[22] = "limberry"; markers[23] = createLocationMarker(new google.maps.LatLng(-56.945,8.4375), "Lionel Castle", "lionel", ''); locations[23] = "Lionel Castle"; locationsDiv[23] = "lionel"; markers[24] = createLocationMarker(new google.maps.LatLng(13.9234,-119.531), "Mandalia Plains", "mandalia", ''); locations[24] = "Mandalia Plains"; locationsDiv[24] = "mandalia"; markers[25] = createLocationMarker(new google.maps.LatLng(-31.3536,-88.5938), "St. Murond Temple", "murond", ''); locations[25] = "St. Murond Temple"; locationsDiv[25] = "murond"; markers[26] = createLocationMarker(new google.maps.LatLng(63.2336,69.6094), "Nelveska Temple", "nelveska", ''); locations[26] = "Nelveska Temple"; locationsDiv[26] = "nelveska"; markers[27] = createLocationMarker(new google.maps.LatLng(-13.9234,-20.3906), "Orbonne Monastery", "orbonne", ''); locations[27] = "Orbonne Monastery"; locationsDiv[27] = "orbonne"; markers[28] = createLocationMarker(new google.maps.LatLng(-8.40717,87.1875), "Poeskas Lake", "poeskas", ''); locations[28] = "Poeskas Lake"; locationsDiv[28] = "poeskas"; markers[29] = createLocationMarker(new google.maps.LatLng(60.2398,-55.5469), "Riovanes Castle", "riovanes", ''); locations[29] = "Riovanes Castle"; locationsDiv[29] = "riovanes"; markers[30] = createLocationMarker(new google.maps.LatLng(14.6048,-56.25), "Sweegy Woods", "sweegy", ''); locations[30] = "Sweegy Woods"; locationsDiv[30] = "sweegy"; markers[31] = createLocationMarker(new google.maps.LatLng(-12.5546,-115.312), "Thieves' Fort", "thievesfort", ''); locations[31] = "Thieves' Fort"; locationsDiv[31] = "thievesfort"; markers[32] = createLocationMarker(new google.maps.LatLng(-69.1626,42.1875), "Warjilis Trade
City", "warjilis", ''); locations[32] = "Warjilis Trade
City"; locationsDiv[32] = "warjilis"; markers[33] = createLocationMarker(new google.maps.LatLng(65.0721,-21.7969), "Yardow Fort City", "yardow", ''); locations[33] = "Yardow Fort City"; locationsDiv[33] = "yardow"; markers[34] = createLocationMarker(new google.maps.LatLng(68.1389,-47.8125), "Yuguo Woods", "yuguo", ''); locations[34] = "Yuguo Woods"; locationsDiv[34] = "yuguo"; markers[35] = createLocationMarker(new google.maps.LatLng(-36.5979,0), "Zaland Fort City", "zaland", ''); locations[35] = "Zaland Fort City"; locationsDiv[35] = "zaland"; markers[36] = createLocationMarker(new google.maps.LatLng(31.3536,114.609), "Zarghidas Trade
City", "zarghidas", ''); locations[36] = "Zarghidas Trade
City"; locationsDiv[36] = "zarghidas"; markers[37] = createLocationMarker(new google.maps.LatLng(40.4469,-101.25), "Fort Zeakden", "zeakden", ''); locations[37] = "Fort Zeakden"; locationsDiv[37] = "zeakden"; markers[38] = createLocationMarker(new google.maps.LatLng(19.9733,-25.3125), "Zeklaus Desert", "zeklaus", ''); locations[38] = "Zeklaus Desert"; locationsDiv[38] = "zeklaus"; markers[39] = createLocationMarker(new google.maps.LatLng(47.0402,87.8906), "Zeltennia Castle", "zeltennia", ''); locations[39] = "Zeltennia Castle"; locationsDiv[39] = "zeltennia"; markers[40] = createLocationMarker(new google.maps.LatLng(-51.618,-26.0156), "Zigolis Swamp", "zigolis", ''); locations[40] = "Zigolis Swamp"; locationsDiv[40] = "zigolis"; markers[41] = createLocationMarker(new google.maps.LatLng(-8.40717,14.7656), "Zirekile Falls", "zirekile", ''); locations[41] = "Zirekile Falls"; locationsDiv[41] = "zirekile"; /* Make all the markers visible */ for (var i = 0; i < markers.length ; i++ ) { markers[i].visible = true; } ///////////////////////////////////////////////////////////////////////////////////// /* This is the drag and drop marker from http://gmaps-samples-v3.googlecode.com/svn/trunk/draggable-markers/draggable-markers.html var ddmarker = new google.maps.Marker({ position: latlng, title: 'Drag and Drop', map: map, draggable: true }); // Update current position info. updateMarkerPosition(latlng); //geocodePosition(latlng); // Add dragging event listeners. google.maps.event.addListener(ddmarker, 'dragstart', function() { updateMarkerAddress('Dragging...'); }); google.maps.event.addListener(ddmarker, 'drag', function() { updateMarkerStatus('Dragging...'); updateMarkerPosition(ddmarker.getPosition()); }); google.maps.event.addListener(ddmarker, 'dragend', function() { updateMarkerStatus('Drag ended'); //geocodePosition(ddmarker.getPosition()); }); /* End drag and drop marker */ /* Do a zoom-change listener. */ var zoom_listener = google.maps.event.addListener(map, 'zoom_changed', function() { new_zoom = map.getZoom(); allowedBounds = set_allowed_bounds(new_zoom); boundLimits = set_bound_limits(allowedBounds); draggingManager(map, new_zoom, currentZoom); }); /* Do a center-changed listener to try to limit panning. PAN! */ /* bounds of the desired area. This is what was tricky before */ /* I think this will need to be based on zoom level. */ function set_allowed_bounds(zoom) { /* where is zoom 1? we don't need this for them. */ if (zoom == 2) { allowedBounds = new google.maps.LatLngBounds( /* good at level 2 */ new google.maps.LatLng(-49,-60), new google.maps.LatLng(49,60) ); } if (zoom == 3) { allowedBounds = new google.maps.LatLngBounds( /* good at level 3 */ new google.maps.LatLng(-65,-90), new google.maps.LatLng(65,90) ); } return allowedBounds; } function set_bound_limits(allowedBounds) { var boundLimits = { maxLat : allowedBounds.getNorthEast().lat(), maxLng : allowedBounds.getNorthEast().lng(), minLat : allowedBounds.getSouthWest().lat(), minLng : allowedBounds.getSouthWest().lng() }; return boundLimits; } var lastValidCenter = map.getCenter(); var newLat, newLng; google.maps.event.addListener(map, 'center_changed', function() { center = map.getCenter(); if (allowedBounds.contains(center)) { // still within valid bounds, so save the last valid position lastValidCenter = map.getCenter(); return; } newLat = lastValidCenter.lat(); newLng = lastValidCenter.lng(); if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){ newLng = center.lng(); } if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){ newLat = center.lat(); } map.panTo(new google.maps.LatLng(newLat, newLng)); }); draggingManager(map, initialZoom, currentZoom); $("#mapwrapper").css({'width': $("#map").width()+'px'}); } var last = null; function show(id) { var itm = "#"+id; //console.log(id); var itm = $(itm); if (!itm) { // do nothing } else { $(".metalocation").hide(); $(itm).show(); if (last && last != itm) { $(last).hide(); } last = itm; } } google.maps.event.addDomListener(window, 'load', init_map); //google.maps.event.addDomListener(window, 'resize', resizeMapDiv); /* global scoped var to use in the show maps function below */ mapdivs = "hidden"; function mapToggler() { dumpListeners(); createListeners(mapdivs); adjustFloat(mapdivs); displayMapDivs(mapdivs); if (mapdivs == "hidden") { mapdivs = "visible"; } else { mapdivs = "hidden"; } } function dumpListeners(){ console.log(marker_listeners); for (var i = 0; i < marker_listeners.length; i++) { element = marker_listeners[i]; google.maps.event.removeListener(element); } } function createListeners(status) { if (status=="hidden") { //we are making the divs all visible, so we set the listeners to be links to hashes. $(markers).each(function(i,marker){ marker_listeners[i] = google.maps.event.addListener(marker, "click", function() { var primaryURL = document.URL.split("#"); window.location = primaryURL[0] + "#" + locationsDiv[i]; }); //GEvent.addListener(marker, "click", function(){ var primaryURL = document.URL.split("#"); window.location = primaryURL[0] + "#" + locationsDiv[i] }); }); } else { //we are reverting back to the standard GMap click actions. $(markers).each(function(i,marker){ marker_listeners[i] = google.maps.event.addListener(marker, "click", function() { var div_id = marker.get('div_id'); show(div_id); }); }); } } function adjustFloat(status) { if (status=="hidden") { //we are making the divs all visible, so we need to break the float. $(".metalocation").css("clear","both"); } else { $(".metalocation").css("clear","none"); } } function displayMapDivs(status) { if (status=="hidden") { //we are making the divs all visible, so we need to... make the divs all visible. idiot. $(".metalocation").hide(); $(".metalocation").show(); } else { $(".metalocation").hide(); } }