Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't try to redownload grid data after a failed attempt. Changes the…

… API - will require updates to Google Maps and OpenLayers
  • Loading branch information...
commit 0cb32537ea87a7c210bf5328d9c5efd0c9afbbf9 1 parent f675073
authored May 27, 2011
31  build/wax.g.js
@@ -211,7 +211,7 @@ wax.request = {
211 211
     get: function(url, callback) {
212 212
         // Cache hit.
213 213
         if (this.cache[url]) {
214  
-            return callback(this.cache[url]);
  214
+            return callback(this.cache[url][0], this.cache[url][1]);
215 215
         // Cache miss.
216 216
         } else {
217 217
             this.promises[url] = this.promises[url] || [];
@@ -227,16 +227,16 @@ wax.request = {
227 227
                 jsonpCallback: 'callback',
228 228
                 success: function(data) {
229 229
                     that.locks[url] = false;
230  
-                    that.cache[url] = data;
  230
+                    that.cache[url] = [null, data];
231 231
                     for (var i = 0; i < that.promises[url].length; i++) {
232  
-                        that.promises[url][i](that.cache[url]);
  232
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
233 233
                     }
234 234
                 },
235  
-                error: function() {
  235
+                error: function(err) {
236 236
                     that.locks[url] = false;
237  
-                    that.cache[url] = null;
  237
+                    that.cache[url] = [err, null];
238 238
                     for (var i = 0; i < that.promises[url].length; i++) {
239  
-                        that.promises[url][i](that.cache[url]);
  239
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
240 240
                     }
241 241
                 }
242 242
             });
@@ -273,8 +273,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
273 273
   var tileX = offset.left;
274 274
   var tileY = offset.top;
275 275
 
276  
-  if (Math.floor((y - tileY) / this.tileRes) > 256 ||
277  
-    Math.floor((x - tileX) / this.tileRes) > 256) return;
  276
+  if (Math.floor((y - tileY) / this.tileRes) > 256) return;
  277
+  if (Math.floor((x - tileX) / this.tileRes) > 256) return;
278 278
 
279 279
   var key = this.grid_tile.grid[
280 280
      Math.floor((y - tileY) / this.tileRes)
@@ -309,11 +309,12 @@ wax.GridManager = function() {
309 309
 // and gets grid data, and tries to avoid re-downloading either.
310 310
 wax.GridManager.prototype.getGrid = function(url, callback) {
311 311
     var that = this;
312  
-    that.getFormatter(that.formatterUrl(url), function(f) {
313  
-        if (!f) return callback(false);
  312
+    that.getFormatter(that.formatterUrl(url), function(err, f) {
  313
+        if (err || !f) return callback(err, null);
314 314
 
315  
-        wax.request.get(that.tileDataUrl(url), function(t) {
316  
-            callback(new wax.GridInstance(t, f));
  315
+        wax.request.get(that.tileDataUrl(url), function(err, t) {
  316
+            if (err) return callback(err, null);
  317
+            callback(null, new wax.GridInstance(t, f));
317 318
         });
318 319
     });
319 320
 };
@@ -343,16 +344,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
343 344
   var that = this;
344 345
   // Formatter is cached.
345 346
   if (typeof this.formatters[url] !== 'undefined') {
346  
-    callback(this.formatters[url]);
  347
+    callback(null, this.formatters[url]);
347 348
     return;
348 349
   } else {
349  
-    wax.request.get(url, function(data) {
  350
+    wax.request.get(url, function(err, data) {
350 351
         if (data && data.formatter) {
351 352
             that.formatters[url] = new wax.Formatter(data);
352 353
         } else {
353 354
             that.formatters[url] = false;
354 355
         }
355  
-        callback(that.formatters[url]);
  356
+        callback(err, that.formatters[url]);
356 357
     });
357 358
   }
358 359
 };
2  build/wax.g.min.js
@@ -31,4 +31,4 @@
31 31
 //         }
32 32
 //     ];
33 33
 //     wax.Record(gmap);
34  
-var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=b;for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a])},error:function(){c.locks[a]=!1,c.cache[a]=null;for(var b=0;b<c.promises[a].length;b++)c.promises[a][b](c.cache[a])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256||Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d){if(!d)return b(!1);wax.request.get(c.tileDataUrl(a),function(a){b(new wax.GridInstance(a,d))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(this.formatters[a]):wax.request.get(a,function(d){d&&d.formatter?c.formatters[a]=new wax.Formatter(d):c.formatters[a]=!1,b(c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}};var wax=wax||{};wax.g=wax.g||{},wax.g.Controls=function(a){this.map=a,this.mapDiv=!1;for(var b in a)if(a[b]&&a[b].nodeType>0){this.mapDiv=a[b];break}},wax.g.Controls.prototype.calculateGrid=function(){if(!this.map.interaction_grid){var a=$("div.interactive-div-"+this.map.getZoom()+" img",this.mapDiv),b=$(this.mapDiv).offset(),c=$(a).map(function(c){var d=$(a[c]).offset();return{xy:{left:d.left-b.left,top:d.top-b.top},tile:a[c]}});return c}},wax.g.Controls.prototype.interaction=function(a){a=a||{};var b=this,c=new wax.GridManager,d=null,e=a.callbacks||{out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click},f=function(a,b){if(b.top<a.y&&b.top+256>a.y&&b.left<a.x&&b.left+256>a.x)return!0},g=$.proxy(function(a,b){var c=!1,d=this.calculateGrid();for(var e=0;e<d.length&&!c;e++)if(f(b.pixel,d[e].xy))var c=d[e];return c},this);google.maps.event.addListener(this.map,"mousemove",function(a){var f={format:"teaser"},h=g(this.map,a);!h||c.getGrid($(h.tile).attr("src"),function(c){if(!!c){var g=c.getFeature(a.pixel.x+$(b.mapDiv).offset().left,a.pixel.y+$(b.mapDiv).offset().top,h.tile,f);g!==d&&(e.out(g,$(b.mapDiv),0),e.over(g,$(b.mapDiv),0),d=g)}})}),google.maps.event.addListener(this.map,"click",function(d){var f={format:a.clickAction||"full"},h=g(this.map,d);!h||c.getGrid($(h.tile).attr("src"),function(a){if(!!a){var c=a.getFeature(d.pixel.x+$(b.mapDiv).offset().left,d.pixel.y+$(b.mapDiv).offset().top,h.tile,f);c&&(f.format=="full"?e.click(c,$(b.mapDiv),0):window.location=c)}})});return this},wax.g.Controls.prototype.legend=function(){var a=new wax.Legend($(this.mapDiv)),b=null;google.maps.event.addListener(this.map,"idle",$.proxy(function(){if(!b){var c=$("div.interactive-div-"+this.map.getZoom()+" img:first",this.mapDiv);c&&(b=c.attr("src"))&&a.render([b])}},this));return this},wax.g.Controls.prototype.embedder=function(a){$(this.mapDiv).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+a+"'>"+$("#"+a).html()+"</div>"));return this};var wax=wax||{};wax.g=wax.g||{},wax.g.MapType=function(a){a=a||{},this.name=a.name||"",this.alt=a.alt||"",this.filetype=a.filetype||".png",this.layerName=a.layerName||"world-light",a.zoomRange?(this.minZoom=a.zoomRange[0],this.maxZoom=a.zoomRange[1]):(this.minZoom=0,this.maxZoom=18),this.baseUrl=a.baseUrl||"http://a.tile.mapbox.com/",this.blankImage=a.blankImage||"",this.interactive=!0,this.tileSize=new google.maps.Size(256,256),this.cache={}},wax.g.MapType.prototype.getTile=function(a,b,c){var d=b+"/"+a.x+"/"+a.y;this.cache[d]=this.cache[d]||$("<div></div>").addClass("interactive-div-"+b).width(256).height(256).data("gTileKey",d).append($("<img />").width(256).height(256).attr("src",this.getTileUrl(a,b)).error(function(){$(this).hide()}))[0];return this.cache[d]},wax.g.MapType.prototype.releaseTile=function(a){var b=$(a).data("gTileKey");this.cache[b]&&delete this.cache[b],$(a).remove()},wax.g.MapType.prototype.getTileUrl=function(a,b){var c=Math.pow(2,b),d=c-1-a.y,e=a.x%c;e=e<0?a.x%c+c:e;return d>=0?this.baseUrl+"1.0.0/"+this.layerName+"/"+b+"/"+e+"/"+d+this.filetype:this.blankImage}
  34
+var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a][0],this.cache[a][1]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=[null,b];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])},error:function(b){c.locks[a]=!1,c.cache[a]=[b,null];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256)return;if(Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d,e){if(d||!e)return b(d,null);wax.request.get(c.tileDataUrl(a),function(a,c){if(a)return b(a,null);b(null,new wax.GridInstance(c,e))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(null,this.formatters[a]):wax.request.get(a,function(d,e){e&&e.formatter?c.formatters[a]=new wax.Formatter(e):c.formatters[a]=!1,b(d,c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}};var wax=wax||{};wax.g=wax.g||{},wax.g.Controls=function(a){this.map=a,this.mapDiv=!1;for(var b in a)if(a[b]&&a[b].nodeType>0){this.mapDiv=a[b];break}},wax.g.Controls.prototype.calculateGrid=function(){if(!this.map.interaction_grid){var a=$("div.interactive-div-"+this.map.getZoom()+" img",this.mapDiv),b=$(this.mapDiv).offset(),c=$(a).map(function(c){var d=$(a[c]).offset();return{xy:{left:d.left-b.left,top:d.top-b.top},tile:a[c]}});return c}},wax.g.Controls.prototype.interaction=function(a){a=a||{};var b=this,c=new wax.GridManager,d=null,e=a.callbacks||{out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click},f=function(a,b){if(b.top<a.y&&b.top+256>a.y&&b.left<a.x&&b.left+256>a.x)return!0},g=$.proxy(function(a,b){var c=!1,d=this.calculateGrid();for(var e=0;e<d.length&&!c;e++)if(f(b.pixel,d[e].xy))var c=d[e];return c},this);google.maps.event.addListener(this.map,"mousemove",function(a){var f={format:"teaser"},h=g(this.map,a);!h||c.getGrid($(h.tile).attr("src"),function(c){if(!!c){var g=c.getFeature(a.pixel.x+$(b.mapDiv).offset().left,a.pixel.y+$(b.mapDiv).offset().top,h.tile,f);g!==d&&(e.out(g,$(b.mapDiv),0),e.over(g,$(b.mapDiv),0),d=g)}})}),google.maps.event.addListener(this.map,"click",function(d){var f={format:a.clickAction||"full"},h=g(this.map,d);!h||c.getGrid($(h.tile).attr("src"),function(a){if(!!a){var c=a.getFeature(d.pixel.x+$(b.mapDiv).offset().left,d.pixel.y+$(b.mapDiv).offset().top,h.tile,f);c&&(f.format=="full"?e.click(c,$(b.mapDiv),0):window.location=c)}})});return this},wax.g.Controls.prototype.legend=function(){var a=new wax.Legend($(this.mapDiv)),b=null;google.maps.event.addListener(this.map,"idle",$.proxy(function(){if(!b){var c=$("div.interactive-div-"+this.map.getZoom()+" img:first",this.mapDiv);c&&(b=c.attr("src"))&&a.render([b])}},this));return this},wax.g.Controls.prototype.embedder=function(a){$(this.mapDiv).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+a+"'>"+$("#"+a).html()+"</div>"));return this};var wax=wax||{};wax.g=wax.g||{},wax.g.MapType=function(a){a=a||{},this.name=a.name||"",this.alt=a.alt||"",this.filetype=a.filetype||".png",this.layerName=a.layerName||"world-light",a.zoomRange?(this.minZoom=a.zoomRange[0],this.maxZoom=a.zoomRange[1]):(this.minZoom=0,this.maxZoom=18),this.baseUrl=a.baseUrl||"http://a.tile.mapbox.com/",this.blankImage=a.blankImage||"",this.interactive=!0,this.tileSize=new google.maps.Size(256,256),this.cache={}},wax.g.MapType.prototype.getTile=function(a,b,c){var d=b+"/"+a.x+"/"+a.y;this.cache[d]=this.cache[d]||$("<div></div>").addClass("interactive-div-"+b).width(256).height(256).data("gTileKey",d).append($("<img />").width(256).height(256).attr("src",this.getTileUrl(a,b)).error(function(){$(this).hide()}))[0];return this.cache[d]},wax.g.MapType.prototype.releaseTile=function(a){var b=$(a).data("gTileKey");this.cache[b]&&delete this.cache[b],$(a).remove()},wax.g.MapType.prototype.getTileUrl=function(a,b){var c=Math.pow(2,b),d=c-1-a.y,e=a.x%c;e=e<0?a.x%c+c:e;return d>=0?this.baseUrl+"1.0.0/"+this.layerName+"/"+b+"/"+e+"/"+d+this.filetype:this.blankImage}
34  build/wax.mm.js
@@ -217,7 +217,7 @@ wax.request = {
217 217
     get: function(url, callback) {
218 218
         // Cache hit.
219 219
         if (this.cache[url]) {
220  
-            return callback(this.cache[url]);
  220
+            return callback(this.cache[url][0], this.cache[url][1]);
221 221
         // Cache miss.
222 222
         } else {
223 223
             this.promises[url] = this.promises[url] || [];
@@ -233,16 +233,16 @@ wax.request = {
233 233
                 jsonpCallback: 'callback',
234 234
                 success: function(data) {
235 235
                     that.locks[url] = false;
236  
-                    that.cache[url] = data;
  236
+                    that.cache[url] = [null, data];
237 237
                     for (var i = 0; i < that.promises[url].length; i++) {
238  
-                        that.promises[url][i](that.cache[url]);
  238
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
239 239
                     }
240 240
                 },
241  
-                error: function() {
  241
+                error: function(err) {
242 242
                     that.locks[url] = false;
243  
-                    that.cache[url] = null;
  243
+                    that.cache[url] = [err, null];
244 244
                     for (var i = 0; i < that.promises[url].length; i++) {
245  
-                        that.promises[url][i](that.cache[url]);
  245
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
246 246
                     }
247 247
                 }
248 248
             });
@@ -279,8 +279,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
279 279
   var tileX = offset.left;
280 280
   var tileY = offset.top;
281 281
 
282  
-  if (Math.floor((y - tileY) / this.tileRes) > 256 ||
283  
-    Math.floor((x - tileX) / this.tileRes) > 256) return;
  282
+  if (Math.floor((y - tileY) / this.tileRes) > 256) return;
  283
+  if (Math.floor((x - tileX) / this.tileRes) > 256) return;
284 284
 
285 285
   var key = this.grid_tile.grid[
286 286
      Math.floor((y - tileY) / this.tileRes)
@@ -315,11 +315,12 @@ wax.GridManager = function() {
315 315
 // and gets grid data, and tries to avoid re-downloading either.
316 316
 wax.GridManager.prototype.getGrid = function(url, callback) {
317 317
     var that = this;
318  
-    that.getFormatter(that.formatterUrl(url), function(f) {
319  
-        if (!f) return callback(false);
  318
+    that.getFormatter(that.formatterUrl(url), function(err, f) {
  319
+        if (err || !f) return callback(err, null);
320 320
 
321  
-        wax.request.get(that.tileDataUrl(url), function(t) {
322  
-            callback(new wax.GridInstance(t, f));
  321
+        wax.request.get(that.tileDataUrl(url), function(err, t) {
  322
+            if (err) return callback(err, null);
  323
+            callback(null, new wax.GridInstance(t, f));
323 324
         });
324 325
     });
325 326
 };
@@ -349,16 +350,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
349 350
   var that = this;
350 351
   // Formatter is cached.
351 352
   if (typeof this.formatters[url] !== 'undefined') {
352  
-    callback(this.formatters[url]);
  353
+    callback(null, this.formatters[url]);
353 354
     return;
354 355
   } else {
355  
-    wax.request.get(url, function(data) {
  356
+    wax.request.get(url, function(err, data) {
356 357
         if (data && data.formatter) {
357 358
             that.formatters[url] = new wax.Formatter(data);
358 359
         } else {
359 360
             that.formatters[url] = false;
360 361
         }
361  
-        callback(that.formatters[url]);
  362
+        callback(err, that.formatters[url]);
362 363
     });
363 364
   }
364 365
 };
@@ -992,7 +993,8 @@ wax.interaction = function(map, options) {
992 993
             if (!this._onMove) this._onMove = wax.util.bind(function(evt) {
993 994
                 var tile = this.getTile(evt);
994 995
                 if (tile) {
995  
-                    this.waxGM.getGrid(tile.src, wax.util.bind(function(g) {
  996
+                    this.waxGM.getGrid(tile.src, wax.util.bind(function(err, g) {
  997
+                        if (err) return;
996 998
                         if (g) {
997 999
                             var feature = g.getFeature(evt.pageX, evt.pageY, tile, {
998 1000
                                 format: 'teaser'
2  build/wax.mm.min.js
@@ -3,4 +3,4 @@
3 3
   * copyright Dustin Diaz 2011
4 4
   * https://github.com/ded/reqwest
5 5
   * license MIT
6  
-  */!function(window){function readyState(a,b,c){return function(){a&&a.readyState==4&&(twoHundo.test(a.status)?b(a):c(a))}}function setHeaders(a,b){var c=b.headers||{};c.Accept="text/javascript, text/html, application/xml, text/xml, */*",c["X-Requested-With"]=c["X-Requested-With"]||"XMLHttpRequest";if(b.data){c["Content-type"]="application/x-www-form-urlencoded";for(var d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d],!1)}}function getCallbackName(a){var b=a.jsonpCallback||"callback";if(a.url.substr(-(b.length+2))==b+"=?"){var c="reqwest_"+uniqid++;a.url=a.url.substr(0,a.url.length-1)+c;return c}var d=new RegExp(b+"=([\\w]+)");return a.url.match(d)[1]}function generalCallback(a){lastValue=a}function getRequest(a,b,c){if(a.type!="jsonp"){var d=xhr();d.open(a.method||"GET",typeof a=="string"?a:a.url,!0),setHeaders(d,a),d.onreadystatechange=readyState(d,b,c),a.before&&a.before(d),d.send(a.data||null);return d}var e=doc.createElement("script"),f=getCallbackName(a);window[f]=generalCallback,e.type="text/javascript",e.src=a.url,e.async=!0,e.onload=function(){a.success&&a.success(lastValue),lastValue=undefined,head.removeChild(e)},head.insertBefore(e,topScript)}function Reqwest(a,b){this.o=a,this.fn=b,init.apply(this,arguments)}function setType(a){if(/\.json$/.test(a))return"json";if(/\.jsonp$/.test(a))return"jsonp";if(/\.js$/.test(a))return"js";if(/\.html?$/.test(a))return"html";if(/\.xml$/.test(a))return"xml";return"js"}function init(o,fn){function complete(a){o.complete&&o.complete(a)}function success(resp){o.timeout&&clearTimeout(self.timeout)&&(self.timeout=null);var r=resp.responseText;switch(type){case"json":resp=eval("("+r+")");break;case"js":resp=eval(r);break;case"html":resp=r}fn(resp),o.success&&o.success(resp),complete(resp)}function error(a){o.error&&o.error(a),complete(a)}this.url=typeof o=="string"?o:o.url,this.timeout=null;var type=o.type||setType(this.url),self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort(),error()},o.timeout)),this.request=getRequest(o,success,error)}function reqwest(a,b){return new Reqwest(a,b)}function enc(a){return encodeURIComponent(a)}function serial(a){var b=a.name;if(a.disabled||!b)return"";b=enc(b);switch(a.tagName.toLowerCase()){case"input":switch(a.type){case"reset":case"button":case"image":case"file":return"";case"checkbox":case"radio":return a.checked?b+"="+(a.value?enc(a.value):!0)+"&":"";default:return b+"="+(a.value?enc(a.value):!0)+"&"}break;case"textarea":return b+"="+enc(a.value)+"&";case"select":return b+"="+enc(a.options[a.selectedIndex].value)+"&"}return""}var twoHundo=/^20\d$/,doc=document,byTag="getElementsByTagName",topScript=doc[byTag]("script")[0],head=topScript.parentNode,xhr="XMLHttpRequest"in window?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},uniqid=0,lastValue;Reqwest.prototype={abort:function(){this.request.abort()},retry:function(){init.call(this,this.o,this.fn)}},reqwest.serialize=function(a){var b=a[byTag]("input"),c=a[byTag]("select"),d=a[byTag]("textarea");return(v(b).chain().toArray().map(serial).value().join("")+v(c).chain().toArray().map(serial).value().join("")+v(d).chain().toArray().map(serial).value().join("")).replace(/&$/,"")},reqwest.serializeArray=function(a){for(var b=this.serialize(a).split("&"),c=0,d=b.length,e=[],f;c<d;c++)b[c]&&(f=b[c].split("="))&&e.push({name:f[0],value:f[1]});return e};var old=window.reqwest;reqwest.noConflict=function(){window.reqwest=old;return this},window.reqwest=reqwest}(this);var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=b;for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a])},error:function(){c.locks[a]=!1,c.cache[a]=null;for(var b=0;b<c.promises[a].length;b++)c.promises[a][b](c.cache[a])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256||Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d){if(!d)return b(!1);wax.request.get(c.tileDataUrl(a),function(a){b(new wax.GridInstance(a,d))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(this.formatters[a]):wax.request.get(a,function(d){d&&d.formatter?c.formatters[a]=new wax.Formatter(d):c.formatters[a]=!1,b(c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}},wax=wax||{},wax.boxselector=function(a,b){var c=null,d=typeof b=="function"?b:b.callback,e={add:function(a){this.containerDiv=document.createElement("div"),this.containerDiv.id=a.parent.id+"-zoombox",this.containerDiv.className="boxselector-box-container",this.containerDiv.style.width=a.dimensions.x+"px",this.containerDiv.style.height=a.dimensions.y+"px",this.boxDiv=document.createElement("div"),this.boxDiv.id=a.parent.id+"-boxselector-box",this.boxDiv.className="boxselector-box",this.containerDiv.appendChild(this.boxDiv),a.parent.appendChild(this.containerDiv),com.modestmaps.addEvent(this.containerDiv,"mousedown",this.mouseDown()),a.addCallback("drawn",this.drawbox())},remove:function(){this.containerDiv.parentNode.removeChild(this.containerDiv),a.removeCallback("mousedown",this.drawbox())},getMousePoint:function(b){var c=new com.modestmaps.Point(b.clientX,b.clientY);c.x+=document.body.scrollLeft+document.documentElement.scrollLeft,c.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var d=a.parent;d;d=d.offsetParent)c.x-=d.offsetLeft,c.y-=d.offsetTop;return c},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){if(b.shiftKey){c=this.getMousePoint(b),this.boxDiv.style.left=c.x+"px",this.boxDiv.style.top=c.y+"px",com.modestmaps.addEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.addEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="crosshair";return com.modestmaps.cancelEvent(b)}},this));return this._mouseDown},mouseMove:function(a){this._mouseMove||(this._mouseMove=wax.util.bind(function(a){var b=this.getMousePoint(a);this.boxDiv.style.display="block",b.x<c.x?this.boxDiv.style.left=b.x+"px":this.boxDiv.style.left=c.x+"px",this.boxDiv.style.width=Math.abs(b.x-c.x)+"px",b.y<c.y?this.boxDiv.style.top=b.y+"px":this.boxDiv.style.top=c.y+"px",this.boxDiv.style.height=Math.abs(b.y-c.y)+"px";return com.modestmaps.cancelEvent(a)},this));return this._mouseMove},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){var f=e.getMousePoint(b),g=a.pointLocation(f),h=a.pointLocation(c),i=[new com.modestmaps.Location(Math.max(g.lat,h.lat),Math.min(g.lon,h.lon)),new com.modestmaps.Location(Math.min(g.lat,h.lat),Math.max(g.lon,h.lon))];this.box=[g,h],d(i),com.modestmaps.removeEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.removeEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="auto";return com.modestmaps.cancelEvent(b)},this));return this._mouseUp},drawbox:function(){this._drawbox||(this._drawbox=wax.util.bind(function(a,b){if(this.boxDiv){this.boxDiv.style.display="block",this.boxDiv.style.height="auto",this.boxDiv.style.width="auto";var c=a.locationPoint(this.box[0]),d=a.locationPoint(this.box[1]);this.boxDiv.style.left=Math.max(0,d.x)+"px",this.boxDiv.style.top=Math.max(0,d.y)+"px",this.boxDiv.style.right=Math.max(0,a.dimensions.x-c.x)+"px",this.boxDiv.style.bottom=Math.max(0,a.dimensions.y-c.y)+"px"}},this));return this._drawbox}};return e.add(a)};if(!com){var com={};com.modestmaps||(com.modestmaps={})}com.modestmaps.Map.prototype.embedder=function(a){a=a||{},$("#"+this.el+"-script").length&&$(this.parent).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+this.el+"-script'>"+$("#"+this.el+"-script").html()+"</div>"));return this},wax=wax||{},wax.fullscreen=function(a,b){var c={state:1,add:function(a){this.a=document.createElement("a"),this.a.className="wax-fullscreen",this.a.href="#fullscreen",this.a.innerHTML="fullscreen",a.parent.appendChild(this.a),com.modestmaps.addEvent(this.a,"click",this.click(a));return this},click:function(a){if(this._click)return this._click;this._click=wax.util.bind(function(b){b&&com.modestmaps.cancelEvent(b),this.state?(this.smallSize=[a.parent.offsetWidth,a.parent.offsetHeight],a.parent.className+=" wax-fullscreen-map",a.setSize(a.parent.offsetWidth,a.parent.offsetHeight)):(a.parent.className=a.parent.className.replace("wax-fullscreen-map",""),a.setSize(this.smallSize[0],this.smallSize[1])),this.state=!this.state},this);return this._click}};return c.add(a)},wax=wax||{};var limit=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d);if(c||!d)d=setTimeout(g,b)}},throttle=function(a,b){return limit(a,b,!1)},locationHash={stateChange:function(a){com.modestmaps.addEvent(window,"hashchange",function(){a(location.hash)},!1)},getState:function(){return location.hash},pushState:function(a){location.hash=a}};wax.hash=function(a,b){var c,d=90-1e-8,e={map:this,parser:function(b){var c=b.split("/");for(var d=0;d<c.length;d++){if(isNaN(c[d]))return!0;c[d]=Number(c)}if(c.length<3)return!0;c.length==3&&a.setCenterZoom(new com.modestmaps.Location(c[1],c[2]),c[0])},add:function(a){b.manager.getState()?e.stateChange(b.manager.getState()):(e.initialize(),e.move()),a.addCallback("drawn",throttle(e.move,500)),b.manager.stateChange(e.stateChange)},formatter:function(){var b=a.getCenter(),c=a.getZoom(),d=Math.max(0,Math.ceil(Math.log(c)/Math.LN2));return"#"+[c.toFixed(2),b.lat.toFixed(d),b.lon.toFixed(d)].join("/")},move:function(){var a=e.formatter();c!==a&&(c=a,b.manager.pushState(c))},stateChange:function(a){a!==c&&e.parser((c=a).substring(1))&&e.move()},initialize:function(){b.defaultCenter&&a.setCenter(b.defaultCenter),b.defaultZoom&&a.setZoom(b.defaultZoom)}};return e.add(a)},wax=wax||{},wax.interaction=function(a,b){var c=com.modestmaps;b=b||{};var d={modifyingEvents:["zoomed","panned","centered","extentset","resized","drawn"],waxGM:new wax.GridManager,callbacks:b.callbacks||{out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click},clickAction:b.clickAction||"full",add:function(){for(var b=0;b<this.modifyingEvents.length;b++)a.addCallback(this.modifyingEvents[b],this.clearMap);c.addEvent(a.parent,"mousemove",this.onMove()),c.addEvent(a.parent,"mousedown",this.mouseDown());return this},getTileGrid:function(){var b=a.getZoom();return this._getTileGrid||(this._getTileGrid=function(a){var c=[];for(var d in a)if(d.split(",")[0]==b){var e=wax.util.offset(a[d]);c.push([e.top,e.left,a[d]])}return c}(a.tiles))},clearTileGrid:function(a,b){this._waxGetTileGrid=null},getTile:function(a){var b,c=this.getTileGrid();for(var d=0;d<c.length;d++)if(c[d][0]<a.pageY&&c[d][0]+256>a.pageY&&c[d][1]<a.pageX&&c[d][1]+256>a.pageX){b=c[d][2];break}return b||!1},clearTimeout:function(){if(this.clickTimeout){window.clearTimeout(this.clickTimeout),this.clickTimeout=null;return!0}return!1},onMove:function(b){this._onMove||(this._onMove=wax.util.bind(function(b){var c=this.getTile(b);c&&this.waxGM.getGrid(c.src,wax.util.bind(function(d){if(d){var e=d.getFeature(b.pageX,b.pageY,c,{format:"teaser"});e?e&&this.feature!==e?(this.feature=e,this.callbacks.out(e,a.parent,0,b),this.callbacks.over(e,a.parent,0,b)):e||(this.feature=null,this.callbacks.out(e,a.parent,0,b)):(this.feature=null,this.callbacks.out({},a.parent,0,b))}},this))},this));return this._onMove},mouseDown:function(b){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){this.clearTimeout()||(this.downEvent=b,c.addEvent(a.parent,"mouseup",this.mouseUp()))},this));return this._mouseDown},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){c.removeEvent(a.parent,"mouseup",this.mouseUp());var d=4;Math.round(b.pageY/d)===Math.round(this.downEvent.pageY/d)&&Math.round(b.pageX/d)===Math.round(this.downEvent.pageX/d)&&(this.clickTimeout=window.setTimeout(wax.util.bind(function(){this.click()(b)},this),300))},this));return this._mouseUp},click:function(a){this._onClick||(this._onClick=wax.util.bind(function(a){var b=this.getTile(a);b&&this.waxGM.getGrid(b.src,wax.util.bind(function(c){if(c){var d=c.getFeature(a.pageX,a.pageY,b,{format:this.clickAction});if(d)switch(this.clickAction){case"full":this.callbacks.click(d,this.parent,0,a);break;case"location":window.location=d}}},this))},this));return this._onClick}};return d.add(a)},wax=wax||{},wax.legend=function(a,b){b=b||{};var c={add:function(){this.legend=new wax.Legend(a.parent,b.container),this.legend.render([a.provider.getTileUrl({zoom:0,column:0,row:0})])}};return c.add(a)},wax=wax||{},wax.mobile=function(a,b){b=b||{};var c=com.modestmaps,d=navigator.userAgent.toLowerCase(),e=d.indexOf("webkit")!=-1,f=d.indexOf("mobile")!=-1,g=f&&e,h=function(a){var b=document.createElement("canvas"),c=parseInt(a.style.width,10),d=parseInt(a.style.height,10),e=c/2,f=d/2,g=Math.min(c,d)/4,h=b.getContext("2d");b.setAttribute("width",c),b.setAttribute("height",d),h.globalAlpha=.5;var i=h.createLinearGradient(0,0,300,225);i.addColorStop(0,"black"),i.addColorStop(1,"rgb(200, 200, 200)"),h.fillStyle=i,h.fillRect(0,0,c,d),h.fillStyle="rgb(255, 255, 255)",h.beginPath(),h.moveTo(e-g*.6,f-g),h.lineTo(e-g*.6,f+g),h.lineTo(e+g*.6,f),h.fill(),a.appendChild(b)},i=function(a){a.style.position="absolute",a.style.height="50px",a.style.left=a.style.right="0";var b=document.createElement("canvas");b.setAttribute("width",a.offsetWidth),b.setAttribute("height",a.offsetHeight);var c=b.getContext("2d");c.globalAlpha=1,c.fillStyle="rgba(255, 255, 255, 0.5)",c.fillRect(0,0,a.offsetWidth,a.offsetHeight),c.fillStyle="rgb(0, 0, 0)",c.font="bold 20px sans-serif",c.fillText("back",20,30),a.appendChild(b)},j=function(a){a.style.position="absolute",a.style.width=a.style.height="auto",a.style.top=window.pageYOffset+"px",a.style.left=a.style.right="0px"},k=function(a){a.style.position="relative",a.style.width=a.style.height=a.style.top=a.style.left=a.style.right="auto"},l,m,n,o,p=b.overlayDraw||h,q=b.backDraw||i;bodyDraw=b.bodyDraw||function(){};var r={add:function(a){g&&(o=document.createElement("meta"),o.id="wax-touch",o.setAttribute("name","viewport"),l=document.createElement("div"),l.id=a.parent.id+"-mobileoverlay",l.className="wax-mobileoverlay",l.style.position="absolute",l.style.width=a.dimensions.x+"px",l.style.height=a.dimensions.y+"px",a.parent.appendChild(l),p(l),n=document.createElement("div"),backDiv=document.createElement("div"),m=document.body,newBody=document.createElement("body"),newBody.appendChild(backDiv),c.addEvent(l,"touchstart",this.toTouch),c.addEvent(backDiv,"touchstart",this.toPage));return this},toTouch:function(){a.parent.parentNode.replaceChild(n,a.parent),newBody.insertBefore(a.parent,backDiv),document.body=newBody,bodyDraw(newBody),q(backDiv),o.setAttribute("content","initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"),document.head.appendChild(o),a._smallSize=[a.parent.clientWidth,a.parent.clientHeight],j(a.parent),a.setSize(a.parent.offsetWidth,window.innerHeight),backDiv.style.display="block",l.style.display="none"},toPage:function(){document.body=m,n.parentNode.replaceChild(a.parent,n),k(a.parent),a.setSize(a._smallSize[0],a._smallSize[1]),backDiv.style.display="none",l.style.display="block"}};return r.add(a)},wax=wax||{},wax.pointselector=function(a,b){function k(a){var b=[];for(var c=0;c<a.length;c++)b.push(new g.Location(a[c].lat,a[c].lon));return b}var c=null,d=null,e=5,f,g=com.modestmaps,h=[],i=typeof b=="function"?b:b.callback,j=function(b){var c=wax.util.eventoffset(b),d=new g.Point(c.x,c.y),e={x:parseFloat(g.getStyle(document.documentElement,"margin-left")),y:parseFloat(g.getStyle(document.documentElement,"margin-top"))};isNaN(e.x)||(d.x-=e.x),isNaN(e.y)||(d.y-=e.y);for(var f=a.parent;f;f=f.offsetParent)d.x-=f.offsetLeft,d.y-=f.offsetTop;return d},l={add:function(a){f=document.createElement("div"),f.id=a.parent.id+"-boxselector",f.className="pointselector-box-container",f.innerHTML="&nbsp;",f.style.width=a.dimensions.x+"px",f.style.height=a.dimensions.y+"px",a.parent.appendChild(f),g.addEvent(f,"mousedown",this.mouseDown()),a.addCallback("drawn",l.drawPoints());return this},deletePoint:function(a,b){confirm("Delete this point?")&&(a.pointDiv.parentNode.removeChild(a.pointDiv),h.splice(wax.util.indexOf(h,a),1),i(k(h)))},drawPoints:function(){this._drawPoints||(this._drawPoints=wax.util.bind(function(){var b=new g.Point(0,0);for(var c=0;c<h.length;c++){var d=a.locationPoint(h[c]);h[c].pointDiv||(h[c].pointDiv=document.createElement("div"),h[c].pointDiv.className="wax-point-div",h[c].pointDiv.style.position="absolute",h[c].pointDiv.style.display="block",h[c].pointDiv.location=h[c],g.addEvent(h[c].pointDiv,"mouseup",function(b){var d=h[c];return function(b){g.removeEvent(a.parent,"mouseup",l.mouseUp()),l.deletePoint(d,b)}}()),f.appendChild(h[c].pointDiv)),h[c].pointDiv.style.left=d.x+"px",h[c].pointDiv.style.top=d.y+"px"}},this));return this._drawPoints},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){c=j(b),g.addEvent(a.parent,"mouseup",this.mouseUp())},this));return this._mouseDown},addLocation:function(a){h.push(a),l.drawPoints()()},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){!c||(d=j(b),g.Point.distance(c,d)<e&&(this.addLocation(a.pointLocation(c)),i(k(h))),c=null,g.removeEvent(a.parent,"mouseup",l.mouseUp()))},this));return this._mouseUp}};return l.add(a)},wax=wax||{},wax.zoombox=function(a,b){var c=null,d={add:function(a){this.boxDiv=document.createElement("div"),this.boxDiv.id=a.parent.id+"-zoombox",this.boxDiv.className="zoombox-box-container",this.boxDiv.style.width=a.dimensions.x+"px",this.boxDiv.style.height=a.dimensions.y+"px",this.box=document.createElement("div"),this.box.id=a.parent.id+"-zoombox-box",this.box.className="zoombox-box",this.boxDiv.appendChild(this.box),com.modestmaps.addEvent(this.boxDiv,"mousedown",this.mouseDown()),a.parent.appendChild(this.boxDiv)},remove:function(){this.boxDiv.parentNode.removeChild(this.boxDiv),a.removeCallback("mousedown",this.mouseDown)},getMousePoint:function(b){var c=new com.modestmaps.Point(b.clientX,b.clientY);c.x+=document.body.scrollLeft+document.documentElement.scrollLeft,c.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var d=a.parent;d;d=d.offsetParent)c.x-=d.offsetLeft,c.y-=d.offsetTop;return c},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){if(b.shiftKey){c=this.getMousePoint(b),this.box.style.left=c.x+"px",this.box.style.top=c.y+"px",com.modestmaps.addEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.addEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="crosshair";return com.modestmaps.cancelEvent(b)}},this));return this._mouseDown},mouseMove:function(a){this._mouseMove||(this._mouseMove=wax.util.bind(function(a){var b=this.getMousePoint(a);this.box.style.display="block",b.x<c.x?this.box.style.left=b.x+"px":this.box.style.left=c.x+"px",this.box.style.width=Math.abs(b.x-c.x)+"px",b.y<c.y?this.box.style.top=b.y+"px":this.box.style.top=c.y+"px",this.box.style.height=Math.abs(b.y-c.y)+"px";return com.modestmaps.cancelEvent(a)},this));return this._mouseMove},mouseUp:function(b){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){var d=this.getMousePoint(b),e=a.pointLocation(d),f=a.pointLocation(c);a.setExtent([e,f]),this.box.style.display="none",com.modestmaps.removeEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.removeEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="auto";return com.modestmaps.cancelEvent(b)},this));return this._mouseUp}};return d.add(a)},wax=wax||{},wax.zoomer=function(a){var b=document.createElement("a");b.innerHTML="+",b.href="#",b.className="zoomer zoomin",com.modestmaps.addEvent(b,"click",function(b){com.modestmaps.cancelEvent(b),a.zoomIn()},!1),a.parent.appendChild(b);var c=document.createElement("a");c.innerHTML="-",c.href="#",c.className="zoomer zoomout",com.modestmaps.addEvent(c,"click",function(b){com.modestmaps.cancelEvent(b),a.zoomOut()},!1),a.parent.appendChild(c);var d={add:function(a){a.addCallback("drawn",function(a,d){a.coordinate.zoom===a.provider.outerLimits()[0].zoom?c.className="zoomer zoomout zoomdisabled":a.coordinate.zoom===a.provider.outerLimits()[1].zoom?b.className="zoomer zoomin zoomdisabled":(b.className="zoomer zoomin",c.className="zoomer zoomout")});return this}};return d.add(a)},wax=wax||{},wax.provider=function(a){this.layerName=a.layerName,this.baseUrls=typeof a.baseUrl=="string"?[a.baseUrl]:a.baseUrl,this.n_urls=this.baseUrls.length,this.filetype=a.filetype||".png",this.zoomRange=a.zoomRange||[0,18]},wax.provider.prototype={outerLimits:function(){return[(new com.modestmaps.Coordinate(0,0,0)).zoomTo(this.zoomRange[0]),(new com.modestmaps.Coordinate(1,1,0)).zoomTo(this.zoomRange[1])]},getTileUrl:function(a){var b;a=this.sourceCoordinate(a);if(!a)return null;var c=Math.pow(2,a.zoom);a.row=Math.pow(2,a.zoom)-a.row-1,this.n_urls===1?b=this.baseUrls[0]:b=this.baseUrls[parseInt(c*a.row+a.column,10)%this.n_urls];var d=["1.0.0",this.layerName,a.zoom,a.column,a.row].join("/");return b+d+this.filetype}},com.modestmaps.extend(wax.provider,com.modestmaps.MapProvider)
  6
