From 3720c2adf722fb5f1ead5f7ff5174338ee9bc71e Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 26 Jun 2011 22:05:43 -0500 Subject: [PATCH] Add support for URL-based parameter to override initial world, map, zoom, and center coordinate settings --- web/js/map.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/web/js/map.js b/web/js/map.js index 60a43e18..31c1c4d0 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -123,6 +123,26 @@ DynMap.prototype = { }); me.defaultworld = me.defaultworld || world; }); + var urlarg = me.getParameterByName('worldname'); + if(urlarg != "") { + me.defaultworld = me.worlds[urlarg] || me.defaultworld; + } + urlarg = me.getParameterByName('mapname'); + if(urlarg != "") { + me.defaultworld.defaultmap = me.defaultworld.maps[urlarg] || me.defaultworld.defaultmap; + } + urlarg = parseInt(me.getParameterByName('x'),10); + if(urlarg != NaN) { + me.defaultworld.center.x = urlarg; + } + urlarg = parseInt(me.getParameterByName('y'),10); + if(urlarg != NaN) { + me.defaultworld.center.y = urlarg; + } + urlarg = parseInt(me.getParameterByName('z'), 10); + if(urlarg != NaN) { + me.defaultworld.center.z = urlarg; + } }, initialize: function() { var me = this; @@ -134,6 +154,9 @@ DynMap.prototype = { (mapContainer = $('
')) .addClass('map') .appendTo(container); + + var urlzoom = parseInt(me.getParameterByName('zoom'),10); + if(urlzoom != NaN) { me.options.defaultzoom = urlzoom; } var map = this.map = new google.maps.Map(mapContainer.get(0), { zoom: me.options.defaultzoom || 0, @@ -592,7 +615,17 @@ DynMap.prototype = { col = me.maptype.background; } $('.map').css('background', col); - } + }, + getParameterByName: function(name) { + name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); + var regexS = "[\\?&]"+name+"=([^&#]*)"; + var regex = new RegExp( regexS ); + var results = regex.exec( window.location.href ); + if( results == null ) + return ""; + else + return decodeURIComponent(results[1].replace(/\+/g, " ")); + } // TODO: Enable hash-links. /* updateLink: function() { var me = this;