diff --git a/polymaps.js b/polymaps.js index 1ce798b..a1169b6 100644 --- a/polymaps.js +++ b/polymaps.js @@ -1351,7 +1351,7 @@ po.wheel = function() { var bug40441 = /WebKit\/533/.test(navigator.userAgent) ? -1 : 0; po.arrow = function() { var arrow = {}, - key = {left: 0, right: 0, up: 0, down: 0, plus: 0, minus: 0}, + key = {left: 0, right: 0, up: 0, down: 0}, last = 0, repeatTimer, repeatDelay = 250, @@ -1362,7 +1362,7 @@ po.arrow = function() { function keydown(e) { if (e.ctrlKey || e.altKey || e.metaKey) return; - var now = Date.now(), dx = 0, dy = 0, dz = 0; + var now = Date.now(), dx = 0, dy = 0; switch (e.keyCode) { case 37: { if (!key.left) { @@ -1396,30 +1396,9 @@ po.arrow = function() { } break; } - case 109: case 189: { - if (!key.plus) { - last = now; - key.plus = 1; - if (!key.minus) dz = -1; - } - break; - } - case 61: case 187: { - if (!key.minus) { - last = now; - key.minus = 1; - if (!key.plus) dz = 1; - } - break; - } default: return; } - if (dz) { - var z = map.zoom(); - map.zoom(dz < 0 ? Math.ceil(z) - 1 : Math.floor(z) + 1); - } else if (dx || dy) { - map.panBy({x: dx, y: dy}); - } + if (dx || dy) map.panBy({x: dx, y: dy}); if (!repeatTimer && (key.left | key.right | key.up | key.down)) { repeatTimer = setInterval(repeat, repeatInterval); } @@ -1433,8 +1412,6 @@ po.arrow = function() { case 39: key.right = 0; break; case 38: key.up = 0; break; case 40: key.down = 0; break; - case 109: case 189: key.plus = 0; break; - case 61: case 187: key.minus = 0; break; default: return; } if (repeatTimer && !(key.left | key.right | key.up | key.down)) { @@ -1443,6 +1420,15 @@ po.arrow = function() { e.preventDefault(); } + function keypress(e) { + switch (e.charCode) { + case 45: case 95: map.zoom(Math.ceil(map.zoom()) - 1); break; + case 43: case 61: map.zoom(Math.floor(map.zoom()) + 1); break; + default: return; + } + e.preventDefault(); + } + function repeat() { if (!map) return; if (Date.now() < last + repeatDelay) return; @@ -1454,12 +1440,14 @@ po.arrow = function() { arrow.map = function(x) { if (!arguments.length) return map; if (map) { + parent.removeEventListener("keypress", keypress, false); parent.removeEventListener("keydown", keydown, false); parent.removeEventListener("keyup", keyup, false); parent = null; } if (map = x) { parent = map.focusableParent(); + parent.addEventListener("keypress", keypress, false); parent.addEventListener("keydown", keydown, false); parent.addEventListener("keyup", keyup, false); } diff --git a/polymaps.min.js b/polymaps.min.js index 06a7352..33b88c1 100644 --- a/polymaps.min.js +++ b/polymaps.min.js @@ -1,52 +1,51 @@ if(!org)var org={};if(!org.polymaps)org.polymaps={}; -(function(s){function M(){for(var d=0;da.row){var f=d;d=a;a=f}return{x0:d.column,y0:d.row,x1:a.column,y1:a.row,dx:a.column-d.column,dy:a.row-d.row}}function Z(d,a,f,e,c){f=Math.max(f,Math.floor(a.y0));e=Math.min(e,Math.ceil(a.y1));if(d.x0==a.x0&&d.y0==a.y0?d.x0+a.dy/d.dy*d.dx0,o=a.dx<0;for(f=f;fa.dy){f=i;i=a;a=f}if(i.dy>d.dy){f=i;i=d;d=f}if(a.dy>d.dy){f=a;a=d;d=f}i.dy&&Z(d,i,e,c,g);a.dy&&Z(d,a,e,c,g)}s.version="2.0.2+6";var S={x:0,y:0};s.id=function(){var d=0;return function(){return++d}}();s.svg=function(d){return document.createElementNS(s.ns.svg, -d)};s.ns={svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"};s.transform=function(d,a,f,e,c,g){var i={},j,o,t;if(!arguments.length){d=1;a=c=f=0;e=1;g=0}i.zoomFraction=function(l){if(!arguments.length)return o;o=l;j=Math.floor(o+Math.log(Math.sqrt(d*d+a*a+f*f+e*e))/Math.log(2));t=Math.pow(2,-j);return i};i.apply=function(l){var r=Math.pow(2,-l.zoom),h=Math.pow(2,l.zoom-j);return{column:(d*l.column*r+f*l.row*r+c)*h,row:(a*l.column*r+e*l.row*r+g)*h,zoom:l.zoom-j}};i.unapply=function(l){var r= -Math.pow(2,-l.zoom),h=Math.pow(2,l.zoom+j);return{column:(l.column*r*e-l.row*r*f-c*e+g*f)/(d*e-a*f)*h,row:(l.column*r*a-l.row*r*d-c*a+g*d)/(f*a-e*d)*h,zoom:l.zoom+j}};i.toString=function(){return"matrix("+[d*t,a*t,f*t,e*t].join(" ")+" 0 0)"};return i.zoomFraction(0)};s.cache=function(d,a){function f(r){l--;a&&a(r);delete i[r.key];if(r.next)r.next.prev=r.prev;else if(o=r.prev)o.next=null;if(r.prev)r.prev.next=r.next;else if(j=r.next)j.prev=null}function e(){for(var r=o;l>t;r=r.prev){if(!r)break;r.lock|| -f(r)}}var c={},g={},i={},j=null,o=null,t=64,l=0;c.peek=function(r){return i[[r.zoom,r.column,r.row].join("/")]};c.load=function(r,h){var m=[r.zoom,r.column,r.row].join("/"),q=i[m];if(q){if(q.prev){if(q.prev.next=q.next)q.next.prev=q.prev;else o=q.prev;q.prev=null;q.next=j;j=j.prev=q}q.lock=1;return g[m]=q}q={key:m,column:r.column,row:r.row,zoom:r.zoom,next:j,prev:null,lock:1};d.call(null,q,h);g[m]=i[m]=q;if(j)j.prev=q;else o=q;j=q;l++;e();return q};c.unload=function(r){if(!(r in g))return false;var h= -g[r];h.lock=0;delete g[r];h.request&&h.request.abort(false)?f(h):e();return h};c.locks=function(){return g};c.size=function(r){if(!arguments.length)return t;t=r;e();return c};return c};s.url=function(d){function a(e){var c=1<=g||!e.length)){c++;e.pop()()}}function a(i){for(var j=0;j=0)return k;return window};a.mouse=function(k){var u=(f.ownerSVGElement||f).createSVGPoint();if(V<0&&(window.scrollX||window.scrollY)){var y=document.body.appendChild(s.svg("svg")); -y.style.position="absolute";y.style.top=y.style.left="0px";var B=y.getScreenCTM();V=!(B.f||B.e);document.body.removeChild(y)}if(V){u.x=k.pageX;u.y=k.pageY}else{u.x=k.clientX;u.y=k.clientY}return u.matrixTransform(f.getScreenCTM().inverse())};a.size=function(k){if(!arguments.length)return c;e=k;return a.resize()};a.resize=function(){if(e){c=e;M.remove(a)}else{var k=f.ownerSVGElement||f;if(k.offsetWidth==null){D.setAttribute("width","100%");D.setAttribute("height","100%");k=D}b=k.getBoundingClientRect(); -c={x:b.width,y:b.height};M.add(a)}D.setAttribute("width",c.x);D.setAttribute("height",c.y);g={x:c.x/2,y:c.y/2};d();a.dispatch({type:"resize"});return a};a.tileSize=function(k){if(!arguments.length)return i;i=k;a.dispatch({type:"move"});return a};a.center=function(k){if(!arguments.length)return j;j=k;d();a.dispatch({type:"move"});return a};a.panBy=function(k){var u=45/Math.pow(2,o+t-3),y=k.x*u;k=k.y*u;return a.center({lon:j.lon+(w*k-n*y)/i.x,lat:Q(R(j.lat)+(w*y+n*k)/i.y)})};a.centerRange=function(k){if(!arguments.length)return H; -if(H=k){x=H[0].lat>-90?R(H[0].lat):-Infinity;G=H[0].lat<90?R(H[1].lat):Infinity}else{x=-Infinity;G=Infinity}d();a.dispatch({type:"move"});return a};a.zoom=function(k){if(!arguments.length)return o+t;o=Math.max(r[0],Math.min(r[1],k));t=o-(o=Math.round(o));l=Math.pow(2,t);return a.center(j)};a.zoomBy=function(k,u,y){if(arguments.length<2)return a.zoom(o+t+k);if(arguments.length<3)y=a.pointLocation(u);o=Math.max(r[0],Math.min(r[1],o+t+k));t=o-(o=Math.round(o));l=Math.pow(2,t);var B=a.locationPoint(y); -return a.panBy({x:u.x-B.x,y:u.y-B.y})};a.zoomRange=function(k){if(!arguments.length)return r;r=k;return a.zoom(o+t)};a.angle=function(k){if(!arguments.length)return h;h=k;m=Math.cos(h);q=Math.sin(h);n=Math.cos(-h);w=Math.sin(-h);d();a.dispatch({type:"move"});return a};a.add=function(k){k.map(a);return a};a.remove=function(k){k.map(null);return a};a.dispatch=s.dispatch(a);return a};M.maps=[];M.add=function(d){for(var a=0;a>O,row:A>>O,zoom:C-O}))&&N.ready){L[N.key]=c.load(P);N.proxyCount++;K.proxyRefs[N.key]=N;break}}L[K.key]=K}}var n=e.map(),w=n.zoom(),x=w-(w=Math.round(w)),G=n.size(),H=n.angle(),D=n.tileSize(),k=n.locationCoordinate(n.center());i?l.removeAttribute("visibility"):l.setAttribute("visibility","hidden");for(var u=-4;u<=2;u++)h[u].setAttribute("class","zoom"+(u<0?"":"+")+u+" zoom"+(w+u));l.setAttribute("transform","translate("+G.x/2+","+G.y/2+")"+(H?"rotate("+H/Math.PI*180+")":"")+(x? -"scale("+Math.pow(2,x)+")":"")+(r?r.zoomFraction(x):""));var y=n.pointCoordinate(k,S);u=n.pointCoordinate(k,{x:G.x,y:0});var B=n.pointCoordinate(k,G);n=n.pointCoordinate(k,{x:0,y:G.y});if(!x&&!H&&!r){k.column=(Math.round(D.x*k.column)+(G.x&1)/2)/D.x;k.row=(Math.round(D.y*k.row)+(G.y&1)/2)/D.y}var I=j?j(w)-w:0;if(I){x=Math.pow(2,I);y.column*=x;y.row*=x;u.column*=x;u.row*=x;B.column*=x;B.row*=x;n.column*=x;n.row*=x;y.zoom=u.zoom=B.zoom=n.zoom+=I}if(r){y=r.unapply(y);u=r.unapply(u);B=r.unapply(B);n= -r.unapply(n);k=r.unapply(k)}w=c.locks();var L={};for(var E in w)w[E].proxyCount=0;if(i&&I>-5&&I<3){x=1<>u<>u<=1;q--)(h[q]=l.appendChild(s.svg("g"))).setAttribute("transform","scale("+Math.pow(2,-q)+")");h[0]=l.appendChild(s.svg("g"));e.init&&e.init(l);t.on("move",f).on("resize",f);f()}return e};e.container=function(){return l};e.id=function(m){if(!arguments.length)return o;o=m;return e};e.visible=function(m){if(!arguments.length)return i;i=m;t&&f();return e};e.transform=function(m){if(!arguments.length)return r; -r=m;t&&f();return e};e.zoom=function(m){if(!arguments.length)return j;j=typeof m=="function"||m==null?m:function(){return m};return e};e.tile=function(m){if(!arguments.length)return g;g=m;return e};e.dispatch=s.dispatch(e);e.on("load",function(m){if(m.tile.proxyRefs){for(var q in m.tile.proxyRefs){var n=m.tile.proxyRefs[q];--n.proxyCount<=0&&c.unload(q)&&n.element.parentNode.removeChild(n.element)}delete m.tile.proxyRefs}});return e};s.image=function(){var d=s.layer(function(f){var e=f.element=s.svg("image"), -c=d.map().tileSize();e.setAttribute("preserveAspectRatio","none");e.setAttribute("width",c.x);e.setAttribute("height",c.y);e.setAttribute("opacity",0);if(typeof a=="function")f.request=s.queue.image(e,a(f),function(){delete f.request;f.ready=true;e.removeAttribute("opacity");d.dispatch({type:"load",tile:f})});else{f.ready=true;e.setAttributeNS(s.ns.xlink,"href",a);d.dispatch({type:"load",tile:f})}},function(f){f.request&&f.request.abort(true)}),a="about:blank";d.url=function(f){if(!arguments.length)return a; -a=typeof f=="string"&&/{.}/.test(f)?s.url(f):f;return d};return d};s.geoJson=function(d){function a(h,m){var q=m({lat:h[1],lon:h[0]}),n=s.svg("circle");n.setAttribute("r",4.5);n.setAttribute("cx",q.x);n.setAttribute("cy",q.y);return n}function f(h,m,q,n){n.push("M");for(var w=0;w9&&Math.abs(t.wheelDelta)/m>=50)Y=1;c=h}if(Y==1)l*=0.03;i||(i=j.pointLocation(r));j.off("move",d);if(g)j.zoomBy(l,r,i);else if(l){h=Date.now();if(h-e>200){j.zoomBy(l>0?+1:-1,r,i);e=h}}j.on("move",d);t.preventDefault();return false}var f={},e=0,c=0,g=true,i,j,o;f.smooth=function(t){if(!arguments.length)return g;g=t;return f};f.map=function(t){if(!arguments.length)return j;if(j){o.removeEventListener("mousemove",d,false);o.removeEventListener("mousewheel",a,false); -o.removeEventListener("DOMMouseScroll",a,false);o=null;j.off("move",d)}if(j=t){j.on("move",d);o=j.container();o.addEventListener("mousemove",d,false);o.addEventListener("mousewheel",a,false);o.addEventListener("DOMMouseScroll",a,false)}return f};return f};var Y=/WebKit\/533/.test(navigator.userAgent)?-1:0;s.arrow=function(){function d(h){if(!(h.ctrlKey||h.altKey||h.metaKey)){var m=Date.now(),q=0,n=0,w=0;switch(h.keyCode){case 37:if(!c.left){g=m;c.left=1;c.right||(q=t)}break;case 39:if(!c.right){g= -m;c.right=1;c.left||(q=-t)}break;case 38:if(!c.up){g=m;c.up=1;c.down||(n=t)}break;case 40:if(!c.down){g=m;c.down=1;c.up||(n=-t)}break;case 109:case 189:if(!c.plus){g=m;c.plus=1;c.minus||(w=-1)}break;case 61:case 187:if(!c.minus){g=m;c.minus=1;c.plus||(w=1)}break;default:return}if(w){m=l.zoom();l.zoom(w<0?Math.ceil(m)-1:Math.floor(m)+1)}else if(q||n)l.panBy({x:q,y:n});if(!i&&c.left|c.right|c.up|c.down)i=setInterval(f,o);h.preventDefault()}}function a(h){g=Date.now();switch(h.keyCode){case 37:c.left= -0;break;case 39:c.right=0;break;case 38:c.up=0;break;case 40:c.down=0;break;case 109:case 189:c.plus=0;break;case 61:case 187:c.minus=0;break;default:return}if(i&&!(c.left|c.right|c.up|c.down))i=clearInterval(i);h.preventDefault()}function f(){if(l)if(!(Date.now()H+D&&E.panBy(L)}function f(){n.setAttribute("class","compass");if(I){clearInterval(I);I=0}}function e(v){return function(){v?this.setAttribute("class","active"):this.removeAttribute("class");L=v}}function c(v){return function(z){n.setAttribute("class","compass active");var A=E.zoom();E.zoom(v< -0?Math.ceil(A)-1:Math.floor(A)+1);return o(z)}}function g(v){return function(z){E.zoom(v);return o(z)}}function i(){this.setAttribute("class","active")}function j(){this.removeAttribute("class")}function o(v){v.stopPropagation();v.preventDefault();return false}function t(v){var z=Math.SQRT1_2*x,A=x*0.7,C=x*0.2,F=s.svg("g"),J=F.appendChild(s.svg("path")),K=F.appendChild(s.svg("path"));J.setAttribute("class","direction");J.setAttribute("pointer-events","all");J.setAttribute("d","M0,0L"+z+","+z+"A"+ -x+","+x+" 0 0,1 "+-z+","+z+"Z");K.setAttribute("class","chevron");K.setAttribute("d","M"+C+","+(A-C)+"L0,"+A+" "+-C+","+(A-C));K.setAttribute("pointer-events","none");F.addEventListener("mousedown",d,false);F.addEventListener("mouseover",e(v),false);F.addEventListener("mouseout",e(null),false);F.addEventListener("dblclick",o,false);return F}function l(v){var z=x*0.4,A=z/2,C=s.svg("g"),F=C.appendChild(s.svg("path")),J=C.appendChild(s.svg("path")),K=C.appendChild(s.svg("path")),P=C.appendChild(s.svg("path")); -F.setAttribute("class","back");F.setAttribute("d","M"+-z+",0V"+-z+"A"+z+","+z+" 0 1,1 "+z+","+-z+"V0Z");J.setAttribute("class","direction");J.setAttribute("d",F.getAttribute("d"));K.setAttribute("class","chevron");K.setAttribute("d","M"+-A+","+-z+"H"+A+(v>0?"M0,"+(-z-A)+"V"+-A:""));P.setAttribute("class","fore");P.setAttribute("fill","none");P.setAttribute("d",F.getAttribute("d"));C.addEventListener("mousedown",c(v),false);C.addEventListener("mouseover",i,false);C.addEventListener("mouseout",j,false); -C.addEventListener("dblclick",o,false);return C}function r(v){var z=x*0.2,A=x*0.4,C=s.svg("g"),F=C.appendChild(s.svg("rect")),J=C.appendChild(s.svg("path"));F.setAttribute("pointer-events","all");F.setAttribute("fill","none");F.setAttribute("x",-A);F.setAttribute("y",-0.75*A);F.setAttribute("width",2*A);F.setAttribute("height",1.5*A);J.setAttribute("class","chevron");J.setAttribute("d","M"+-z+",0H"+z);C.addEventListener("mousedown",g(v),false);C.addEventListener("dblclick",o,false);return C}function h(){var v= -x+6,z=v,A=E.size();switch(u){case "top-left":break;case "top-right":v=A.x-v;break;case "bottom-left":z=A.y-z;break;case "bottom-right":v=A.x-v;z=A.y-z;break}n.setAttribute("transform","translate("+v+","+z+")");for(var C in w)C==E.zoom()?w[C].setAttribute("class","active"):w[C].removeAttribute("class")}function m(){for(;n.lastChild;)n.removeChild(n.lastChild);if(B!="none"){var v=n.appendChild(s.svg("g"));v.setAttribute("class","pan");var z=v.appendChild(s.svg("circle"));z.setAttribute("class","back"); -z.setAttribute("r",x);v.appendChild(t({x:0,y:-G})).setAttribute("transform","rotate(0)");v.appendChild(t({x:G,y:0})).setAttribute("transform","rotate(90)");v.appendChild(t({x:0,y:G})).setAttribute("transform","rotate(180)");v.appendChild(t({x:-G,y:0})).setAttribute("transform","rotate(270)");v=v.appendChild(s.svg("circle"));v.setAttribute("fill","none");v.setAttribute("class","fore");v.setAttribute("r",x)}if(y!="none"){v=n.appendChild(s.svg("g"));v.setAttribute("class","zoom");z=-0.5;if(y=="big"){w= -{};var A=E.zoomRange()[0];for(z=0;A<=E.zoomRange()[1];A++,z++)(w[A]=v.appendChild(r(A))).setAttribute("transform","translate(0,"+-(z+0.75)*x*0.4+")")}A=B=="none"?0.4:2;v.setAttribute("transform","translate(0,"+x*(/^top-/.test(u)?A+(z+0.5)*0.4:-A)+")");v.appendChild(l(+1)).setAttribute("transform","translate(0,"+-(z+0.5)*x*0.4+")");v.appendChild(l(-1)).setAttribute("transform","scale(-1)")}h()}var q={},n=s.svg("g"),w={},x=30,G=16,H=0,D=250,k=50,u="top-left",y="small",B="small",I,L,E;n.setAttribute("class", -"compass");q.radius=function(v){if(!arguments.length)return x;x=v;E&&m();return q};q.speed=function(v){if(!arguments.length)return x;G=v;return q};q.position=function(v){if(!arguments.length)return u;u=v;E&&m();return q};q.pan=function(v){if(!arguments.length)return B;B=v;E&&m();return q};q.zoom=function(v){if(!arguments.length)return y;y=v;E&&m();return q};q.map=function(v){if(!arguments.length)return E;if(E){n.parentNode.removeChild(n);E.off("move",h).off("resize",h);window.removeEventListener("mouseup", -f,false)}if(E=v){window.addEventListener("mouseup",f,false);E.on("move",h).on("resize",h);E.container().appendChild(n);m()}return q};return q};s.grid=function(){function d(){var c=e.firstChild,g=f.size(),i=f.pointLocation(S);f.pointLocation(g);var j=Math.pow(2,4-Math.round(f.zoom()));i.lat=Math.floor(i.lat/j)*j;i.lon=Math.ceil(i.lon/j)*j;for(var o;(o=f.locationPoint(i).x)<=g.x;i.lon+=j){c||(c=e.appendChild(s.svg("line")));c.setAttribute("x1",o);c.setAttribute("x2",o);c.setAttribute("y1",0);c.setAttribute("y2", -g.y);c=c.nextSibling}for(;(o=f.locationPoint(i).y)<=g.y;i.lat-=j){c||(c=e.appendChild(s.svg("line")));c.setAttribute("y1",o);c.setAttribute("y2",o);c.setAttribute("x1",0);c.setAttribute("x2",g.x);c=c.nextSibling}for(;c;){g=c.nextSibling;e.removeChild(c);c=g}}var a={},f,e=s.svg("g");e.setAttribute("class","grid");a.map=function(c){if(!arguments.length)return f;if(f){e.parentNode.removeChild(e);f.off("move",d).off("resize",d)}if(f=c){f.on("move",d).on("resize",d);f.container().appendChild(e);f.dispatch({type:"move"})}return a}; -return a}})(org.polymaps); +(function(s){function M(){for(var d=0;da.row){var e=d;d=a;a=e}return{x0:d.column,y0:d.row,x1:a.column,y1:a.row,dx:a.column-d.column,dy:a.row-d.row}}function Z(d,a,e,f,h){e=Math.max(e,Math.floor(a.y0));f=Math.min(f,Math.ceil(a.y1));if(d.x0==a.x0&&d.y0==a.y0?d.x0+a.dy/d.dy*d.dx0,r=a.dx<0;for(e=e;ea.dy){e=i;i=a;a=e}if(i.dy>d.dy){e=i;i=d;d=e}if(a.dy>d.dy){e=a;a=d;d=e}i.dy&&Z(d,i,f,h,c);a.dy&&Z(d,a,f,h,c)}s.version="2.0.2+6";var S={x:0,y:0};s.id=function(){var d=0;return function(){return++d}}();s.svg=function(d){return document.createElementNS(s.ns.svg, +d)};s.ns={svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"};s.transform=function(d,a,e,f,h,c){var i={},j,r,u;if(!arguments.length){d=1;a=h=e=0;f=1;c=0}i.zoomFraction=function(m){if(!arguments.length)return r;r=m;j=Math.floor(r+Math.log(Math.sqrt(d*d+a*a+e*e+f*f))/Math.log(2));u=Math.pow(2,-j);return i};i.apply=function(m){var o=Math.pow(2,-m.zoom),g=Math.pow(2,m.zoom-j);return{column:(d*m.column*o+e*m.row*o+h)*g,row:(a*m.column*o+f*m.row*o+c)*g,zoom:m.zoom-j}};i.unapply=function(m){var o= +Math.pow(2,-m.zoom),g=Math.pow(2,m.zoom+j);return{column:(m.column*o*f-m.row*o*e-h*f+c*e)/(d*f-a*e)*g,row:(m.column*o*a-m.row*o*d-h*a+c*d)/(e*a-f*d)*g,zoom:m.zoom+j}};i.toString=function(){return"matrix("+[d*u,a*u,e*u,f*u].join(" ")+" 0 0)"};return i.zoomFraction(0)};s.cache=function(d,a){function e(o){m--;a&&a(o);delete i[o.key];if(o.next)o.next.prev=o.prev;else if(r=o.prev)r.next=null;if(o.prev)o.prev.next=o.next;else if(j=o.next)j.prev=null}function f(){for(var o=r;m>u;o=o.prev){if(!o)break;o.lock|| +e(o)}}var h={},c={},i={},j=null,r=null,u=64,m=0;h.peek=function(o){return i[[o.zoom,o.column,o.row].join("/")]};h.load=function(o,g){var k=[o.zoom,o.column,o.row].join("/"),q=i[k];if(q){if(q.prev){if(q.prev.next=q.next)q.next.prev=q.prev;else r=q.prev;q.prev=null;q.next=j;j=j.prev=q}q.lock=1;return c[k]=q}q={key:k,column:o.column,row:o.row,zoom:o.zoom,next:j,prev:null,lock:1};d.call(null,q,g);c[k]=i[k]=q;if(j)j.prev=q;else r=q;j=q;m++;f();return q};h.unload=function(o){if(!(o in c))return false;var g= +c[o];g.lock=0;delete c[o];g.request&&g.request.abort(false)?e(g):f();return g};h.locks=function(){return c};h.size=function(o){if(!arguments.length)return u;u=o;f();return h};return h};s.url=function(d){function a(f){var h=1<=c||!f.length)){h++;f.pop()()}}function a(i){for(var j=0;j=0)return l;return window};a.mouse=function(l){var t=(e.ownerSVGElement||e).createSVGPoint();if(V<0&&(window.scrollX||window.scrollY)){var y=document.body.appendChild(s.svg("svg")); +y.style.position="absolute";y.style.top=y.style.left="0px";var B=y.getScreenCTM();V=!(B.f||B.e);document.body.removeChild(y)}if(V){t.x=l.pageX;t.y=l.pageY}else{t.x=l.clientX;t.y=l.clientY}return t.matrixTransform(e.getScreenCTM().inverse())};a.size=function(l){if(!arguments.length)return h;f=l;return a.resize()};a.resize=function(){if(f){h=f;M.remove(a)}else{var l=e.ownerSVGElement||e;if(l.offsetWidth==null){D.setAttribute("width","100%");D.setAttribute("height","100%");l=D}b=l.getBoundingClientRect(); +h={x:b.width,y:b.height};M.add(a)}D.setAttribute("width",h.x);D.setAttribute("height",h.y);c={x:h.x/2,y:h.y/2};d();a.dispatch({type:"resize"});return a};a.tileSize=function(l){if(!arguments.length)return i;i=l;a.dispatch({type:"move"});return a};a.center=function(l){if(!arguments.length)return j;j=l;d();a.dispatch({type:"move"});return a};a.panBy=function(l){var t=45/Math.pow(2,r+u-3),y=l.x*t;l=l.y*t;return a.center({lon:j.lon+(w*l-n*y)/i.x,lat:Q(R(j.lat)+(w*y+n*l)/i.y)})};a.centerRange=function(l){if(!arguments.length)return H; +if(H=l){x=H[0].lat>-90?R(H[0].lat):-Infinity;G=H[0].lat<90?R(H[1].lat):Infinity}else{x=-Infinity;G=Infinity}d();a.dispatch({type:"move"});return a};a.zoom=function(l){if(!arguments.length)return r+u;r=Math.max(o[0],Math.min(o[1],l));u=r-(r=Math.round(r));m=Math.pow(2,u);return a.center(j)};a.zoomBy=function(l,t,y){if(arguments.length<2)return a.zoom(r+u+l);if(arguments.length<3)y=a.pointLocation(t);r=Math.max(o[0],Math.min(o[1],r+u+l));u=r-(r=Math.round(r));m=Math.pow(2,u);var B=a.locationPoint(y); +return a.panBy({x:t.x-B.x,y:t.y-B.y})};a.zoomRange=function(l){if(!arguments.length)return o;o=l;return a.zoom(r+u)};a.angle=function(l){if(!arguments.length)return g;g=l;k=Math.cos(g);q=Math.sin(g);n=Math.cos(-g);w=Math.sin(-g);d();a.dispatch({type:"move"});return a};a.add=function(l){l.map(a);return a};a.remove=function(l){l.map(null);return a};a.dispatch=s.dispatch(a);return a};M.maps=[];M.add=function(d){for(var a=0;a>O,row:A>>O,zoom:C-O}))&&N.ready){L[N.key]=h.load(P);N.proxyCount++;K.proxyRefs[N.key]=N;break}}L[K.key]=K}}var n=f.map(),w=n.zoom(),x=w-(w=Math.round(w)),G=n.size(),H=n.angle(),D=n.tileSize(),l=n.locationCoordinate(n.center());i?m.removeAttribute("visibility"):m.setAttribute("visibility","hidden");for(var t=-4;t<=2;t++)g[t].setAttribute("class","zoom"+(t<0?"":"+")+t+" zoom"+(w+t));m.setAttribute("transform","translate("+G.x/2+","+G.y/2+")"+(H?"rotate("+H/Math.PI*180+")":"")+(x? +"scale("+Math.pow(2,x)+")":"")+(o?o.zoomFraction(x):""));var y=n.pointCoordinate(l,S);t=n.pointCoordinate(l,{x:G.x,y:0});var B=n.pointCoordinate(l,G);n=n.pointCoordinate(l,{x:0,y:G.y});if(!x&&!H&&!o){l.column=(Math.round(D.x*l.column)+(G.x&1)/2)/D.x;l.row=(Math.round(D.y*l.row)+(G.y&1)/2)/D.y}var I=j?j(w)-w:0;if(I){x=Math.pow(2,I);y.column*=x;y.row*=x;t.column*=x;t.row*=x;B.column*=x;B.row*=x;n.column*=x;n.row*=x;y.zoom=t.zoom=B.zoom=n.zoom+=I}if(o){y=o.unapply(y);t=o.unapply(t);B=o.unapply(B);n= +o.unapply(n);l=o.unapply(l)}w=h.locks();var L={};for(var E in w)w[E].proxyCount=0;if(i&&I>-5&&I<3){x=1<>t<>t<=1;q--)(g[q]=m.appendChild(s.svg("g"))).setAttribute("transform","scale("+Math.pow(2,-q)+")");g[0]=m.appendChild(s.svg("g"));f.init&&f.init(m);u.on("move",e).on("resize",e);e()}return f};f.container=function(){return m};f.id=function(k){if(!arguments.length)return r;r=k;return f};f.visible=function(k){if(!arguments.length)return i;i=k;u&&e();return f};f.transform=function(k){if(!arguments.length)return o; +o=k;u&&e();return f};f.zoom=function(k){if(!arguments.length)return j;j=typeof k=="function"||k==null?k:function(){return k};return f};f.tile=function(k){if(!arguments.length)return c;c=k;return f};f.dispatch=s.dispatch(f);f.on("load",function(k){if(k.tile.proxyRefs){for(var q in k.tile.proxyRefs){var n=k.tile.proxyRefs[q];--n.proxyCount<=0&&h.unload(q)&&n.element.parentNode.removeChild(n.element)}delete k.tile.proxyRefs}});return f};s.image=function(){var d=s.layer(function(e){var f=e.element=s.svg("image"), +h=d.map().tileSize();f.setAttribute("preserveAspectRatio","none");f.setAttribute("width",h.x);f.setAttribute("height",h.y);f.setAttribute("opacity",0);if(typeof a=="function")e.request=s.queue.image(f,a(e),function(){delete e.request;e.ready=true;f.removeAttribute("opacity");d.dispatch({type:"load",tile:e})});else{e.ready=true;f.setAttributeNS(s.ns.xlink,"href",a);d.dispatch({type:"load",tile:e})}},function(e){e.request&&e.request.abort(true)}),a="about:blank";d.url=function(e){if(!arguments.length)return a; +a=typeof e=="string"&&/{.}/.test(e)?s.url(e):e;return d};return d};s.geoJson=function(d){function a(g,k){var q=k({lat:g[1],lon:g[0]}),n=s.svg("circle");n.setAttribute("r",4.5);n.setAttribute("cx",q.x);n.setAttribute("cy",q.y);return n}function e(g,k,q,n){n.push("M");for(var w=0;w9&&Math.abs(u.wheelDelta)/k>=50)Y=1;h=g}if(Y==1)m*=0.03;i||(i=j.pointLocation(o));j.off("move",d);if(c)j.zoomBy(m,o,i);else if(m){g=Date.now();if(g-f>200){j.zoomBy(m>0?+1:-1,o,i);f=g}}j.on("move",d);u.preventDefault();return false}var e={},f=0,h=0,c=true,i,j,r;e.smooth=function(u){if(!arguments.length)return c;c=u;return e};e.map=function(u){if(!arguments.length)return j;if(j){r.removeEventListener("mousemove",d,false);r.removeEventListener("mousewheel",a,false); +r.removeEventListener("DOMMouseScroll",a,false);r=null;j.off("move",d)}if(j=u){j.on("move",d);r=j.container();r.addEventListener("mousemove",d,false);r.addEventListener("mousewheel",a,false);r.addEventListener("DOMMouseScroll",a,false)}return e};return e};var Y=/WebKit\/533/.test(navigator.userAgent)?-1:0;s.arrow=function(){function d(k){if(!(k.ctrlKey||k.altKey||k.metaKey)){var q=Date.now(),n=0,w=0;switch(k.keyCode){case 37:if(!c.left){i=q;c.left=1;c.right||(n=m)}break;case 39:if(!c.right){i=q;c.right= +1;c.left||(n=-m)}break;case 38:if(!c.up){i=q;c.up=1;c.down||(w=m)}break;case 40:if(!c.down){i=q;c.down=1;c.up||(w=-m)}break;default:return}if(n||w)o.panBy({x:n,y:w});if(!j&&c.left|c.right|c.up|c.down)j=setInterval(f,u);k.preventDefault()}}function a(k){i=Date.now();switch(k.keyCode){case 37:c.left=0;break;case 39:c.right=0;break;case 38:c.up=0;break;case 40:c.down=0;break;default:return}if(j&&!(c.left|c.right|c.up|c.down))j=clearInterval(j);k.preventDefault()}function e(k){switch(k.charCode){case 45:case 95:o.zoom(Math.ceil(o.zoom())- +1);break;case 43:case 61:o.zoom(Math.floor(o.zoom())+1);break;default:return}k.preventDefault()}function f(){if(o)if(!(Date.now()H+D&&E.panBy(L)}function e(){n.setAttribute("class","compass");if(I){clearInterval(I);I=0}}function f(v){return function(){v?this.setAttribute("class","active"):this.removeAttribute("class");L=v}}function h(v){return function(z){n.setAttribute("class","compass active");var A=E.zoom();E.zoom(v<0?Math.ceil(A)-1:Math.floor(A)+1);return r(z)}} +function c(v){return function(z){E.zoom(v);return r(z)}}function i(){this.setAttribute("class","active")}function j(){this.removeAttribute("class")}function r(v){v.stopPropagation();v.preventDefault();return false}function u(v){var z=Math.SQRT1_2*x,A=x*0.7,C=x*0.2,F=s.svg("g"),J=F.appendChild(s.svg("path")),K=F.appendChild(s.svg("path"));J.setAttribute("class","direction");J.setAttribute("pointer-events","all");J.setAttribute("d","M0,0L"+z+","+z+"A"+x+","+x+" 0 0,1 "+-z+","+z+"Z");K.setAttribute("class", +"chevron");K.setAttribute("d","M"+C+","+(A-C)+"L0,"+A+" "+-C+","+(A-C));K.setAttribute("pointer-events","none");F.addEventListener("mousedown",d,false);F.addEventListener("mouseover",f(v),false);F.addEventListener("mouseout",f(null),false);F.addEventListener("dblclick",r,false);return F}function m(v){var z=x*0.4,A=z/2,C=s.svg("g"),F=C.appendChild(s.svg("path")),J=C.appendChild(s.svg("path")),K=C.appendChild(s.svg("path")),P=C.appendChild(s.svg("path"));F.setAttribute("class","back");F.setAttribute("d", +"M"+-z+",0V"+-z+"A"+z+","+z+" 0 1,1 "+z+","+-z+"V0Z");J.setAttribute("class","direction");J.setAttribute("d",F.getAttribute("d"));K.setAttribute("class","chevron");K.setAttribute("d","M"+-A+","+-z+"H"+A+(v>0?"M0,"+(-z-A)+"V"+-A:""));P.setAttribute("class","fore");P.setAttribute("fill","none");P.setAttribute("d",F.getAttribute("d"));C.addEventListener("mousedown",h(v),false);C.addEventListener("mouseover",i,false);C.addEventListener("mouseout",j,false);C.addEventListener("dblclick",r,false);return C} +function o(v){var z=x*0.2,A=x*0.4,C=s.svg("g"),F=C.appendChild(s.svg("rect")),J=C.appendChild(s.svg("path"));F.setAttribute("pointer-events","all");F.setAttribute("fill","none");F.setAttribute("x",-A);F.setAttribute("y",-0.75*A);F.setAttribute("width",2*A);F.setAttribute("height",1.5*A);J.setAttribute("class","chevron");J.setAttribute("d","M"+-z+",0H"+z);C.addEventListener("mousedown",c(v),false);C.addEventListener("dblclick",r,false);return C}function g(){var v=x+6,z=v,A=E.size();switch(t){case "top-left":break; +case "top-right":v=A.x-v;break;case "bottom-left":z=A.y-z;break;case "bottom-right":v=A.x-v;z=A.y-z;break}n.setAttribute("transform","translate("+v+","+z+")");for(var C in w)C==E.zoom()?w[C].setAttribute("class","active"):w[C].removeAttribute("class")}function k(){for(;n.lastChild;)n.removeChild(n.lastChild);if(B!="none"){var v=n.appendChild(s.svg("g"));v.setAttribute("class","pan");var z=v.appendChild(s.svg("circle"));z.setAttribute("class","back");z.setAttribute("r",x);v.appendChild(u({x:0,y:-G})).setAttribute("transform", +"rotate(0)");v.appendChild(u({x:G,y:0})).setAttribute("transform","rotate(90)");v.appendChild(u({x:0,y:G})).setAttribute("transform","rotate(180)");v.appendChild(u({x:-G,y:0})).setAttribute("transform","rotate(270)");v=v.appendChild(s.svg("circle"));v.setAttribute("fill","none");v.setAttribute("class","fore");v.setAttribute("r",x)}if(y!="none"){v=n.appendChild(s.svg("g"));v.setAttribute("class","zoom");z=-0.5;if(y=="big"){w={};var A=E.zoomRange()[0];for(z=0;A<=E.zoomRange()[1];A++,z++)(w[A]=v.appendChild(o(A))).setAttribute("transform", +"translate(0,"+-(z+0.75)*x*0.4+")")}A=B=="none"?0.4:2;v.setAttribute("transform","translate(0,"+x*(/^top-/.test(t)?A+(z+0.5)*0.4:-A)+")");v.appendChild(m(+1)).setAttribute("transform","translate(0,"+-(z+0.5)*x*0.4+")");v.appendChild(m(-1)).setAttribute("transform","scale(-1)")}g()}var q={},n=s.svg("g"),w={},x=30,G=16,H=0,D=250,l=50,t="top-left",y="small",B="small",I,L,E;n.setAttribute("class","compass");q.radius=function(v){if(!arguments.length)return x;x=v;E&&k();return q};q.speed=function(v){if(!arguments.length)return x; +G=v;return q};q.position=function(v){if(!arguments.length)return t;t=v;E&&k();return q};q.pan=function(v){if(!arguments.length)return B;B=v;E&&k();return q};q.zoom=function(v){if(!arguments.length)return y;y=v;E&&k();return q};q.map=function(v){if(!arguments.length)return E;if(E){n.parentNode.removeChild(n);E.off("move",g).off("resize",g);window.removeEventListener("mouseup",e,false)}if(E=v){window.addEventListener("mouseup",e,false);E.on("move",g).on("resize",g);E.container().appendChild(n);k()}return q}; +return q};s.grid=function(){function d(){var h=f.firstChild,c=e.size(),i=e.pointLocation(S);e.pointLocation(c);var j=Math.pow(2,4-Math.round(e.zoom()));i.lat=Math.floor(i.lat/j)*j;i.lon=Math.ceil(i.lon/j)*j;for(var r;(r=e.locationPoint(i).x)<=c.x;i.lon+=j){h||(h=f.appendChild(s.svg("line")));h.setAttribute("x1",r);h.setAttribute("x2",r);h.setAttribute("y1",0);h.setAttribute("y2",c.y);h=h.nextSibling}for(;(r=e.locationPoint(i).y)<=c.y;i.lat-=j){h||(h=f.appendChild(s.svg("line")));h.setAttribute("y1", +r);h.setAttribute("y2",r);h.setAttribute("x1",0);h.setAttribute("x2",c.x);h=h.nextSibling}for(;h;){c=h.nextSibling;f.removeChild(h);h=c}}var a={},e,f=s.svg("g");f.setAttribute("class","grid");a.map=function(h){if(!arguments.length)return e;if(e){f.parentNode.removeChild(f);e.off("move",d).off("resize",d)}if(e=h){e.on("move",d).on("resize",d);e.container().appendChild(f);e.dispatch({type:"move"})}return a};return a}})(org.polymaps); diff --git a/src/Arrow.js b/src/Arrow.js index 7dacbfd..37fce88 100644 --- a/src/Arrow.js +++ b/src/Arrow.js @@ -1,6 +1,6 @@ po.arrow = function() { var arrow = {}, - key = {left: 0, right: 0, up: 0, down: 0, plus: 0, minus: 0}, + key = {left: 0, right: 0, up: 0, down: 0}, last = 0, repeatTimer, repeatDelay = 250, @@ -11,7 +11,7 @@ po.arrow = function() { function keydown(e) { if (e.ctrlKey || e.altKey || e.metaKey) return; - var now = Date.now(), dx = 0, dy = 0, dz = 0; + var now = Date.now(), dx = 0, dy = 0; switch (e.keyCode) { case 37: { if (!key.left) { @@ -45,30 +45,9 @@ po.arrow = function() { } break; } - case 109: case 189: { - if (!key.plus) { - last = now; - key.plus = 1; - if (!key.minus) dz = -1; - } - break; - } - case 61: case 187: { - if (!key.minus) { - last = now; - key.minus = 1; - if (!key.plus) dz = 1; - } - break; - } default: return; } - if (dz) { - var z = map.zoom(); - map.zoom(dz < 0 ? Math.ceil(z) - 1 : Math.floor(z) + 1); - } else if (dx || dy) { - map.panBy({x: dx, y: dy}); - } + if (dx || dy) map.panBy({x: dx, y: dy}); if (!repeatTimer && (key.left | key.right | key.up | key.down)) { repeatTimer = setInterval(repeat, repeatInterval); } @@ -82,8 +61,6 @@ po.arrow = function() { case 39: key.right = 0; break; case 38: key.up = 0; break; case 40: key.down = 0; break; - case 109: case 189: key.plus = 0; break; - case 61: case 187: key.minus = 0; break; default: return; } if (repeatTimer && !(key.left | key.right | key.up | key.down)) { @@ -92,6 +69,15 @@ po.arrow = function() { e.preventDefault(); } + function keypress(e) { + switch (e.charCode) { + case 45: case 95: map.zoom(Math.ceil(map.zoom()) - 1); break; // - _ + case 43: case 61: map.zoom(Math.floor(map.zoom()) + 1); break; // = + + default: return; + } + e.preventDefault(); + } + function repeat() { if (!map) return; if (Date.now() < last + repeatDelay) return; @@ -103,12 +89,14 @@ po.arrow = function() { arrow.map = function(x) { if (!arguments.length) return map; if (map) { + parent.removeEventListener("keypress", keypress, false); parent.removeEventListener("keydown", keydown, false); parent.removeEventListener("keyup", keyup, false); parent = null; } if (map = x) { parent = map.focusableParent(); + parent.addEventListener("keypress", keypress, false); parent.addEventListener("keydown", keydown, false); parent.addEventListener("keyup", keyup, false); } diff --git a/src/start.js b/src/start.js index 1dfc3bf..1d468a2 100644 --- a/src/start.js +++ b/src/start.js @@ -2,6 +2,6 @@ if (!org) var org = {}; if (!org.polymaps) org.polymaps = {}; (function(po){ - po.version = "2.0.2+6"; // This fork not semver! + po.version = "2.0.3+1"; // This fork not semver! var zero = {x: 0, y: 0};