+  */!function(window){function readyState(a,b,c){return function(){a&&a.readyState==4&&(twoHundo.test(a.status)?b(a):c(a))}}function setHeaders(a,b){var c=b.headers||{};c.Accept="text/javascript, text/html, application/xml, text/xml, */*",c["X-Requested-With"]=c["X-Requested-With"]||"XMLHttpRequest";if(b.data){c["Content-type"]="application/x-www-form-urlencoded";for(var d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d],!1)}}function getCallbackName(a){var b=a.jsonpCallback||"callback";if(a.url.substr(-(b.length+2))==b+"=?"){var c="reqwest_"+uniqid++;a.url=a.url.substr(0,a.url.length-1)+c;return c}var d=new RegExp(b+"=([\\w]+)");return a.url.match(d)[1]}function generalCallback(a){lastValue=a}function getRequest(a,b,c){if(a.type!="jsonp"){var d=xhr();d.open(a.method||"GET",typeof a=="string"?a:a.url,!0),setHeaders(d,a),d.onreadystatechange=readyState(d,b,c),a.before&&a.before(d),d.send(a.data||null);return d}var e=doc.createElement("script"),f=getCallbackName(a);window[f]=generalCallback,e.type="text/javascript",e.src=a.url,e.async=!0,e.onload=function(){a.success&&a.success(lastValue),lastValue=undefined,head.removeChild(e)},head.insertBefore(e,topScript)}function Reqwest(a,b){this.o=a,this.fn=b,init.apply(this,arguments)}function setType(a){if(/\.json$/.test(a))return"json";if(/\.jsonp$/.test(a))return"jsonp";if(/\.js$/.test(a))return"js";if(/\.html?$/.test(a))return"html";if(/\.xml$/.test(a))return"xml";return"js"}function init(o,fn){function complete(a){o.complete&&o.complete(a)}function success(resp){o.timeout&&clearTimeout(self.timeout)&&(self.timeout=null);var r=resp.responseText;switch(type){case"json":resp=eval("("+r+")");break;case"js":resp=eval(r);break;case"html":resp=r}fn(resp),o.success&&o.success(resp),complete(resp)}function error(a){o.error&&o.error(a),complete(a)}this.url=typeof o=="string"?o:o.url,this.timeout=null;var type=o.type||setType(this.url),self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort(),error()},o.timeout)),this.request=getRequest(o,success,error)}function reqwest(a,b){return new Reqwest(a,b)}function enc(a){return encodeURIComponent(a)}function serial(a){var b=a.name;if(a.disabled||!b)return"";b=enc(b);switch(a.tagName.toLowerCase()){case"input":switch(a.type){case"reset":case"button":case"image":case"file":return"";case"checkbox":case"radio":return a.checked?b+"="+(a.value?enc(a.value):!0)+"&":"";default:return b+"="+(a.value?enc(a.value):!0)+"&"}break;case"textarea":return b+"="+enc(a.value)+"&";case"select":return b+"="+enc(a.options[a.selectedIndex].value)+"&"}return""}var twoHundo=/^20\d$/,doc=document,byTag="getElementsByTagName",topScript=doc[byTag]("script")[0],head=topScript.parentNode,xhr="XMLHttpRequest"in window?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},uniqid=0,lastValue;Reqwest.prototype={abort:function(){this.request.abort()},retry:function(){init.call(this,this.o,this.fn)}},reqwest.serialize=function(a){var b=a[byTag]("input"),c=a[byTag]("select"),d=a[byTag]("textarea");return(v(b).chain().toArray().map(serial).value().join("")+v(c).chain().toArray().map(serial).value().join("")+v(d).chain().toArray().map(serial).value().join("")).replace(/&$/,"")},reqwest.serializeArray=function(a){for(var b=this.serialize(a).split("&"),c=0,d=b.length,e=[],f;c<d;c++)b[c]&&(f=b[c].split("="))&&e.push({name:f[0],value:f[1]});return e};var old=window.reqwest;reqwest.noConflict=function(){window.reqwest=old;return this},window.reqwest=reqwest}(this);var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a][0],this.cache[a][1]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=[null,b];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])},error:function(b){c.locks[a]=!1,c.cache[a]=[b,null];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256)return;if(Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d,e){if(d||!e)return b(d,null);wax.request.get(c.tileDataUrl(a),function(a,c){if(a)return b(a,null);b(null,new wax.GridInstance(c,e))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(null,this.formatters[a]):wax.request.get(a,function(d,e){e&&e.formatter?c.formatters[a]=new wax.Formatter(e):c.formatters[a]=!1,b(d,c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}},wax=wax||{},wax.boxselector=function(a,b){var c=null,d=typeof b=="function"?b:b.callback,e={add:function(a){this.containerDiv=document.createElement("div"),this.containerDiv.id=a.parent.id+"-zoombox",this.containerDiv.className="boxselector-box-container",this.containerDiv.style.width=a.dimensions.x+"px",this.containerDiv.style.height=a.dimensions.y+"px",this.boxDiv=document.createElement("div"),this.boxDiv.id=a.parent.id+"-boxselector-box",this.boxDiv.className="boxselector-box",this.containerDiv.appendChild(this.boxDiv),a.parent.appendChild(this.containerDiv),com.modestmaps.addEvent(this.containerDiv,"mousedown",this.mouseDown()),a.addCallback("drawn",this.drawbox())},remove:function(){this.containerDiv.parentNode.removeChild(this.containerDiv),a.removeCallback("mousedown",this.drawbox())},getMousePoint:function(b){var c=new com.modestmaps.Point(b.clientX,b.clientY);c.x+=document.body.scrollLeft+document.documentElement.scrollLeft,c.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var d=a.parent;d;d=d.offsetParent)c.x-=d.offsetLeft,c.y-=d.offsetTop;return c},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){if(b.shiftKey){c=this.getMousePoint(b),this.boxDiv.style.left=c.x+"px",this.boxDiv.style.top=c.y+"px",com.modestmaps.addEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.addEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="crosshair";return com.modestmaps.cancelEvent(b)}},this));return this._mouseDown},mouseMove:function(a){this._mouseMove||(this._mouseMove=wax.util.bind(function(a){var b=this.getMousePoint(a);this.boxDiv.style.display="block",b.x<c.x?this.boxDiv.style.left=b.x+"px":this.boxDiv.style.left=c.x+"px",this.boxDiv.style.width=Math.abs(b.x-c.x)+"px",b.y<c.y?this.boxDiv.style.top=b.y+"px":this.boxDiv.style.top=c.y+"px",this.boxDiv.style.height=Math.abs(b.y-c.y)+"px";return com.modestmaps.cancelEvent(a)},this));return this._mouseMove},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){var f=e.getMousePoint(b),g=a.pointLocation(f),h=a.pointLocation(c),i=[new com.modestmaps.Location(Math.max(g.lat,h.lat),Math.min(g.lon,h.lon)),new com.modestmaps.Location(Math.min(g.lat,h.lat),Math.max(g.lon,h.lon))];this.box=[g,h],d(i),com.modestmaps.removeEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.removeEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="auto";return com.modestmaps.cancelEvent(b)},this));return this._mouseUp},drawbox:function(){this._drawbox||(this._drawbox=wax.util.bind(function(a,b){if(this.boxDiv){this.boxDiv.style.display="block",this.boxDiv.style.height="auto",this.boxDiv.style.width="auto";var c=a.locationPoint(this.box[0]),d=a.locationPoint(this.box[1]);this.boxDiv.style.left=Math.max(0,d.x)+"px",this.boxDiv.style.top=Math.max(0,d.y)+"px",this.boxDiv.style.right=Math.max(0,a.dimensions.x-c.x)+"px",this.boxDiv.style.bottom=Math.max(0,a.dimensions.y-c.y)+"px"}},this));return this._drawbox}};return e.add(a)};if(!com){var com={};com.modestmaps||(com.modestmaps={})}com.modestmaps.Map.prototype.embedder=function(a){a=a||{},$("#"+this.el+"-script").length&&$(this.parent).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+this.el+"-script'>"+$("#"+this.el+"-script").html()+"</div>"));return this},wax=wax||{},wax.fullscreen=function(a,b){var c={state:1,add:function(a){this.a=document.createElement("a"),this.a.className="wax-fullscreen",this.a.href="#fullscreen",this.a.innerHTML="fullscreen",a.parent.appendChild(this.a),com.modestmaps.addEvent(this.a,"click",this.click(a));return this},click:function(a){if(this._click)return this._click;this._click=wax.util.bind(function(b){b&&com.modestmaps.cancelEvent(b),this.state?(this.smallSize=[a.parent.offsetWidth,a.parent.offsetHeight],a.parent.className+=" wax-fullscreen-map",a.setSize(a.parent.offsetWidth,a.parent.offsetHeight)):(a.parent.className=a.parent.className.replace("wax-fullscreen-map",""),a.setSize(this.smallSize[0],this.smallSize[1])),this.state=!this.state},this);return this._click}};return c.add(a)},wax=wax||{};var limit=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d);if(c||!d)d=setTimeout(g,b)}},throttle=function(a,b){return limit(a,b,!1)},locationHash={stateChange:function(a){com.modestmaps.addEvent(window,"hashchange",function(){a(location.hash)},!1)},getState:function(){return location.hash},pushState:function(a){location.hash=a}};wax.hash=function(a,b){var c,d=90-1e-8,e={map:this,parser:function(b){var c=b.split("/");for(var d=0;d<c.length;d++){if(isNaN(c[d]))return!0;c[d]=Number(c)}if(c.length<3)return!0;c.length==3&&a.setCenterZoom(new com.modestmaps.Location(c[1],c[2]),c[0])},add:function(a){b.manager.getState()?e.stateChange(b.manager.getState()):(e.initialize(),e.move()),a.addCallback("drawn",throttle(e.move,500)),b.manager.stateChange(e.stateChange)},formatter:function(){var b=a.getCenter(),c=a.getZoom(),d=Math.max(0,Math.ceil(Math.log(c)/Math.LN2));return"#"+[c.toFixed(2),b.lat.toFixed(d),b.lon.toFixed(d)].join("/")},move:function(){var a=e.formatter();c!==a&&(c=a,b.manager.pushState(c))},stateChange:function(a){a!==c&&e.parser((c=a).substring(1))&&e.move()},initialize:function(){b.defaultCenter&&a.setCenter(b.defaultCenter),b.defaultZoom&&a.setZoom(b.defaultZoom)}};return e.add(a)},wax=wax||{},wax.interaction=function(a,b){var c=com.modestmaps;b=b||{};var d={modifyingEvents:["zoomed","panned","centered","extentset","resized","drawn"],waxGM:new wax.GridManager,callbacks:b.callbacks||{out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click},clickAction:b.clickAction||"full",add:function(){for(var b=0;b<this.modifyingEvents.length;b++)a.addCallback(this.modifyingEvents[b],this.clearMap);c.addEvent(a.parent,"mousemove",this.onMove()),c.addEvent(a.parent,"mousedown",this.mouseDown());return this},getTileGrid:function(){var b=a.getZoom();return this._getTileGrid||(this._getTileGrid=function(a){var c=[];for(var d in a)if(d.split(",")[0]==b){var e=wax.util.offset(a[d]);c.push([e.top,e.left,a[d]])}return c}(a.tiles))},clearTileGrid:function(a,b){this._waxGetTileGrid=null},getTile:function(a){var b,c=this.getTileGrid();for(var d=0;d<c.length;d++)if(c[d][0]<a.pageY&&c[d][0]+256>a.pageY&&c[d][1]<a.pageX&&c[d][1]+256>a.pageX){b=c[d][2];break}return b||!1},clearTimeout:function(){if(this.clickTimeout){window.clearTimeout(this.clickTimeout),this.clickTimeout=null;return!0}return!1},onMove:function(b){this._onMove||(this._onMove=wax.util.bind(function(b){var c=this.getTile(b);c&&this.waxGM.getGrid(c.src,wax.util.bind(function(d,e){if(!d&&e){var f=e.getFeature(b.pageX,b.pageY,c,{format:"teaser"});f?f&&this.feature!==f?(this.feature=f,this.callbacks.out(f,a.parent,0,b),this.callbacks.over(f,a.parent,0,b)):f||(this.feature=null,this.callbacks.out(f,a.parent,0,b)):(this.feature=null,this.callbacks.out({},a.parent,0,b))}},this))},this));return this._onMove},mouseDown:function(b){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){this.clearTimeout()||(this.downEvent=b,c.addEvent(a.parent,"mouseup",this.mouseUp()))},this));return this._mouseDown},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){c.removeEvent(a.parent,"mouseup",this.mouseUp());var d=4;Math.round(b.pageY/d)===Math.round(this.downEvent.pageY/d)&&Math.round(b.pageX/d)===Math.round(this.downEvent.pageX/d)&&(this.clickTimeout=window.setTimeout(wax.util.bind(function(){this.click()(b)},this),300))},this));return this._mouseUp},click:function(a){this._onClick||(this._onClick=wax.util.bind(function(a){var b=this.getTile(a);b&&this.waxGM.getGrid(b.src,wax.util.bind(function(c){if(c){var d=c.getFeature(a.pageX,a.pageY,b,{format:this.clickAction});if(d)switch(this.clickAction){case"full":this.callbacks.click(d,this.parent,0,a);break;case"location":window.location=d}}},this))},this));return this._onClick}};return d.add(a)},wax=wax||{},wax.legend=function(a,b){b=b||{};var c={add:function(){this.legend=new wax.Legend(a.parent,b.container),this.legend.render([a.provider.getTileUrl({zoom:0,column:0,row:0})])}};return c.add(a)},wax=wax||{},wax.mobile=function(a,b){b=b||{};var c=com.modestmaps,d=navigator.userAgent.toLowerCase(),e=d.indexOf("webkit")!=-1,f=d.indexOf("mobile")!=-1,g=f&&e,h=function(a){var b=document.createElement("canvas"),c=parseInt(a.style.width,10),d=parseInt(a.style.height,10),e=c/2,f=d/2,g=Math.min(c,d)/4,h=b.getContext("2d");b.setAttribute("width",c),b.setAttribute("height",d),h.globalAlpha=.5;var i=h.createLinearGradient(0,0,300,225);i.addColorStop(0,"black"),i.addColorStop(1,"rgb(200, 200, 200)"),h.fillStyle=i,h.fillRect(0,0,c,d),h.fillStyle="rgb(255, 255, 255)",h.beginPath(),h.moveTo(e-g*.6,f-g),h.lineTo(e-g*.6,f+g),h.lineTo(e+g*.6,f),h.fill(),a.appendChild(b)},i=function(a){a.style.position="absolute",a.style.height="50px",a.style.left=a.style.right="0";var b=document.createElement("canvas");b.setAttribute("width",a.offsetWidth),b.setAttribute("height",a.offsetHeight);var c=b.getContext("2d");c.globalAlpha=1,c.fillStyle="rgba(255, 255, 255, 0.5)",c.fillRect(0,0,a.offsetWidth,a.offsetHeight),c.fillStyle="rgb(0, 0, 0)",c.font="bold 20px sans-serif",c.fillText("back",20,30),a.appendChild(b)},j=function(a){a.style.position="absolute",a.style.width=a.style.height="auto",a.style.top=window.pageYOffset+"px",a.style.left=a.style.right="0px"},k=function(a){a.style.position="relative",a.style.width=a.style.height=a.style.top=a.style.left=a.style.right="auto"},l,m,n,o,p=b.overlayDraw||h,q=b.backDraw||i;bodyDraw=b.bodyDraw||function(){};var r={add:function(a){g&&(o=document.createElement("meta"),o.id="wax-touch",o.setAttribute("name","viewport"),l=document.createElement("div"),l.id=a.parent.id+"-mobileoverlay",l.className="wax-mobileoverlay",l.style.position="absolute",l.style.width=a.dimensions.x+"px",l.style.height=a.dimensions.y+"px",a.parent.appendChild(l),p(l),n=document.createElement("div"),backDiv=document.createElement("div"),m=document.body,newBody=document.createElement("body"),newBody.appendChild(backDiv),c.addEvent(l,"touchstart",this.toTouch),c.addEvent(backDiv,"touchstart",this.toPage));return this},toTouch:function(){a.parent.parentNode.replaceChild(n,a.parent),newBody.insertBefore(a.parent,backDiv),document.body=newBody,bodyDraw(newBody),q(backDiv),o.setAttribute("content","initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"),document.head.appendChild(o),a._smallSize=[a.parent.clientWidth,a.parent.clientHeight],j(a.parent),a.setSize(a.parent.offsetWidth,window.innerHeight),backDiv.style.display="block",l.style.display="none"},toPage:function(){document.body=m,n.parentNode.replaceChild(a.parent,n),k(a.parent),a.setSize(a._smallSize[0],a._smallSize[1]),backDiv.style.display="none",l.style.display="block"}};return r.add(a)},wax=wax||{},wax.pointselector=function(a,b){function k(a){var b=[];for(var c=0;c<a.length;c++)b.push(new g.Location(a[c].lat,a[c].lon));return b}var c=null,d=null,e=5,f,g=com.modestmaps,h=[],i=typeof b=="function"?b:b.callback,j=function(b){var c=wax.util.eventoffset(b),d=new g.Point(c.x,c.y),e={x:parseFloat(g.getStyle(document.documentElement,"margin-left")),y:parseFloat(g.getStyle(document.documentElement,"margin-top"))};isNaN(e.x)||(d.x-=e.x),isNaN(e.y)||(d.y-=e.y);for(var f=a.parent;f;f=f.offsetParent)d.x-=f.offsetLeft,d.y-=f.offsetTop;return d},l={add:function(a){f=document.createElement("div"),f.id=a.parent.id+"-boxselector",f.className="pointselector-box-container",f.innerHTML="&nbsp;",f.style.width=a.dimensions.x+"px",f.style.height=a.dimensions.y+"px",a.parent.appendChild(f),g.addEvent(f,"mousedown",this.mouseDown()),a.addCallback("drawn",l.drawPoints());return this},deletePoint:function(a,b){confirm("Delete this point?")&&(a.pointDiv.parentNode.removeChild(a.pointDiv),h.splice(wax.util.indexOf(h,a),1),i(k(h)))},drawPoints:function(){this._drawPoints||(this._drawPoints=wax.util.bind(function(){var b=new g.Point(0,0);for(var c=0;c<h.length;c++){var d=a.locationPoint(h[c]);h[c].pointDiv||(h[c].pointDiv=document.createElement("div"),h[c].pointDiv.className="wax-point-div",h[c].pointDiv.style.position="absolute",h[c].pointDiv.style.display="block",h[c].pointDiv.location=h[c],g.addEvent(h[c].pointDiv,"mouseup",function(b){var d=h[c];return function(b){g.removeEvent(a.parent,"mouseup",l.mouseUp()),l.deletePoint(d,b)}}()),f.appendChild(h[c].pointDiv)),h[c].pointDiv.style.left=d.x+"px",h[c].pointDiv.style.top=d.y+"px"}},this));return this._drawPoints},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){c=j(b),g.addEvent(a.parent,"mouseup",this.mouseUp())},this));return this._mouseDown},addLocation:function(a){h.push(a),l.drawPoints()()},mouseUp:function(){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){!c||(d=j(b),g.Point.distance(c,d)<e&&(this.addLocation(a.pointLocation(c)),i(k(h))),c=null,g.removeEvent(a.parent,"mouseup",l.mouseUp()))},this));return this._mouseUp}};return l.add(a)},wax=wax||{},wax.zoombox=function(a,b){var c=null,d={add:function(a){this.boxDiv=document.createElement("div"),this.boxDiv.id=a.parent.id+"-zoombox",this.boxDiv.className="zoombox-box-container",this.boxDiv.style.width=a.dimensions.x+"px",this.boxDiv.style.height=a.dimensions.y+"px",this.box=document.createElement("div"),this.box.id=a.parent.id+"-zoombox-box",this.box.className="zoombox-box",this.boxDiv.appendChild(this.box),com.modestmaps.addEvent(this.boxDiv,"mousedown",this.mouseDown()),a.parent.appendChild(this.boxDiv)},remove:function(){this.boxDiv.parentNode.removeChild(this.boxDiv),a.removeCallback("mousedown",this.mouseDown)},getMousePoint:function(b){var c=new com.modestmaps.Point(b.clientX,b.clientY);c.x+=document.body.scrollLeft+document.documentElement.scrollLeft,c.y+=document.body.scrollTop+document.documentElement.scrollTop;for(var d=a.parent;d;d=d.offsetParent)c.x-=d.offsetLeft,c.y-=d.offsetTop;return c},mouseDown:function(){this._mouseDown||(this._mouseDown=wax.util.bind(function(b){if(b.shiftKey){c=this.getMousePoint(b),this.box.style.left=c.x+"px",this.box.style.top=c.y+"px",com.modestmaps.addEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.addEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="crosshair";return com.modestmaps.cancelEvent(b)}},this));return this._mouseDown},mouseMove:function(a){this._mouseMove||(this._mouseMove=wax.util.bind(function(a){var b=this.getMousePoint(a);this.box.style.display="block",b.x<c.x?this.box.style.left=b.x+"px":this.box.style.left=c.x+"px",this.box.style.width=Math.abs(b.x-c.x)+"px",b.y<c.y?this.box.style.top=b.y+"px":this.box.style.top=c.y+"px",this.box.style.height=Math.abs(b.y-c.y)+"px";return com.modestmaps.cancelEvent(a)},this));return this._mouseMove},mouseUp:function(b){this._mouseUp||(this._mouseUp=wax.util.bind(function(b){var d=this.getMousePoint(b),e=a.pointLocation(d),f=a.pointLocation(c);a.setExtent([e,f]),this.box.style.display="none",com.modestmaps.removeEvent(a.parent,"mousemove",this.mouseMove()),com.modestmaps.removeEvent(a.parent,"mouseup",this.mouseUp()),a.parent.style.cursor="auto";return com.modestmaps.cancelEvent(b)},this));return this._mouseUp}};return d.add(a)},wax=wax||{},wax.zoomer=function(a){var b=document.createElement("a");b.innerHTML="+",b.href="#",b.className="zoomer zoomin",com.modestmaps.addEvent(b,"click",function(b){com.modestmaps.cancelEvent(b),a.zoomIn()},!1),a.parent.appendChild(b);var c=document.createElement("a");c.innerHTML="-",c.href="#",c.className="zoomer zoomout",com.modestmaps.addEvent(c,"click",function(b){com.modestmaps.cancelEvent(b),a.zoomOut()},!1),a.parent.appendChild(c);var d={add:function(a){a.addCallback("drawn",function(a,d){a.coordinate.zoom===a.provider.outerLimits()[0].zoom?c.className="zoomer zoomout zoomdisabled":a.coordinate.zoom===a.provider.outerLimits()[1].zoom?b.className="zoomer zoomin zoomdisabled":(b.className="zoomer zoomin",c.className="zoomer zoomout")});return this}};return d.add(a)},wax=wax||{},wax.provider=function(a){this.layerName=a.layerName,this.baseUrls=typeof a.baseUrl=="string"?[a.baseUrl]:a.baseUrl,this.n_urls=this.baseUrls.length,this.filetype=a.filetype||".png",this.zoomRange=a.zoomRange||[0,18]},wax.provider.prototype={outerLimits:function(){return[(new com.modestmaps.Coordinate(0,0,0)).zoomTo(this.zoomRange[0]),(new com.modestmaps.Coordinate(1,1,0)).zoomTo(this.zoomRange[1])]},getTileUrl:function(a){var b;a=this.sourceCoordinate(a);if(!a)return null;var c=Math.pow(2,a.zoom);a.row=Math.pow(2,a.zoom)-a.row-1,this.n_urls===1?b=this.baseUrls[0]:b=this.baseUrls[parseInt(c*a.row+a.column,10)%this.n_urls];var d=["1.0.0",this.layerName,a.zoom,a.column,a.row].join("/");return b+d+this.filetype}},com.modestmaps.extend(wax.provider,com.modestmaps.MapProvider)
31  build/wax.ol.js
@@ -211,7 +211,7 @@ wax.request = {
211 211
     get: function(url, callback) {
212 212
         // Cache hit.
213 213
         if (this.cache[url]) {
214  
-            return callback(this.cache[url]);
  214
+            return callback(this.cache[url][0], this.cache[url][1]);
215 215
         // Cache miss.
216 216
         } else {
217 217
             this.promises[url] = this.promises[url] || [];
@@ -227,16 +227,16 @@ wax.request = {
227 227
                 jsonpCallback: 'callback',
228 228
                 success: function(data) {
229 229
                     that.locks[url] = false;
230  
-                    that.cache[url] = data;
  230
+                    that.cache[url] = [null, data];
231 231
                     for (var i = 0; i < that.promises[url].length; i++) {
232  
-                        that.promises[url][i](that.cache[url]);
  232
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
233 233
                     }
234 234
                 },
235  
-                error: function() {
  235
+                error: function(err) {
236 236
                     that.locks[url] = false;
237  
-                    that.cache[url] = null;
  237
+                    that.cache[url] = [err, null];
238 238
                     for (var i = 0; i < that.promises[url].length; i++) {
239  
-                        that.promises[url][i](that.cache[url]);
  239
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
240 240
                     }
241 241
                 }
242 242
             });
@@ -273,8 +273,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
273 273
   var tileX = offset.left;
274 274
   var tileY = offset.top;
275 275
 
276  
-  if (Math.floor((y - tileY) / this.tileRes) > 256 ||
277  
-    Math.floor((x - tileX) / this.tileRes) > 256) return;
  276
+  if (Math.floor((y - tileY) / this.tileRes) > 256) return;
  277
+  if (Math.floor((x - tileX) / this.tileRes) > 256) return;
278 278
 
279 279
   var key = this.grid_tile.grid[
280 280
      Math.floor((y - tileY) / this.tileRes)
@@ -309,11 +309,12 @@ wax.GridManager = function() {
309 309
 // and gets grid data, and tries to avoid re-downloading either.
310 310
 wax.GridManager.prototype.getGrid = function(url, callback) {
311 311
     var that = this;
312  
-    that.getFormatter(that.formatterUrl(url), function(f) {
313  
-        if (!f) return callback(false);
  312
+    that.getFormatter(that.formatterUrl(url), function(err, f) {
  313
+        if (err || !f) return callback(err, null);
314 314
 
315  
-        wax.request.get(that.tileDataUrl(url), function(t) {
316  
-            callback(new wax.GridInstance(t, f));
  315
+        wax.request.get(that.tileDataUrl(url), function(err, t) {
  316
+            if (err) return callback(err, null);
  317
+            callback(null, new wax.GridInstance(t, f));
317 318
         });
318 319
     });
319 320
 };
@@ -343,16 +344,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
343 344
   var that = this;
344 345
   // Formatter is cached.
345 346
   if (typeof this.formatters[url] !== 'undefined') {
346  
-    callback(this.formatters[url]);
  347
+    callback(null, this.formatters[url]);
347 348
     return;
348 349
   } else {
349  
-    wax.request.get(url, function(data) {
  350
+    wax.request.get(url, function(err, data) {
350 351
         if (data && data.formatter) {
351 352
             that.formatters[url] = new wax.Formatter(data);
352 353
         } else {
353 354
             that.formatters[url] = false;
354 355
         }
355  
-        callback(that.formatters[url]);
  356
+        callback(err, that.formatters[url]);
356 357
     });
357 358
   }
358 359
 };
2  build/wax.ol.min.js
@@ -31,4 +31,4 @@
31 31
 //         }
32 32
 //     ];
33 33
 //     wax.Record(gmap);
34  
-var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=b;for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a])},error:function(){c.locks[a]=!1,c.cache[a]=null;for(var b=0;b<c.promises[a].length;b++)c.promises[a][b](c.cache[a])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256||Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d){if(!d)return b(!1);wax.request.get(c.tileDataUrl(a),function(a){b(new wax.GridInstance(a,d))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(this.formatters[a]):wax.request.get(a,function(d){d&&d.formatter?c.formatters[a]=new wax.Formatter(d):c.formatters[a]=!1,b(c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}};var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Embedder=OpenLayers.Class(OpenLayers.Control,{initialize:function(a){a=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},setMap:function(a){$("#"+this.el+"-script").length&&(OpenLayers.Control.prototype.setMap.apply(this,arguments),$(a.div).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+this.el+"-script'>"+$("#"+this.el+"-script").html()+"</div>"))),this.activate()},CLASS_NAME:"wax.ol.Embedder"});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Interaction=OpenLayers.Class(OpenLayers.Control,{feature:{},handlerOptions:null,handlers:null,gm:new wax.GridManager,initialize:function(a){this.options=a||{},this.clickAction=this.options.clickAction||"full",OpenLayers.Control.prototype.initialize.apply(this,[this.options||{}]),this.callbacks={out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click}},setMap:function(a){$(a.viewPortDiv).bind("mousemove",$.proxy(this.getInfoForHover,this)),$(a.viewPortDiv).bind("mouseout",$.proxy(this.resetLayers,this)),this.clickHandler=new OpenLayers.Handler.Click(this,{click:this.getInfoForClick}),this.clickHandler.setMap(a),this.clickHandler.activate(),a.events.on({addlayer:this.resetLayers,changelayer:this.resetLayers,removelayer:this.resetLayers,changebaselayer:this.resetLayers,scope:this}),OpenLayers.Control.prototype.setMap.apply(this,arguments)},getTileStack:function(a,b){var c=[];layerfound:for(var d=0;d<a.length;d++)for(var e=0;e<a[d].grid.length;e++)for(var f=0;f<a[d].grid[e].length;f++){var g=$(a[d].grid[e][f].imgDiv).offset();if(g&&g.top<b.pageY&&g.top+256>b.pageY&&g.left<b.pageX&&g.left+256>b.pageX){c.push(a[d].grid[e][f]);continue layerfound}}return c},viableLayers:function(){if(this._viableLayers)return this._viableLayers;return this._viableLayers=$(this.map.layers).filter(function(a){return this.map.layers[a].visibility===!0&&this.map.layers[a].CLASS_NAME==="OpenLayers.Layer.TMS"})},resetLayers:function(){this._viableLayers=null,this.callbacks.out()},getInfoForClick:function(a){var b=this.viableLayers(),c=this.getTileStack(this.viableLayers(),a),d=null,e=null,f=this;for(var g=0;g<c.length;g++)this.gm.getGrid(c[g].url,function(b){if(!!b){var d=b.getFeature(a.pageX,a.pageY,c[g].imgDiv,{format:f.clickAction});if(d)switch(f.clickAction){case"full":f.callbacks.click(d,c[g].layer.map.viewPortDiv,g);break;case"location":window.location=d}}})},getInfoForHover:function(a){var b={format:"teaser"},c=this.viableLayers(),d=this.getTileStack(this.viableLayers(),a),e=null,f=null,g=this;for(var h=0;h<d.length;h++)this.gm.getGrid(d[h].url,function(c){if(c&&d[h]){var e=c.getFeature(a.pageX,a.pageY,d[h].imgDiv,b);if(e){if(!d[h])return;e&&g.feature[h]!==e?(g.feature[h]=e,g.callbacks.out(e,d[h].layer.map.div,h,a),g.callbacks.over(e,d[h].layer.map.div,h,a)):e||(g.feature[h]=null,g.callbacks.out(e,d[h].layer.map.div,h,a))}else g.feature[h]=null,d[h]?g.callbacks.out({},d[h].layer.map.div,h,a):g.callbacks.out({},!1,h)}})},CLASS_NAME:"wax.ol.Interaction"});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Legend=OpenLayers.Class(OpenLayers.Control,{CLASS_NAME:"wax.ol.Legend",legend:null,options:null,initialize:function(a){this.options=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},activate:function(){this.legend=new wax.Legend(this.map.viewPortDiv,this.options.container);return OpenLayers.Control.prototype.activate.apply(this,arguments)},setMap:function(a){OpenLayers.Control.prototype.setMap.apply(this,arguments),this.activate(),this.map.events.on({addlayer:this.setLegend,changelayer:this.setLegend,removelayer:this.setLegend,changebaselayer:this.setLegend,scope:this})},setLegend:function(){var a=[];for(var b=0;b<this.map.layers.length;b++){var c=this.map.layers[b];c&&c.getURL&&c.visibility&&a.push(c.getURL(new OpenLayers.Bounds))}this.legend.render(a)}});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Switcher=OpenLayers.Class(OpenLayers.Control,{CLASS_NAME:"wax.ol.Switcher",initialize:function(a){this.$element=$(a.e),this.options=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},setMap:function(a){OpenLayers.Control.prototype.setMap.apply(this,arguments),this.map.events.on({addlayer:this.redraw,changelayer:this.redraw,removelayer:this.redraw,changebaselayer:this.redraw,scope:this}),this.redraw()},layerClick:function(a){var b=a.currentTarget,c=$(b).data("layer");$("a.active",this.$element).removeClass("active"),$.each(this.map.getLayersBy("isBaseLayer",!1),function(){this.CLASS_NAME!=="OpenLayers.Layer.Vector.RootContainer"&&this.displayInLayerSwitcher&&this.setVisibility(!1)}),c.setVisibility(!0),$(b).addClass("active")},needsRedraw:function(){if(!this.layerStates||this.layerStates.length||this.map.layers.length!=this.layerStates.length)return!0;for(var a=0,b=this.layerStates.length;a<b;a++){var c=this.layerStates[a],d=this.map.layers[a];if(c.name!=d.name||c.inRange!=d.inRange||c.id!=d.id||c.visibility!=d.visibility)return!0}return!1},redraw:function(){if(this.needsRedraw()){this.$element.html("");var a=this.map.layers.length;this.layerStates=[];for(var b=0;b<a;b++){var c=this.map.layers[b];this.layerStates[b]={name:c.name,visibility:c.visibility,inRange:c.inRange,id:c.id}}var d=this.map.layers.slice();for(b=0,a=d.length;b<a;b++){var e=d[b];if(e.displayInLayerSwitcher){var f=e.isBaseLayer?e===this.map.baseLayer:e.getVisibility(),g=$.proxy(function(a){this.layerClick(a);return!1},this),h=$("<a></a>");h.click(g).attr("href","#").text(e.name).addClass("layer-toggle").data("layer",e).attr("disabled",!e.inRange),f&&h.addClass("active")}this.$element.append(h),this.$element.trigger("layeradded",h)}}}})
  34
+var wax=wax||{};Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var d=0,e;if(arguments.length>=2)e=arguments[1];else for(;;){if(d in b){e=b[d++];break}if(++d>=c)throw new TypeError}while(d<c)d in b&&(e=a.call(undefined,e,b[d],d,b)),d++;return e}),wax.Record=function(a,b){var c=function(a,b){var c=a.split(".").reduce(function(a,b){return[a[1]||a[0],a[1]?a[1][b]:a[0][b]]},[b||window,null]);if(c[0]&&c[1])return c;throw a+" not found."},d=function(a,b){var d=c(a),e;b=b.length?wax.Record(b):[];if(Object.create)e=Object.create(d[1].prototype),d[1].apply(e,b);else switch(b.length){case 0:e=new d[1];break;case 1:e=new d[1](b[0]);break;case 2:e=new d[1](b[0],b[1]);break;case 3:e=new d[1](b[0],b[1],b[2]);break;case 4:e=new d[1](b[0],b[1],b[2],b[3]);break;case 5:e=new d[1](b[0],b[1],b[2],b[3],b[4]);break;default:}return e},e=function(a,b,d){var e=c(a,d),f=b.length?wax.Record(b):[];return d&&wax.util.indexOf(".",a)===-1?e[1].apply(d,f):e[1].apply(e[0],f)},f=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@literal","@chain","@inject","@group"],a.split(" ")[0])!==-1},g=function(a){return wax.util.isString(a)&&wax.util.indexOf(["@new","@call","@chain"],a.split(" ")[0])!==-1},h=function(a){if(wax.util.isArray(a)&&a[0]&&f(a[0]))return{verb:a[0].split(" ")[0],subject:a[0].split(" ")[1],object:a.slice(1)};return!1},i,j=!1,k=null,l=null,m=h(a);if(!m){if(a!==null&&typeof a=="object"){var n=wax.util.keys(a);for(i=0;i<n.length;i++){var o=n[i];a[o]=wax.Record(a[o],b)}return a}return a}switch(m.verb){case"@group":for(i=0;i<m.object.length;i++)k=wax.Record(m.object[i],b),l=h(m.object[i]),l&&g(l.verb)&&(b=k);return b;case"@new":return d(m.subject,m.object);case"@literal":j=c(m.subject);return j?j[1]:null;case"@inject":return e(m.subject,m.object,b);case"@chain":return e(m.subject,m.object,b);case"@call":return e(m.subject,m.object,null)}};var wax=wax||{};wax.request={cache:{},locks:{},promises:{},get:function(a,b){if(this.cache[a])return b(this.cache[a][0],this.cache[a][1]);this.promises[a]=this.promises[a]||[],this.promises[a].push(b);if(!this.locks[a]){var c=this;this.locks[a]=!0,reqwest({url:a+"?callback=grid",type:"jsonp",jsonpCallback:"callback",success:function(b){c.locks[a]=!1,c.cache[a]=[null,b];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])},error:function(b){c.locks[a]=!1,c.cache[a]=[b,null];for(var d=0;d<c.promises[a].length;d++)c.promises[a][d](c.cache[a][0],c.cache[a][1])}})}}},wax.GridInstance=function(a,b){this.grid_tile=a,this.formatter=b,this.tileRes=4},wax.GridInstance.prototype.resolveCode=function(a){a>=93&&a--,a>=35&&a--,a-=32;return a},wax.GridInstance.prototype.getFeature=function(a,b,c,d){if(!!this.grid_tile&&!!this.grid_tile.grid){var e=wax.util.offset(c),f=e.left,g=e.top;if(Math.floor((b-g)/this.tileRes)>256)return;if(Math.floor((a-f)/this.tileRes)>256)return;var h=this.grid_tile.grid[Math.floor((b-g)/this.tileRes)].charCodeAt(Math.floor((a-f)/this.tileRes));h=this.resolveCode(h);if(this.grid_tile.keys[h])return this.formatter.format(d,this.grid_tile.data[this.grid_tile.keys[h]])}},wax.GridManager=function(){this.grid_tiles={},this.key_maps={},this.formatters={},this.locks={}},wax.GridManager.prototype.getGrid=function(a,b){var c=this;c.getFormatter(c.formatterUrl(a),function(d,e){if(d||!e)return b(d,null);wax.request.get(c.tileDataUrl(a),function(a,c){if(a)return b(a,null);b(null,new wax.GridInstance(c,e))})})},wax.GridManager.prototype.makeEvent=function(a){return{target:a.target||a.srcElement,pX:a.pageX||a.clientX,pY:a.pageY||a.clientY,evt:a}},wax.GridManager.prototype.tileDataUrl=function(a){return a.replace(/(\.png|\.jpg|\.jpeg)(\d*)/,".grid.json")},wax.GridManager.prototype.formatterUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")},wax.GridManager.prototype.getFormatter=function(a,b){var c=this;typeof this.formatters[a]!="undefined"?b(null,this.formatters[a]):wax.request.get(a,function(d,e){e&&e.formatter?c.formatters[a]=new wax.Formatter(e):c.formatters[a]=!1,b(d,c.formatters[a])})},wax.Formatter=function(obj){if(obj.formatter&&typeof obj.formatter=="string")try{eval("this.f = "+obj.formatter)}catch(e){console&&console.log(e)}else this.f=function(){}},wax.Formatter.prototype.format=function(a,b){try{return this.f(a,b)}catch(c){console&&console.log(c)}};var wax=wax||{};wax.Legend=function(a,b){this.context=a,this.container=b||$('<div class="wax-legends"></div>')[0],this.legends={},$(this.context).append(this.container)},wax.Legend.prototype.render=function(a){$(".wax-legend",this.container).hide();var b=wax.util.bind(function(a,b){b?this.legends[a]?this.legends[a].show():(this.legends[a]=$("<div class='wax-legend'></div>").append(b),this.container.append(this.legends[a])):this.legends[a]=!1},this),c=function(a){a&&a.legend&&b(e,a.legend)};for(var d=0;d<a.length;d++){var e=this.legendUrl(a[d]);wax.request.get(e,c)}},wax.Legend.prototype.legendUrl=function(a){return a.replace(/\d+\/\d+\/\d+\.\w+/,"layer.json")};var w=function(a){a.melt=function(b,c){b.apply(c,[a,c]);return a};return a},wax=wax||{};wax.tooltip={};var _currentTooltip;wax.tooltip.getToolTip=function(a,b,c,d){tooltip=document.createElement("div"),tooltip.className="wax-tooltip wax-tooltip-"+c,tooltip.innerHTML=a,b.appendChild(tooltip);return tooltip},wax.tooltip.click=function(a,b,c){var d=wax.tooltip.getToolTip(a,b,c),e=document.createElement("a");e.href="#close",e.className="close",e.innerHTML="Close",e.addListener("click",function(){d.parentNode.removeChild(d);return!1}),d.className+=" wax-popup",d.innerHTML=a,d.appendChild(e)},wax.tooltip.select=function(a,b,c,d){!a||(_currentTooltip=wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default",_currentTooltip&&(_currentTooltip.parentNode.removeChild(_currentTooltip),_currentTooltip=undefined)},wax.util=wax.util||{},wax.util={offset:function(a){var b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d+=a.offsetTop,e+=a.offsetLeft;return{top:d,left:e,height:c,width:b}},bind:function(a,b){var c=Array.prototype.slice.call(arguments,2);return function(){return a.apply(b,c.concat(Array.prototype.slice.call(arguments)))}},isString:function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},indexOf:function(a,b){var c=Array.prototype.indexOf;if(a===null)return-1;var d,e;if(c&&a.indexOf===c)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},keys:Object.keys||function(a){var b=Object.prototype.hasOwnProperty;if(a!==Object(a))throw new TypeError("Invalid object");var c=[];for(var d in a)b.call(a,d)&&(c[c.length]=d);return c},eventoffset:function(a){var b=0,c=0;if(!a)var a=window.event;if(a.pageX||a.pageY)return{x:a.pageX,y:a.pageY};if(a.clientX||a.clientY)return{x:a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:a.clientY+document.body.scrollTop+document.documentElement.scrollTop}}};var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Embedder=OpenLayers.Class(OpenLayers.Control,{initialize:function(a){a=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},setMap:function(a){$("#"+this.el+"-script").length&&(OpenLayers.Control.prototype.setMap.apply(this,arguments),$(a.div).prepend($('<input type="text" class="embed-src" />').css({"z-index":"9999999999",position:"relative"}).val("<div id='"+this.el+"-script'>"+$("#"+this.el+"-script").html()+"</div>"))),this.activate()},CLASS_NAME:"wax.ol.Embedder"});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Interaction=OpenLayers.Class(OpenLayers.Control,{feature:{},handlerOptions:null,handlers:null,gm:new wax.GridManager,initialize:function(a){this.options=a||{},this.clickAction=this.options.clickAction||"full",OpenLayers.Control.prototype.initialize.apply(this,[this.options||{}]),this.callbacks={out:wax.tooltip.unselect,over:wax.tooltip.select,click:wax.tooltip.click}},setMap:function(a){$(a.viewPortDiv).bind("mousemove",$.proxy(this.getInfoForHover,this)),$(a.viewPortDiv).bind("mouseout",$.proxy(this.resetLayers,this)),this.clickHandler=new OpenLayers.Handler.Click(this,{click:this.getInfoForClick}),this.clickHandler.setMap(a),this.clickHandler.activate(),a.events.on({addlayer:this.resetLayers,changelayer:this.resetLayers,removelayer:this.resetLayers,changebaselayer:this.resetLayers,scope:this}),OpenLayers.Control.prototype.setMap.apply(this,arguments)},getTileStack:function(a,b){var c=[];layerfound:for(var d=0;d<a.length;d++)for(var e=0;e<a[d].grid.length;e++)for(var f=0;f<a[d].grid[e].length;f++){var g=$(a[d].grid[e][f].imgDiv).offset();if(g&&g.top<b.pageY&&g.top+256>b.pageY&&g.left<b.pageX&&g.left+256>b.pageX){c.push(a[d].grid[e][f]);continue layerfound}}return c},viableLayers:function(){if(this._viableLayers)return this._viableLayers;return this._viableLayers=$(this.map.layers).filter(function(a){return this.map.layers[a].visibility===!0&&this.map.layers[a].CLASS_NAME==="OpenLayers.Layer.TMS"})},resetLayers:function(){this._viableLayers=null,this.callbacks.out()},getInfoForClick:function(a){var b=this.viableLayers(),c=this.getTileStack(this.viableLayers(),a),d=null,e=null,f=this;for(var g=0;g<c.length;g++)this.gm.getGrid(c[g].url,function(b){if(!!b){var d=b.getFeature(a.pageX,a.pageY,c[g].imgDiv,{format:f.clickAction});if(d)switch(f.clickAction){case"full":f.callbacks.click(d,c[g].layer.map.viewPortDiv,g);break;case"location":window.location=d}}})},getInfoForHover:function(a){var b={format:"teaser"},c=this.viableLayers(),d=this.getTileStack(this.viableLayers(),a),e=null,f=null,g=this;for(var h=0;h<d.length;h++)this.gm.getGrid(d[h].url,function(c){if(c&&d[h]){var e=c.getFeature(a.pageX,a.pageY,d[h].imgDiv,b);if(e){if(!d[h])return;e&&g.feature[h]!==e?(g.feature[h]=e,g.callbacks.out(e,d[h].layer.map.div,h,a),g.callbacks.over(e,d[h].layer.map.div,h,a)):e||(g.feature[h]=null,g.callbacks.out(e,d[h].layer.map.div,h,a))}else g.feature[h]=null,d[h]?g.callbacks.out({},d[h].layer.map.div,h,a):g.callbacks.out({},!1,h)}})},CLASS_NAME:"wax.ol.Interaction"});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Legend=OpenLayers.Class(OpenLayers.Control,{CLASS_NAME:"wax.ol.Legend",legend:null,options:null,initialize:function(a){this.options=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},activate:function(){this.legend=new wax.Legend(this.map.viewPortDiv,this.options.container);return OpenLayers.Control.prototype.activate.apply(this,arguments)},setMap:function(a){OpenLayers.Control.prototype.setMap.apply(this,arguments),this.activate(),this.map.events.on({addlayer:this.setLegend,changelayer:this.setLegend,removelayer:this.setLegend,changebaselayer:this.setLegend,scope:this})},setLegend:function(){var a=[];for(var b=0;b<this.map.layers.length;b++){var c=this.map.layers[b];c&&c.getURL&&c.visibility&&a.push(c.getURL(new OpenLayers.Bounds))}this.legend.render(a)}});var wax=wax||{};wax.ol=wax.ol||{},wax.ol.Switcher=OpenLayers.Class(OpenLayers.Control,{CLASS_NAME:"wax.ol.Switcher",initialize:function(a){this.$element=$(a.e),this.options=a||{},OpenLayers.Control.prototype.initialize.apply(this,[a||{}])},setMap:function(a){OpenLayers.Control.prototype.setMap.apply(this,arguments),this.map.events.on({addlayer:this.redraw,changelayer:this.redraw,removelayer:this.redraw,changebaselayer:this.redraw,scope:this}),this.redraw()},layerClick:function(a){var b=a.currentTarget,c=$(b).data("layer");$("a.active",this.$element).removeClass("active"),$.each(this.map.getLayersBy("isBaseLayer",!1),function(){this.CLASS_NAME!=="OpenLayers.Layer.Vector.RootContainer"&&this.displayInLayerSwitcher&&this.setVisibility(!1)}),c.setVisibility(!0),$(b).addClass("active")},needsRedraw:function(){if(!this.layerStates||this.layerStates.length||this.map.layers.length!=this.layerStates.length)return!0;for(var a=0,b=this.layerStates.length;a<b;a++){var c=this.layerStates[a],d=this.map.layers[a];if(c.name!=d.name||c.inRange!=d.inRange||c.id!=d.id||c.visibility!=d.visibility)return!0}return!1},redraw:function(){if(this.needsRedraw()){this.$element.html("");var a=this.map.layers.length;this.layerStates=[];for(var b=0;b<a;b++){var c=this.map.layers[b];this.layerStates[b]={name:c.name,visibility:c.visibility,inRange:c.inRange,id:c.id}}var d=this.map.layers.slice();for(b=0,a=d.length;b<a;b++){var e=d[b];if(e.displayInLayerSwitcher){var f=e.isBaseLayer?e===this.map.baseLayer:e.getVisibility(),g=$.proxy(function(a){this.layerClick(a);return!1},this),h=$("<a></a>");h.click(g).attr("href","#").text(e.name).addClass("layer-toggle").data("layer",e).attr("disabled",!e.inRange),f&&h.addClass("active")}this.$element.append(h),this.$element.trigger("layeradded",h)}}}})
31  control/lib/gridutil.js
@@ -14,7 +14,7 @@ wax.request = {
14 14
     get: function(url, callback) {
15 15
         // Cache hit.
16 16
         if (this.cache[url]) {
17  
-            return callback(this.cache[url]);
  17
+            return callback(this.cache[url][0], this.cache[url][1]);
18 18
         // Cache miss.
19 19
         } else {
20 20
             this.promises[url] = this.promises[url] || [];
@@ -30,16 +30,16 @@ wax.request = {
30 30
                 jsonpCallback: 'callback',
31 31
                 success: function(data) {
32 32
                     that.locks[url] = false;
33  
-                    that.cache[url] = data;
  33
+                    that.cache[url] = [null, data];
34 34
                     for (var i = 0; i < that.promises[url].length; i++) {
35  
-                        that.promises[url][i](that.cache[url]);
  35
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
36 36
                     }
37 37
                 },
38  
-                error: function() {
  38
+                error: function(err) {
39 39
                     that.locks[url] = false;
40  
-                    that.cache[url] = null;
  40
+                    that.cache[url] = [err, null];
41 41
                     for (var i = 0; i < that.promises[url].length; i++) {
42  
-                        that.promises[url][i](that.cache[url]);
  42
+                        that.promises[url][i](that.cache[url][0], that.cache[url][1]);
43 43
                     }
44 44
                 }
45 45
             });
@@ -76,8 +76,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
76 76
   var tileX = offset.left;
77 77
   var tileY = offset.top;
78 78
 
79  
-  if (Math.floor((y - tileY) / this.tileRes) > 256 ||
80  
-    Math.floor((x - tileX) / this.tileRes) > 256) return;
  79
+  if (Math.floor((y - tileY) / this.tileRes) > 256) return;
  80
+  if (Math.floor((x - tileX) / this.tileRes) > 256) return;
81 81
 
82 82
   var key = this.grid_tile.grid[
83 83
      Math.floor((y - tileY) / this.tileRes)
@@ -112,11 +112,12 @@ wax.GridManager = function() {
112 112
 // and gets grid data, and tries to avoid re-downloading either.
113 113
 wax.GridManager.prototype.getGrid = function(url, callback) {
114 114
     var that = this;
115  
-    that.getFormatter(that.formatterUrl(url), function(f) {
116  
-        if (!f) return callback(false);
  115
+    that.getFormatter(that.formatterUrl(url), function(err, f) {
  116
+        if (err || !f) return callback(err, null);
117 117
 
118  
-        wax.request.get(that.tileDataUrl(url), function(t) {
119  
-            callback(new wax.GridInstance(t, f));
  118
+        wax.request.get(that.tileDataUrl(url), function(err, t) {
  119
+            if (err) return callback(err, null);
  120
+            callback(null, new wax.GridInstance(t, f));
120 121
         });
121 122
     });
122 123
 };
@@ -146,16 +147,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
146 147
   var that = this;
147 148
   // Formatter is cached.
148 149
   if (typeof this.formatters[url] !== 'undefined') {
149  
-    callback(this.formatters[url]);
  150
+    callback(null, this.formatters[url]);
150 151
     return;
151 152
   } else {
152  
-    wax.request.get(url, function(data) {
  153
+    wax.request.get(url, function(err, data) {
153 154
         if (data && data.formatter) {
154 155
             that.formatters[url] = new wax.Formatter(data);
155 156
         } else {
156 157
             that.formatters[url] = false;
157 158
         }
158  
-        callback(that.formatters[url]);
  159
+        callback(err, that.formatters[url]);
159 160
     });
160 161
   }
161 162
 };
3  control/mm/interaction.js
@@ -96,7 +96,8 @@ wax.interaction = function(map, options) {
96 96
             if (!this._onMove) this._onMove = wax.util.bind(function(evt) {
97 97
                 var tile = this.getTile(evt);
98 98
                 if (tile) {
99  
-                    this.waxGM.getGrid(tile.src, wax.util.bind(function(g) {
  99
+                    this.waxGM.getGrid(tile.src, wax.util.bind(function(err, g) {
  100
+                        if (err) return;
100 101
                         if (g) {
101 102
                             var feature = g.getFeature(evt.pageX, evt.pageY, tile, {
102 103
                                 format: 'teaser'

0 notes on commit 0cb3253

Please sign in to comment.
Something went wrong with that request. Please try again.