Browse files

Internet Explorer doesn't register mousedown on divs without a backgr…

…ound color or contents. IE, you win. Again.
  • Loading branch information...
1 parent 0416b29 commit 723e68b7388c52700ee5a7697d083134f5810637 @tmcw tmcw committed May 24, 2011
Showing with 170 additions and 123 deletions.
  1. +2 −2 build/wax.g.js
  2. +71 −57 build/wax.mm.js
  3. +1 −1 build/wax.mm.min.js
  4. +2 −2 build/wax.ol.js
  5. +20 −0 control/lib/util.js
  6. +70 −56 control/mm/pointselector.js
  7. +3 −5 manual/index.html
  8. BIN theme/blank.gif
  9. +1 −0 theme/controls.css
View
4 build/wax.g.js
@@ -573,12 +573,12 @@ wax.util = {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
- if (e.pageX || e.pageY) {
+ if (e.pageX || e.pageY) {
return {
x: e.pageX,
y: e.pageY
}
- } else if (e.clientX || e.clientY) {
+ } else if (e.clientX || e.clientY) {
return {
x: e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft,
View
128 build/wax.mm.js
@@ -579,12 +579,12 @@ wax.util = {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
- if (e.pageX || e.pageY) {
+ if (e.pageX || e.pageY) {
return {
x: e.pageX,
y: e.pageY
}
- } else if (e.clientX || e.clientY) {
+ } else if (e.clientX || e.clientY) {
return {
x: e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft,
@@ -1111,6 +1111,7 @@ wax.pointselector = function(map, opts) {
var mouseDownPoint = null,
mouseUpPoint = null,
tolerance = 5,
+ overlayDiv,
MM = com.modestmaps,
locations = [];
@@ -1120,96 +1121,109 @@ wax.pointselector = function(map, opts) {
// Create a `com.modestmaps.Point` from a screen event, like a click.
var makePoint = function(e) {
- console.log('starting');
var coords = wax.util.eventoffset(e);
var point = new MM.Point(coords.x, coords.y);
// correct for scrolled document
// and for the document
- point.x -= parseFloat(MM.getStyle(document.documentElement, 'margin-left'));
- point.y -= parseFloat(MM.getStyle(document.documentElement, 'margin-top'));
+ var body = {
+ x: parseFloat(MM.getStyle(document.documentElement, 'margin-left')),
+ y: parseFloat(MM.getStyle(document.documentElement, 'margin-top'))
+ };
+
+ if (!isNaN(body.x)) point.x -= body.x;
+ if (!isNaN(body.y)) point.y -= body.y;
// correct for nested offsets in DOM
for (var node = map.parent; node; node = node.offsetParent) {
point.x -= node.offsetLeft;
point.y -= node.offsetTop;
}
- console.log(point);
return point;
};
+ function cleanLocations(locations) {
+ var o = [];
+ for (var i = 0; i < locations.length; i++) {
+ o.push(new MM.Location(locations[i].lat, locations[i].lon));
+ }
+ return o;
+ };
+
var pointselector = {
// Attach this control to a map by registering callbacks
// and adding the overlay
add: function(map) {
- this.overlayDiv = document.createElement('div');
- this.overlayDiv.id = map.parent.id + '-boxselector';
- this.overlayDiv.className = 'pointselector-box-container';
- this.overlayDiv.style.width = map.dimensions.x + 'px';
- this.overlayDiv.style.height = map.dimensions.y + 'px';
- map.parent.appendChild(this.overlayDiv);
- MM.addEvent(this.overlayDiv, 'mousedown', pointselector.mouseDown);
- map.addCallback('drawn', pointselector.drawPoints);
+ overlayDiv = document.createElement('div');
+ overlayDiv.id = map.parent.id + '-boxselector';
+ overlayDiv.className = 'pointselector-box-container';
+ overlayDiv.innerHTML = '&nbsp;';
+ overlayDiv.style.backgroundImage = 'url(http://a.tiles.mapbox.com/mapbox/1.0.0/world-glass/6/23/39.png)';
+ overlayDiv.style.width = map.dimensions.x + 'px';
+ overlayDiv.style.height = map.dimensions.y + 'px';
+
+ map.parent.appendChild(overlayDiv);
+ MM.addEvent(overlayDiv, 'mousedown', this.mouseDown());
+ map.addCallback('drawn', pointselector.drawPoints());
return this;
},
deletePoint: function(location, e) {
if (confirm('Delete this point?')) {
location.pointDiv.parentNode.removeChild(location.pointDiv);
locations.splice(wax.util.indexOf(locations, location), 1);
- callback(pointselector.cleanLocations(locations));
+ callback(cleanLocations(locations));
}
},
drawPoints: function() {
- var offset = new MM.Point(0, 0);
- for (var i = 0; i < locations.length; i++) {
- var point = map.locationPoint(locations[i]);
- if (!locations[i].pointDiv) {
- locations[i].pointDiv = document.createElement('div');
- locations[i].pointDiv.className = 'wax-point-div';
- locations[i].pointDiv.style.position = 'absolute';
- locations[i].pointDiv.style.display = 'block';
- // TODO: avoid circular reference
- locations[i].pointDiv.location = locations[i];
- // Create this closure once per point
- MM.addEvent(locations[i].pointDiv, 'mouseup', (function selectPointWrap(e) {
- var l = locations[i];
- return function(e) {
- MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp);
- pointselector.deletePoint(l, e);
- };
- })());
- this.overlayDiv.appendChild(locations[i].pointDiv);
+ return this._drawPoints = this._drawPoints || wax.util.bind(function() {
+ var offset = new MM.Point(0, 0);
+ for (var i = 0; i < locations.length; i++) {
+ var point = map.locationPoint(locations[i]);
+ if (!locations[i].pointDiv) {
+ locations[i].pointDiv = document.createElement('div');
+ locations[i].pointDiv.className = 'wax-point-div';
+ locations[i].pointDiv.style.position = 'absolute';
+ locations[i].pointDiv.style.display = 'block';
+ // TODO: avoid circular reference
+ locations[i].pointDiv.location = locations[i];
+ // Create this closure once per point
+ MM.addEvent(locations[i].pointDiv, 'mouseup', (function selectPointWrap(e) {
+ var l = locations[i];
+ return function(e) {
+ MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp());
+ pointselector.deletePoint(l, e);
+ };
+ })());
+ overlayDiv.appendChild(locations[i].pointDiv);
+ }
+ locations[i].pointDiv.style.left = point.x + 'px';
+ locations[i].pointDiv.style.top = point.y + 'px';
}
- locations[i].pointDiv.style.left = point.x + 'px';
- locations[i].pointDiv.style.top = point.y + 'px';
- }
+ }, this);
},
- mouseDown: function(e) {
- mouseDownPoint = makePoint(e);
- MM.addEvent(map.parent, 'mouseup', pointselector.mouseUp);
+ mouseDown: function() {
+ return this._mouseDown = this._mouseDown || wax.util.bind(function(e) {
+ mouseDownPoint = makePoint(e);
+ MM.addEvent(map.parent, 'mouseup', this.mouseUp());
+ }, this);
},
addLocation: function(location) {
locations.push(location);
- pointselector.drawPoints();
+ pointselector.drawPoints()();
},
// Remove the awful circular reference from locations.
// TODO: This function should be made unnecessary by not having it.
- cleanLocations: function(locations) {
- var o = [];
- for (var i = 0; i < locations.length; i++) {
- o.push(new MM.Location(locations[i].lat, locations[i].lon));
- }
- return o;
- },
- mouseUp: function(e) {
- if (!mouseDownPoint) return;
- mouseUpPoint = makePoint(e);
- if (MM.Point.distance(mouseDownPoint, mouseUpPoint) < tolerance) {
- pointselector.addLocation(map.pointLocation(mouseDownPoint));
- callback(pointselector.cleanLocations(locations));
- }
- mouseDownPoint = null;
- MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp);
+ mouseUp: function() {
+ return this._mouseUp = this._mouseUp || wax.util.bind(function(e) {
+ if (!mouseDownPoint) return;
+ mouseUpPoint = makePoint(e);
+ if (MM.Point.distance(mouseDownPoint, mouseUpPoint) < tolerance) {
+ this.addLocation(map.pointLocation(mouseDownPoint));
+ callback(cleanLocations(locations));
+ }
+ mouseDownPoint = null;
+ MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp());
+ }, this);
}
};
View
2 build/wax.mm.min.js
@@ -3,4 +3,4 @@
* copyright Dustin Diaz 2011
* https://github.com/ded/reqwest
* license MIT
- */!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={},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||(wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default"},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(){return 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)},mouseMove:function(a){return 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)},mouseUp:function(){return 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)},drawbox:function(){return 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 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){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 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,a,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){return 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)},mouseDown:function(b){return this._mouseDown=this._mouseDown||wax.util.bind(function(b){this.clearTimeout()||(this.downEvent=b,c.addEvent(a.parent,"mouseup",this.mouseUp()))},this)},mouseUp:function(){return 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)},click:function(a){return 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 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={},wax=wax||{},wax.pointselector=function(a,b){var c=null,d=null,e=5,f=com.modestmaps,g=[],h=typeof b=="function"?b:b.callback,i=function(b){console.log("starting");var c=wax.util.eventoffset(b),d=new f.Point(c.x,c.y);d.x-=parseFloat(f.getStyle(document.documentElement,"margin-left")),d.y-=parseFloat(f.getStyle(document.documentElement,"margin-top"));for(var e=a.parent;e;e=e.offsetParent)d.x-=e.offsetLeft,d.y-=e.offsetTop;console.log(d);return d},j={add:function(a){this.overlayDiv=document.createElement("div"),this.overlayDiv.id=a.parent.id+"-boxselector",this.overlayDiv.className="pointselector-box-container",this.overlayDiv.style.width=a.dimensions.x+"px",this.overlayDiv.style.height=a.dimensions.y+"px",a.parent.appendChild(this.overlayDiv),f.addEvent(this.overlayDiv,"mousedown",j.mouseDown),a.addCallback("drawn",j.drawPoints);return this},deletePoint:function(a,b){confirm("Delete this point?")&&(a.pointDiv.parentNode.removeChild(a.pointDiv),g.splice(wax.util.indexOf(g,a),1),h(j.cleanLocations(g)))},drawPoints:function(){var b=new f.Point(0,0);for(var c=0;c<g.length;c++){var d=a.locationPoint(g[c]);g[c].pointDiv||(g[c].pointDiv=document.createElement("div"),g[c].pointDiv.className="wax-point-div",g[c].pointDiv.style.position="absolute",g[c].pointDiv.style.display="block",g[c].pointDiv.location=g[c],f.addEvent(g[c].pointDiv,"mouseup",function(b){var d=g[c];return function(b){f.removeEvent(a.parent,"mouseup",j.mouseUp),j.deletePoint(d,b)}}()),this.overlayDiv.appendChild(g[c].pointDiv)),g[c].pointDiv.style.left=d.x+"px",g[c].pointDiv.style.top=d.y+"px"}},mouseDown:function(b){c=i(b),f.addEvent(a.parent,"mouseup",j.mouseUp)},addLocation:function(a){g.push(a),j.drawPoints()},cleanLocations:function(a){var b=[];for(var c=0;c<a.length;c++)b.push(new f.Location(a[c].lat,a[c].lon));return b},mouseUp:function(b){!c||(d=i(b),f.Point.distance(c,d)<e&&(j.addLocation(a.pointLocation(c)),h(j.cleanLocations(g))),c=null,f.removeEvent(a.parent,"mouseup",j.mouseUp))}};return j.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(){return 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)},mouseMove:function(a){return 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)},mouseUp:function(b){return 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 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)
+ */!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={},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||(wax.tooltip.getToolTip(a,b,c,d),b.style.cursor="pointer")},wax.tooltip.unselect=function(a,b,c,d){b.style.cursor="default"},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(){return 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)},mouseMove:function(a){return 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)},mouseUp:function(){return 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)},drawbox:function(){return 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 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){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 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,a,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){return 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)},mouseDown:function(b){return this._mouseDown=this._mouseDown||wax.util.bind(function(b){this.clearTimeout()||(this.downEvent=b,c.addEvent(a.parent,"mouseup",this.mouseUp()))},this)},mouseUp:function(){return 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)},click:function(a){return 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 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={},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.backgroundImage="url(http://a.tiles.mapbox.com/mapbox/1.0.0/world-glass/6/23/39.png)",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(){return 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)},mouseDown:function(){return this._mouseDown=this._mouseDown||wax.util.bind(function(b){c=j(b),g.addEvent(a.parent,"mouseup",this.mouseUp())},this)},addLocation:function(a){h.push(a),l.drawPoints()()},mouseUp:function(){return 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 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(){return 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)},mouseMove:function(a){return 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)},mouseUp:function(b){return 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 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)
View
4 build/wax.ol.js
@@ -573,12 +573,12 @@ wax.util = {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
- if (e.pageX || e.pageY) {
+ if (e.pageX || e.pageY) {
return {
x: e.pageX,
y: e.pageY
}
- } else if (e.clientX || e.clientY) {
+ } else if (e.clientX || e.clientY) {
return {
x: e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft,
View
20 control/lib/util.js
@@ -52,5 +52,25 @@ wax.util = {
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
return keys;
+ },
+
+ // From quirksmode
+ eventoffset: function(e) {
+ var posx = 0;
+ var posy = 0;
+ if (!e) var e = window.event;
+ if (e.pageX || e.pageY) {
+ return {
+ x: e.pageX,
+ y: e.pageY
+ }
+ } else if (e.clientX || e.clientY) {
+ return {
+ x: e.clientX + document.body.scrollLeft
+ + document.documentElement.scrollLeft,
+ y: e.clientY + document.body.scrollTop
+ + document.documentElement.scrollTop
+ }
+ }
}
};
View
126 control/mm/pointselector.js
@@ -8,6 +8,7 @@ wax.pointselector = function(map, opts) {
var mouseDownPoint = null,
mouseUpPoint = null,
tolerance = 5,
+ overlayDiv,
MM = com.modestmaps,
locations = [];
@@ -17,14 +18,18 @@ wax.pointselector = function(map, opts) {
// Create a `com.modestmaps.Point` from a screen event, like a click.
var makePoint = function(e) {
- var point = new MM.Point(e.clientX, e.clientY);
+ var coords = wax.util.eventoffset(e);
+ var point = new MM.Point(coords.x, coords.y);
// correct for scrolled document
- point.x += document.body.scrollLeft + document.documentElement.scrollLeft;
- point.y += document.body.scrollTop + document.documentElement.scrollTop;
// and for the document
- point.x -= parseFloat(MM.getStyle(document.documentElement, 'margin-left'));
- point.y -= parseFloat(MM.getStyle(document.documentElement, 'margin-top'));
+ var body = {
+ x: parseFloat(MM.getStyle(document.documentElement, 'margin-left')),
+ y: parseFloat(MM.getStyle(document.documentElement, 'margin-top'))
+ };
+
+ if (!isNaN(body.x)) point.x -= body.x;
+ if (!isNaN(body.y)) point.y -= body.y;
// correct for nested offsets in DOM
for (var node = map.parent; node; node = node.offsetParent) {
@@ -34,78 +39,87 @@ wax.pointselector = function(map, opts) {
return point;
};
+ function cleanLocations(locations) {
+ var o = [];
+ for (var i = 0; i < locations.length; i++) {
+ o.push(new MM.Location(locations[i].lat, locations[i].lon));
+ }
+ return o;
+ };
+
var pointselector = {
// Attach this control to a map by registering callbacks
// and adding the overlay
add: function(map) {
- this.overlayDiv = document.createElement('div');
- this.overlayDiv.id = map.parent.id + '-boxselector';
- this.overlayDiv.className = 'pointselector-box-container';
- this.overlayDiv.style.width = map.dimensions.x + 'px';
- this.overlayDiv.style.height = map.dimensions.y + 'px';
- map.parent.appendChild(this.overlayDiv);
- MM.addEvent(map.parent, 'mousedown', pointselector.mouseDown);
- map.addCallback('drawn', pointselector.drawPoints);
+ overlayDiv = document.createElement('div');
+ overlayDiv.id = map.parent.id + '-boxselector';
+ overlayDiv.className = 'pointselector-box-container';
+ overlayDiv.innerHTML = '&nbsp;';
+ overlayDiv.style.width = map.dimensions.x + 'px';
+ overlayDiv.style.height = map.dimensions.y + 'px';
+
+ map.parent.appendChild(overlayDiv);
+ MM.addEvent(overlayDiv, 'mousedown', this.mouseDown());
+ map.addCallback('drawn', pointselector.drawPoints());
return this;
},
deletePoint: function(location, e) {
if (confirm('Delete this point?')) {
location.pointDiv.parentNode.removeChild(location.pointDiv);
locations.splice(wax.util.indexOf(locations, location), 1);
- callback(pointselector.cleanLocations(locations));
+ callback(cleanLocations(locations));
}
},
drawPoints: function() {
- var offset = new MM.Point(0, 0);
- for (var i = 0; i < locations.length; i++) {
- var point = map.locationPoint(locations[i]);
- if (!locations[i].pointDiv) {
- locations[i].pointDiv = document.createElement('div');
- locations[i].pointDiv.className = 'wax-point-div';
- locations[i].pointDiv.style.position = 'absolute';
- locations[i].pointDiv.style.display = 'block';
- // TODO: avoid circular reference
- locations[i].pointDiv.location = locations[i];
- // Create this closure once per point
- MM.addEvent(locations[i].pointDiv, 'mouseup', (function selectPointWrap(e) {
- var l = locations[i];
- return function(e) {
- MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp);
- pointselector.deletePoint(l, e);
- };
- })());
- this.overlayDiv.appendChild(locations[i].pointDiv);
+ return this._drawPoints = this._drawPoints || wax.util.bind(function() {
+ var offset = new MM.Point(0, 0);
+ for (var i = 0; i < locations.length; i++) {
+ var point = map.locationPoint(locations[i]);
+ if (!locations[i].pointDiv) {
+ locations[i].pointDiv = document.createElement('div');
+ locations[i].pointDiv.className = 'wax-point-div';
+ locations[i].pointDiv.style.position = 'absolute';
+ locations[i].pointDiv.style.display = 'block';
+ // TODO: avoid circular reference
+ locations[i].pointDiv.location = locations[i];
+ // Create this closure once per point
+ MM.addEvent(locations[i].pointDiv, 'mouseup', (function selectPointWrap(e) {
+ var l = locations[i];
+ return function(e) {
+ MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp());
+ pointselector.deletePoint(l, e);
+ };
+ })());
+ overlayDiv.appendChild(locations[i].pointDiv);
+ }
+ locations[i].pointDiv.style.left = point.x + 'px';
+ locations[i].pointDiv.style.top = point.y + 'px';
}
- locations[i].pointDiv.style.left = point.x + 'px';
- locations[i].pointDiv.style.top = point.y + 'px';
- }
+ }, this);
},
- mouseDown: function(e) {
- mouseDownPoint = makePoint(e);
- MM.addEvent(map.parent, 'mouseup', pointselector.mouseUp);
+ mouseDown: function() {
+ return this._mouseDown = this._mouseDown || wax.util.bind(function(e) {
+ mouseDownPoint = makePoint(e);
+ MM.addEvent(map.parent, 'mouseup', this.mouseUp());
+ }, this);
},
addLocation: function(location) {
locations.push(location);
- pointselector.drawPoints();
+ pointselector.drawPoints()();
},
// Remove the awful circular reference from locations.
// TODO: This function should be made unnecessary by not having it.
- cleanLocations: function(locations) {
- var o = [];
- for (var i = 0; i < locations.length; i++) {
- o.push(new MM.Location(locations[i].lat, locations[i].lon));
- }
- return o;
- },
- mouseUp: function(e) {
- if (!mouseDownPoint) return;
- mouseUpPoint = makePoint(e);
- if (MM.Point.distance(mouseDownPoint, mouseUpPoint) < tolerance) {
- pointselector.addLocation(map.pointLocation(mouseDownPoint));
- callback(pointselector.cleanLocations(locations));
- }
- mouseDownPoint = null;
- MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp);
+ mouseUp: function() {
+ return this._mouseUp = this._mouseUp || wax.util.bind(function(e) {
+ if (!mouseDownPoint) return;
+ mouseUpPoint = makePoint(e);
+ if (MM.Point.distance(mouseDownPoint, mouseUpPoint) < tolerance) {
+ this.addLocation(map.pointLocation(mouseDownPoint));
+ callback(cleanLocations(locations));
+ }
+ mouseDownPoint = null;
+ MM.removeEvent(map.parent, 'mouseup', pointselector.mouseUp());
+ }, this);
}
};
View
8 manual/index.html
@@ -69,12 +69,10 @@
include it on your page. The include files are segmented by the mapping API you're
using, so in our case, we'll use Modest Maps - `mm`.
- <script src='build/wax.mm.min.js' type='text/javascript'></script>
Then you'll want to include the theme file so that you can see controls -
you can always swap in your own later on.
- <link href='theme/controls.css' rel='stylesheet' type='text/css' />
You'll do the usual Modest Maps setup - just as you'll do the standard setup
process with the other APIs.
@@ -273,9 +271,7 @@
new mm.Point(448,300))
wax.pointselector(m, function(coords) {
$('#modestmaps-pointselector .attribution').text(
- coords.map(function(c) {
- return c.lat + ',' + c.lon;
- }).join(' - '));
+ coords.join(' - '))
});
m.setCenterZoom(
new com.modestmaps.Location(38.8225909, -97.5585),
@@ -486,6 +482,7 @@
</span>
</div>
<pre class='sh_javascript run'>
+/*
var mm = com.modestmaps;
var m = new mm.Map('modestmaps-reverse',
new wax.provider({
@@ -504,6 +501,7 @@
m.setCenterZoom(
new com.modestmaps.Location(30.5, 69.78),
4);
+ */
</pre>
</div>
</div>
View
BIN theme/blank.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1 theme/controls.css
@@ -94,6 +94,7 @@ a.zoomer {
margin:0;
padding:0;
position:absolute;
+ background: url(blank.gif);
top:0;
left:0;
}

0 comments on commit 723e68b

Please sign in to comment.