var centreLat=0.0; var centreLon=0.0; var initialZoom=2; 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 = "maps/worldmap/"+world+"/"+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 = "584px"; } /* 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: '#152b5a', minZoom: 2, maxZoom: 5, 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 = "maps/sword/"; markers = []; marker_listeners = []; locations = []; locationsDiv = []; marker_counter = 0; function createLocationMarker(latlng, id_text, div_id, shop_marker) { if (shop_marker == "sword") { marker_icon = iconBase + 'image.png'; marker_shadow = iconBase + 'shadow.png'; } else { marker_icon = iconBase + 'ball.png'; marker_shadow = iconBase + 'ball_shadow.png'; } var marker = new MarkerWithLabel({ map: map, position: latlng, labelContent: id_text, labelVisible: false, labelClass: 'locationName', labelAnchor: new google.maps.Point(20, 0), icon: marker_icon, 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(55.1789,-75.6738), "Kohlingen", "wob_kohlingen", 'sword'); locations[0] = "Kohlingen"; locationsDiv[0] = "wob_kohlingen"; markers[1] = createLocationMarker(new google.maps.LatLng(57.4686,-32.6953), "Narshe", "wob_narshe", 'sword'); locations[1] = "Narshe"; locationsDiv[1] = "wob_narshe"; markers[2] = createLocationMarker(new google.maps.LatLng(44.5278,-7.69043), "Nikeah", "wob_nikeah", 'sword'); locations[2] = "Nikeah"; locationsDiv[2] = "wob_nikeah"; markers[3] = createLocationMarker(new google.maps.LatLng(36.3859,-47.2852), "Figaro Castle", "wob_figaro_castle", 'sword'); locations[3] = "Figaro Castle"; locationsDiv[3] = "wob_figaro_castle"; markers[4] = createLocationMarker(new google.maps.LatLng(25.483,-79.3652), "Zozo", "wob_zozo", 'ball'); locations[4] = "Zozo"; locationsDiv[4] = "wob_zozo"; markers[5] = createLocationMarker(new google.maps.LatLng(-2.46018,-75.498), "Jidoor", "wob_jidoor", 'sword'); locations[5] = "Jidoor"; locationsDiv[5] = "wob_jidoor"; markers[6] = createLocationMarker(new google.maps.LatLng(-19.7253,-61.9189), "Opera House", "wob_opera_house", 'ball'); locations[6] = "Opera House"; locationsDiv[6] = "wob_opera_house"; markers[7] = createLocationMarker(new google.maps.LatLng(20.6328,-29.5312), "Cabin", "wob_cabin", 'sword'); locations[7] = "Cabin"; locationsDiv[7] = "wob_cabin"; markers[8] = createLocationMarker(new google.maps.LatLng(20.0972,-19.0723), "Mt. Kolts", "wob_mt_kolts", 'ball'); locations[8] = "Mt. Kolts"; locationsDiv[8] = "wob_mt_kolts"; markers[9] = createLocationMarker(new google.maps.LatLng(11.5661,-31.5527), "South Figaro", "wob_south_figaro", 'sword'); locations[9] = "South Figaro"; locationsDiv[9] = "wob_south_figaro"; markers[10] = createLocationMarker(new google.maps.LatLng(-15.9613,-5.93262), "Tzen", "wob_tzen", 'sword'); locations[10] = "Tzen"; locationsDiv[10] = "wob_tzen"; markers[11] = createLocationMarker(new google.maps.LatLng(-40.5138,-5.27344), "Vector", "wob_vector", 'sword'); locations[11] = "Vector"; locationsDiv[11] = "wob_vector"; markers[12] = createLocationMarker(new google.maps.LatLng(-44.4652,28.3447), "Imperial
Observation Post", "wob_imperial_observation_post", 'ball'); locations[12] = "Imperial
Observation Post"; locationsDiv[12] = "wob_imperial_observation_post"; markers[13] = createLocationMarker(new google.maps.LatLng(-49.2678,8.08594), "Albrook", "wob_albrook", 'sword'); locations[13] = "Albrook"; locationsDiv[13] = "wob_albrook"; markers[14] = createLocationMarker(new google.maps.LatLng(-44.5278,30.9375), "Sealed Gate", "wob_sealed_gate", 'ball'); locations[14] = "Sealed Gate"; locationsDiv[14] = "wob_sealed_gate"; markers[15] = createLocationMarker(new google.maps.LatLng(-59.4897,-46.2305), "Maranda", "wob_maranda", 'sword'); locations[15] = "Maranda"; locationsDiv[15] = "wob_maranda"; markers[16] = createLocationMarker(new google.maps.LatLng(39.7266,37.4414), "Doma Imperial Base", "wob_doma_imperial_base", 'ball'); locations[16] = "Doma Imperial Base"; locationsDiv[16] = "wob_doma_imperial_base"; markers[17] = createLocationMarker(new google.maps.LatLng(30.9022,21.7089), "Doma", "wob_doma", 'ball'); locations[17] = "Doma"; locationsDiv[17] = "wob_doma"; markers[18] = createLocationMarker(new google.maps.LatLng(32.3614,37.8369), "Phantom Forest", "wob_phantom_forest", 'ball'); locations[18] = "Phantom Forest"; locationsDiv[18] = "wob_phantom_forest"; markers[19] = createLocationMarker(new google.maps.LatLng(24.7668,43.0664), "Baren Falls", "wob_baren_falls", 'ball'); locations[19] = "Baren Falls"; locationsDiv[19] = "wob_baren_falls"; markers[20] = createLocationMarker(new google.maps.LatLng(-2.06498,57.832), "The Veldt", "wob_the_veldt", 'ball'); locations[20] = "The Veldt"; locationsDiv[20] = "wob_the_veldt"; markers[21] = createLocationMarker(new google.maps.LatLng(56.7286,28.3001), "Old Man's House", "wob_old_mans_house", 'ball'); locations[21] = "Old Man's House"; locationsDiv[21] = "wob_old_mans_house"; markers[22] = createLocationMarker(new google.maps.LatLng(9.31899,69.3018), "Mobliz", "wob_mobliz", 'sword'); locations[22] = "Mobliz"; locationsDiv[22] = "wob_mobliz"; markers[23] = createLocationMarker(new google.maps.LatLng(-0.439449,91.7578), "Thamasa", "wob_thamasa", 'sword'); locations[23] = "Thamasa"; locationsDiv[23] = "wob_thamasa"; markers[24] = createLocationMarker(new google.maps.LatLng(56.072,-20.3906), "Lethe River", "wob_lethe_river", 'ball'); locations[24] = "Lethe River"; locationsDiv[24] = "wob_lethe_river"; markers[25] = createLocationMarker(new google.maps.LatLng(42.5854,-17.5781), "Returners' Hideout", "wob_returners_hideout", 'ball'); locations[25] = "Returners' Hideout"; locationsDiv[25] = "wob_returners_hideout"; /* 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 are zooms one and two? we don't need this for them. */ if (zoom == 3) { allowedBounds = new google.maps.LatLngBounds( /* good at level 3 */ new google.maps.LatLng(-40,-32), new google.maps.LatLng(42,32) ); } else if (zoom == 4) { allowedBounds = new google.maps.LatLngBounds( /* good at level 4 */ new google.maps.LatLng(-58,-72), new google.maps.LatLng(58,72) ); } else if (zoom == 5) { allowedBounds = new google.maps.LatLngBounds( /* good at level 5 */ new google.maps.LatLng(-65,-90), new google.maps.LatLng(70,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(); } }