From 4195e57e2e33fbab3a0614b0f80828577ba047c1 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 23 Sep 2010 09:27:03 -0700 Subject: [PATCH 1/2] Fix a bug with default geoJson settings. The default URL for geoJson layers was "about:blank"; this causes a security exception when issuing an XMLHttpRequest from another domain. The new default URL is null, which avoids any XMLHttpRequest and just creates blank tiles. In addition, setting the features property to a non-null value has the side-effect of setting the URL to null and vice versa. For consistency, the default URL for image layers is now also null, which causes no image to be loaded. This commit also fixes a bug when the URL is a string with no placeholders, allowing simple repeating image tiles to be created. --- polymaps.js | 23 +++++++------ polymaps.min.js | 88 ++++++++++++++++++++++++------------------------- src/GeoJson.js | 15 +++++---- src/Image.js | 6 ++-- src/start.js | 2 +- 5 files changed, 70 insertions(+), 64 deletions(-) diff --git a/polymaps.js b/polymaps.js index f110106..12e7e6d 100644 --- a/polymaps.js +++ b/polymaps.js @@ -2,7 +2,7 @@ if (!org) var org = {}; if (!org.polymaps) org.polymaps = {}; (function(po){ - po.version = "2.2+1.0+1"; // This fork not semver! + po.version = "2.2+1.0+2"; // This fork not semver! var zero = {x: 0, y: 0}; po.ns = { @@ -1089,16 +1089,16 @@ function scanTriangle(a, b, c, ymin, ymax, scanLine) { } po.image = function() { var image = po.layer(load, unload), - url = "about:blank"; + url; function load(tile) { var element = tile.element = po.svg("image"), size = image.map().tileSize(); element.setAttribute("preserveAspectRatio", "none"); element.setAttribute("width", size.x); element.setAttribute("height", size.y); - element.setAttribute("opacity", 0); if (typeof url == "function") { + element.setAttribute("opacity", 0); tile.request = po.queue.image(element, url(tile), function(img) { delete tile.request; tile.ready = true; @@ -1108,7 +1108,7 @@ po.image = function() { }); } else { tile.ready = true; - element.setAttributeNS(po.ns.xlink, "href", url); + if (url) element.setAttributeNS(po.ns.xlink, "href", url); image.dispatch({type: "load", tile: tile}); } } @@ -1128,7 +1128,7 @@ po.image = function() { po.geoJson = function(fetch) { var geoJson = po.layer(load, unload), container = geoJson.container(), - url = "about:blank", + url, clip = true, clipId = "org.polymaps." + po.id(), clipHref = "url(#" + clipId + ")", @@ -1274,10 +1274,10 @@ po.geoJson = function(fetch) { geoJson.dispatch({type: "load", tile: tile, features: updated}); } - if (features) { - update({type: "FeatureCollection", features: features}); - } else { + if (url != null) { tile.request = fetch(typeof url == "function" ? url(tile) : url, update); + } else { + update({type: "FeatureCollection", features: features || []}); } } @@ -1331,14 +1331,17 @@ po.geoJson = function(fetch) { geoJson.url = function(x) { if (!arguments.length) return url; url = typeof x == "string" && /{.}/.test(x) ? po.url(x) : x; + if (url != null) features = null; if (typeof url == "string") geoJson.tile(false); return geoJson.reload(); }; geoJson.features = function(x) { if (!arguments.length) return features; - if (x) geoJson.tile(false); - features = x; + if (features = x) { + url = null; + geoJson.tile(false); + } return geoJson.reload(); }; diff --git a/polymaps.min.js b/polymaps.min.js index ba8ecfb..c6b693d 100644 --- a/polymaps.min.js +++ b/polymaps.min.js @@ -1,60 +1,60 @@ if(!org)var org={};if(!org.polymaps)org.polymaps={}; (function(r){function fa(d){var f=d.indexOf(":");return f<0?d:{space:r.ns[d.substring(0,f)],local:d.substring(f+1)}}function R(){for(var d=0;df.row){var a=d;d=f;f=a}return{x0:d.column,y0:d.row,x1:f.column,y1:f.row,dx:f.column-d.column,dy:f.row-d.row}}function ca(d,f,a,j,h){a=Math.max(a,Math.floor(f.y0)); -j=Math.min(j,Math.ceil(f.y1));if(d.x0==f.x0&&d.y0==f.y0?d.x0+f.dy/d.dy*d.dx0,k=f.dx<0;for(a=a;af.dy){a=e;e=f;f=a}if(e.dy>d.dy){a=e;e=d;d=a}if(f.dy>d.dy){a=f;f=d;d=a}e.dy&&ca(d,e,j,h,c);f.dy&&ca(d,f,j,h,c)}r.version="2.2+1.0+1"; -var X={x:0,y:0};r.ns={svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"};r.id=function(){var d=0;return function(){return++d}}();r.svg=function(d){return document.createElementNS(r.ns.svg,d)};r.transform=function(d,f,a,j,h,c){var e={},o,k,q;if(!arguments.length){d=1;f=h=a=0;j=1;c=0}e.zoomFraction=function(m){if(!arguments.length)return k;k=m;o=Math.floor(k+Math.log(Math.sqrt(d*d+f*f+a*a+j*j))/Math.log(2));q=Math.pow(2,-o);return e};e.apply=function(m){var i=Math.pow(2,-m.zoom), -s=Math.pow(2,m.zoom-o);return{column:(d*m.column*i+a*m.row*i+h)*s,row:(f*m.column*i+j*m.row*i+c)*s,zoom:m.zoom-o}};e.unapply=function(m){var i=Math.pow(2,-m.zoom),s=Math.pow(2,m.zoom+o);return{column:(m.column*i*j-m.row*i*a-h*j+c*a)/(d*j-f*a)*s,row:(m.column*i*f-m.row*i*d-h*f+c*d)/(a*f-j*d)*s,zoom:m.zoom+o}};e.toString=function(){return"matrix("+[d*q,f*q,a*q,j*q].join(" ")+" 0 0)"};return e.zoomFraction(0)};r.cache=function(d,f){function a(i){m--;f&&f(i);delete e[i.key];if(i.next)i.next.prev=i.prev; -else if(k=i.prev)k.next=null;if(i.prev)i.prev.next=i.next;else if(o=i.next)o.prev=null}function j(){for(var i=k;m>q;i=i.prev){if(!i)break;i.lock||a(i)}}var h={},c={},e={},o=null,k=null,q=64,m=0;h.peek=function(i){return e[[i.zoom,i.column,i.row].join("/")]};h.load=function(i,s){var u=[i.zoom,i.column,i.row].join("/"),y=e[u];if(y){if(y.prev){if(y.prev.next=y.next)y.next.prev=y.prev;else k=y.prev;y.prev=null;y.next=o;o=o.prev=y}y.lock=1;return c[u]=y}y={key:u,column:i.column,row:i.row,zoom:i.zoom,next:o, -prev:null,lock:1};d.call(null,y,s);c[u]=e[u]=y;if(o)o.prev=y;else k=y;o=y;m++;return y};h.unload=function(i){if(!(i in c))return false;var s=c[i];s.lock=0;delete c[i];s.request&&s.request.abort(false)&&a(s);return s};h.locks=function(){return c};h.size=function(i){if(!arguments.length)return q;q=i;j();return h};h.flush=function(){j();return h};h.clear=function(){for(var i in e){var s=e[i];s.request&&s.request.abort(false);f&&f(e[i]);if(s.lock){s.lock=0;s.element.parentNode.removeChild(s.element)}}c= -{};e={};o=k=null;m=0;return h};return h};r.url=function(d){function f(j){var h=j.zoom<0?1:1<=c||!j.length)){h++;j.pop()()}}function f(e){for(var o=0;os[1])q=s[1];m=q-(q=Math.round(q));i=Math.pow(2,m)}function f(){if(x){var g=45/Math.pow(2,q+m-3),p=Math.max(Math.abs(K*e.x+y*e.y),Math.abs(F*e.x+w*e.y)),n=V(B-p*g/o.y);p=V(D+p*g/o.y);k.lat=Math.max(n,Math.min(p,k.lat));n=Math.max(Math.abs(K*e.y+y*e.x),Math.abs(F*e.y+w*e.x));k.lon=Math.max(x[0].lon-n*g/o.x,Math.min(x[1].lon+ -n*g/o.x,k.lon))}}var a={},j,h,c=X,e=X,o={x:256,y:256},k={lat:37.76487,lon:-122.41948},q=12,m=0,i=1,s=[1,18],u=0,y=1,K=0,w=1,F=0,B=-180,D=180,x=[{lat:V(B),lon:-Infinity},{lat:V(D),lon:Infinity}];a.locationCoordinate=function(g){g=r.map.locationCoordinate(g);var p=Math.pow(2,q);g.column*=p;g.row*=p;g.zoom+=q;return g};a.coordinateLocation=r.map.coordinateLocation;a.coordinatePoint=function(g,p){var n=Math.pow(2,q-p.zoom),v=Math.pow(2,q-g.zoom),A=(p.column*n-g.column*v)*o.x*i;n=(p.row*n-g.row*v)*o.y* -i;return{x:e.x+y*A-K*n,y:e.y+K*A+y*n}};a.pointCoordinate=function(g,p){var n=Math.pow(2,q-g.zoom),v=(p.x-e.x)/i,A=(p.y-e.y)/i;return{column:g.column*n+(w*v-F*A)/o.x,row:g.row*n+(F*v+w*A)/o.y,zoom:q}};a.locationPoint=function(g){var p=Math.pow(2,q+m-3)/45,n=(g.lon-k.lon)*p*o.x;g=(W(k.lat)-W(g.lat))*p*o.y;return{x:e.x+y*n-K*g,y:e.y+K*n+y*g}};a.pointLocation=function(g){var p=45/Math.pow(2,q+m-3),n=(g.x-e.x)*p;g=(g.y-e.y)*p;return{lon:k.lon+(w*n-F*g)/o.x,lat:V(W(k.lat)-(F*n+w*g)/o.y)}};var l=r.svg("rect"); -l.setAttribute("visibility","hidden");l.setAttribute("pointer-events","all");a.container=function(g){if(!arguments.length)return j;j=g;j.setAttribute("class","map");j.appendChild(l);return a.resize()};a.focusableParent=function(){for(var g=j;g;g=g.parentNode)if(g.tabIndex>=0)return g;return window};a.mouse=function(g){var p=(j.ownerSVGElement||j).createSVGPoint();if(Z<0&&(window.scrollX||window.scrollY)){var n=document.body.appendChild(r.svg("svg"));n.style.position="absolute";n.style.top=n.style.left= -"0px";var v=n.getScreenCTM();Z=!(v.f||v.e);document.body.removeChild(n)}if(Z){p.x=g.pageX;p.y=g.pageY}else{p.x=g.clientX;p.y=g.clientY}return p.matrixTransform(j.getScreenCTM().inverse())};a.size=function(g){if(!arguments.length)return c;h=g;return a.resize()};a.resize=function(){if(h){c=h;R.remove(a)}else{l.setAttribute("width","100%");l.setAttribute("height","100%");b=l.getBBox();c={x:b.width,y:b.height};R.add(a)}l.setAttribute("width",c.x);l.setAttribute("height",c.y);e={x:c.x/2,y:c.y/2};f();a.dispatch({type:"resize"}); -return a};a.tileSize=function(g){if(!arguments.length)return o;o=g;a.dispatch({type:"move"});return a};a.center=function(g){if(!arguments.length)return k;k=g;f();a.dispatch({type:"move"});return a};a.panBy=function(g){var p=45/Math.pow(2,q+m-3),n=g.x*p;g=g.y*p;return a.center({lon:k.lon+(F*g-w*n)/o.x,lat:V(W(k.lat)+(F*n+w*g)/o.y)})};a.centerRange=function(g){if(!arguments.length)return x;if(x=g){B=x[0].lat>-90?W(x[0].lat):-Infinity;D=x[0].lat<90?W(x[1].lat):Infinity}else{B=-Infinity;D=Infinity}f(); -a.dispatch({type:"move"});return a};a.zoom=function(g){if(!arguments.length)return q+m;q=g;d();return a.center(k)};a.zoomBy=function(g,p,n){if(arguments.length<2)return a.zoom(q+m+g);if(arguments.length<3)n=a.pointLocation(p);q=q+m+g;d();var v=a.locationPoint(n);return a.panBy({x:p.x-v.x,y:p.y-v.y})};a.zoomRange=function(g){if(!arguments.length)return s;s=g;return a.zoom(q+m)};a.extent=function(g){if(!arguments.length)return[a.pointLocation({x:0,y:c.y}),a.pointLocation({x:c.x,y:0})];var p=a.locationPoint(g[0]), -n=a.locationPoint(g[1]),v=Math.max((n.x-p.x)/c.x,(p.y-n.y)/c.y);p=a.pointLocation({x:(p.x+n.x)/2,y:(p.y+n.y)/2});q=q+m-Math.log(v)/Math.log(2);d();return a.center(p)};a.angle=function(g){if(!arguments.length)return u;u=g;y=Math.cos(u);K=Math.sin(u);w=Math.cos(-u);F=Math.sin(-u);f();a.dispatch({type:"move"});return a};a.add=function(g){g.map(a);return a};a.remove=function(g){g.map(null);return a};a.dispatch=r.dispatch(a);return a};R.maps=[];R.add=function(d){for(var f=0;f0,k=f.dx<0;for(a=a;af.dy){a=e;e=f;f=a}if(e.dy>d.dy){a=e;e=d;d=a}if(f.dy>d.dy){a=f;f=d;d=a}e.dy&&ca(d,e,j,h,c);f.dy&&ca(d,f,j,h,c)}r.version="2.2+1.0+2"; +var X={x:0,y:0};r.ns={svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"};r.id=function(){var d=0;return function(){return++d}}();r.svg=function(d){return document.createElementNS(r.ns.svg,d)};r.transform=function(d,f,a,j,h,c){var e={},o,k,q;if(!arguments.length){d=1;f=h=a=0;j=1;c=0}e.zoomFraction=function(l){if(!arguments.length)return k;k=l;o=Math.floor(k+Math.log(Math.sqrt(d*d+f*f+a*a+j*j))/Math.log(2));q=Math.pow(2,-o);return e};e.apply=function(l){var i=Math.pow(2,-l.zoom), +s=Math.pow(2,l.zoom-o);return{column:(d*l.column*i+a*l.row*i+h)*s,row:(f*l.column*i+j*l.row*i+c)*s,zoom:l.zoom-o}};e.unapply=function(l){var i=Math.pow(2,-l.zoom),s=Math.pow(2,l.zoom+o);return{column:(l.column*i*j-l.row*i*a-h*j+c*a)/(d*j-f*a)*s,row:(l.column*i*f-l.row*i*d-h*f+c*d)/(a*f-j*d)*s,zoom:l.zoom+o}};e.toString=function(){return"matrix("+[d*q,f*q,a*q,j*q].join(" ")+" 0 0)"};return e.zoomFraction(0)};r.cache=function(d,f){function a(i){l--;f&&f(i);delete e[i.key];if(i.next)i.next.prev=i.prev; +else if(k=i.prev)k.next=null;if(i.prev)i.prev.next=i.next;else if(o=i.next)o.prev=null}function j(){for(var i=k;l>q;i=i.prev){if(!i)break;i.lock||a(i)}}var h={},c={},e={},o=null,k=null,q=64,l=0;h.peek=function(i){return e[[i.zoom,i.column,i.row].join("/")]};h.load=function(i,s){var u=[i.zoom,i.column,i.row].join("/"),y=e[u];if(y){if(y.prev){if(y.prev.next=y.next)y.next.prev=y.prev;else k=y.prev;y.prev=null;y.next=o;o=o.prev=y}y.lock=1;return c[u]=y}y={key:u,column:i.column,row:i.row,zoom:i.zoom,next:o, +prev:null,lock:1};d.call(null,y,s);c[u]=e[u]=y;if(o)o.prev=y;else k=y;o=y;l++;return y};h.unload=function(i){if(!(i in c))return false;var s=c[i];s.lock=0;delete c[i];s.request&&s.request.abort(false)&&a(s);return s};h.locks=function(){return c};h.size=function(i){if(!arguments.length)return q;q=i;j();return h};h.flush=function(){j();return h};h.clear=function(){for(var i in e){var s=e[i];s.request&&s.request.abort(false);f&&f(e[i]);if(s.lock){s.lock=0;s.element.parentNode.removeChild(s.element)}}c= +{};e={};o=k=null;l=0;return h};return h};r.url=function(d){function f(j){var h=j.zoom<0?1:1<=c||!j.length)){h++;j.pop()()}}function f(e){for(var o=0;os[1])q=s[1];l=q-(q=Math.round(q));i=Math.pow(2,l)}function f(){if(x){var g=45/Math.pow(2,q+l-3),p=Math.max(Math.abs(K*e.x+y*e.y),Math.abs(F*e.x+w*e.y)),n=V(B-p*g/o.y);p=V(D+p*g/o.y);k.lat=Math.max(n,Math.min(p,k.lat));n=Math.max(Math.abs(K*e.y+y*e.x),Math.abs(F*e.y+w*e.x));k.lon=Math.max(x[0].lon-n*g/o.x,Math.min(x[1].lon+ +n*g/o.x,k.lon))}}var a={},j,h,c=X,e=X,o={x:256,y:256},k={lat:37.76487,lon:-122.41948},q=12,l=0,i=1,s=[1,18],u=0,y=1,K=0,w=1,F=0,B=-180,D=180,x=[{lat:V(B),lon:-Infinity},{lat:V(D),lon:Infinity}];a.locationCoordinate=function(g){g=r.map.locationCoordinate(g);var p=Math.pow(2,q);g.column*=p;g.row*=p;g.zoom+=q;return g};a.coordinateLocation=r.map.coordinateLocation;a.coordinatePoint=function(g,p){var n=Math.pow(2,q-p.zoom),v=Math.pow(2,q-g.zoom),A=(p.column*n-g.column*v)*o.x*i;n=(p.row*n-g.row*v)*o.y* +i;return{x:e.x+y*A-K*n,y:e.y+K*A+y*n}};a.pointCoordinate=function(g,p){var n=Math.pow(2,q-g.zoom),v=(p.x-e.x)/i,A=(p.y-e.y)/i;return{column:g.column*n+(w*v-F*A)/o.x,row:g.row*n+(F*v+w*A)/o.y,zoom:q}};a.locationPoint=function(g){var p=Math.pow(2,q+l-3)/45,n=(g.lon-k.lon)*p*o.x;g=(W(k.lat)-W(g.lat))*p*o.y;return{x:e.x+y*n-K*g,y:e.y+K*n+y*g}};a.pointLocation=function(g){var p=45/Math.pow(2,q+l-3),n=(g.x-e.x)*p;g=(g.y-e.y)*p;return{lon:k.lon+(w*n-F*g)/o.x,lat:V(W(k.lat)-(F*n+w*g)/o.y)}};var m=r.svg("rect"); +m.setAttribute("visibility","hidden");m.setAttribute("pointer-events","all");a.container=function(g){if(!arguments.length)return j;j=g;j.setAttribute("class","map");j.appendChild(m);return a.resize()};a.focusableParent=function(){for(var g=j;g;g=g.parentNode)if(g.tabIndex>=0)return g;return window};a.mouse=function(g){var p=(j.ownerSVGElement||j).createSVGPoint();if(Z<0&&(window.scrollX||window.scrollY)){var n=document.body.appendChild(r.svg("svg"));n.style.position="absolute";n.style.top=n.style.left= +"0px";var v=n.getScreenCTM();Z=!(v.f||v.e);document.body.removeChild(n)}if(Z){p.x=g.pageX;p.y=g.pageY}else{p.x=g.clientX;p.y=g.clientY}return p.matrixTransform(j.getScreenCTM().inverse())};a.size=function(g){if(!arguments.length)return c;h=g;return a.resize()};a.resize=function(){if(h){c=h;R.remove(a)}else{m.setAttribute("width","100%");m.setAttribute("height","100%");b=m.getBBox();c={x:b.width,y:b.height};R.add(a)}m.setAttribute("width",c.x);m.setAttribute("height",c.y);e={x:c.x/2,y:c.y/2};f();a.dispatch({type:"resize"}); +return a};a.tileSize=function(g){if(!arguments.length)return o;o=g;a.dispatch({type:"move"});return a};a.center=function(g){if(!arguments.length)return k;k=g;f();a.dispatch({type:"move"});return a};a.panBy=function(g){var p=45/Math.pow(2,q+l-3),n=g.x*p;g=g.y*p;return a.center({lon:k.lon+(F*g-w*n)/o.x,lat:V(W(k.lat)+(F*n+w*g)/o.y)})};a.centerRange=function(g){if(!arguments.length)return x;if(x=g){B=x[0].lat>-90?W(x[0].lat):-Infinity;D=x[0].lat<90?W(x[1].lat):Infinity}else{B=-Infinity;D=Infinity}f(); +a.dispatch({type:"move"});return a};a.zoom=function(g){if(!arguments.length)return q+l;q=g;d();return a.center(k)};a.zoomBy=function(g,p,n){if(arguments.length<2)return a.zoom(q+l+g);if(arguments.length<3)n=a.pointLocation(p);q=q+l+g;d();var v=a.locationPoint(n);return a.panBy({x:p.x-v.x,y:p.y-v.y})};a.zoomRange=function(g){if(!arguments.length)return s;s=g;return a.zoom(q+l)};a.extent=function(g){if(!arguments.length)return[a.pointLocation({x:0,y:c.y}),a.pointLocation({x:c.x,y:0})];var p=a.locationPoint(g[0]), +n=a.locationPoint(g[1]),v=Math.max((n.x-p.x)/c.x,(p.y-n.y)/c.y);p=a.pointLocation({x:(p.x+n.x)/2,y:(p.y+n.y)/2});q=q+l-Math.log(v)/Math.log(2);d();return a.center(p)};a.angle=function(g){if(!arguments.length)return u;u=g;y=Math.cos(u);K=Math.sin(u);w=Math.cos(-u);F=Math.sin(-u);f();a.dispatch({type:"move"});return a};a.add=function(g){g.map(a);return a};a.remove=function(g){g.map(null);return a};a.dispatch=r.dispatch(a);return a};R.maps=[];R.add=function(d){for(var f=0;fB;K--){s.insertBefore(w[-1],D);s.insertBefore(w[2],w[-4]);for(var x=w[2],l=2;l>-4;)w[l]=w[--l];w[l]=x}}function h(){function B(E){var T=E.zoom,U=T<0?1:1<B;K--){s.insertBefore(w[-1],D);s.insertBefore(w[2],w[-4]);for(var x=w[2],m=2;m>-4;)w[m]=w[--m];w[m]=x}}function h(){function B(E){var T=E.zoom,U=T<0?1:1<>Q,row:U>>Q,zoom:t-Q}))&&O.ready){J[O.key]=e.load(M);O.proxyCount++;G.proxyRefs[O.key]=O;break}}J[G.key]=G}} -var x=c.map(),l=x.zoom(),g=l-(l=Math.round(l)),p=x.size(),n=x.angle(),v=x.tileSize(),A=x.locationCoordinate(x.center());if(K!=l){if(Kl)j(l);else K=l;for(var z=-4;z<=2;z++){var I=w[z];I.setAttribute("class","zoom"+(z<0?"":"+")+z+" zoom"+(l+z));I.setAttribute("transform","scale("+Math.pow(2,-z)+")")}}s.setAttribute("transform","translate("+p.x/2+","+p.y/2+")"+(n?"rotate("+n/Math.PI*180+")":"")+(g?"scale("+Math.pow(2,g)+")":"")+(u?u.zoomFraction(g):""));var H=x.pointCoordinate(A,X); +var x=c.map(),m=x.zoom(),g=m-(m=Math.round(m)),p=x.size(),n=x.angle(),v=x.tileSize(),A=x.locationCoordinate(x.center());if(K!=m){if(Km)j(m);else K=m;for(var z=-4;z<=2;z++){var I=w[z];I.setAttribute("class","zoom"+(z<0?"":"+")+z+" zoom"+(m+z));I.setAttribute("transform","scale("+Math.pow(2,-z)+")")}}s.setAttribute("transform","translate("+p.x/2+","+p.y/2+")"+(n?"rotate("+n/Math.PI*180+")":"")+(g?"scale("+Math.pow(2,g)+")":"")+(u?u.zoomFraction(g):""));var H=x.pointCoordinate(A,X); z=x.pointCoordinate(A,{x:p.x,y:0});I=x.pointCoordinate(A,p);x=x.pointCoordinate(A,{x:0,y:p.y});if(!g&&!n&&!u){A.column=(Math.round(v.x*A.column)+(p.x&1)/2)/v.x;A.row=(Math.round(v.y*A.row)+(p.y&1)/2)/v.y}if(u){H=u.unapply(H);z=u.unapply(z);I=u.unapply(I);x=u.unapply(x);A=u.unapply(A)}var N=q?q(H.zoom)-H.zoom:0;if(N){n=Math.pow(2,N);H.column*=n;H.row*=n;z.column*=n;z.row*=n;I.column*=n;I.row*=n;x.column*=n;x.row*=n;H.zoom=z.zoom=I.zoom=x.zoom+=N}p=e.locks();var J={};for(var P in p)p[P].proxyCount= 0;if(k&&N>-5&&N<3){n=H.zoom<0?1:1<>z<>z<=1;F--)w[F]=s.appendChild(r.svg("g"));w[0]=s.appendChild(r.svg("g"));c.map=function(B){if(!arguments.length)return i;if(i){if(i==B){s.parentNode.appendChild(s);return c}i.off("move", -h).off("resize",h);s.parentNode.removeChild(s)}if(i=B){i.container().appendChild(s);c.init&&c.init(s);i.on("move",h).on("resize",h);h()}return c};c.container=function(){return s};c.id=function(B){if(!arguments.length)return m;m=B;s.setAttribute("id",B);return c};c.visible=function(B){if(!arguments.length)return k;(k=B)?s.removeAttribute("visibility"):s.setAttribute("visibility","hidden");i&&h();return c};c.transform=function(B){if(!arguments.length)return u;u=B;i&&h();return c};c.zoom=function(B){if(!arguments.length)return q; +J[P];if(z.element.parentNode!=w[z.level]){w[z.level].appendChild(z.element);c.show&&c.show(z)}}e.flush();m+=g;if(y!=m){y=m;c.dispatch({type:"zoom"})}}var c={},e=c.cache=r.cache(d,f).size(512),o=true,k=true,q,l,i,s=r.svg("g"),u,y,K,w={};s.setAttribute("class","layer");for(var F=-4;F<=-1;F++)w[F]=s.appendChild(r.svg("g"));for(F=2;F>=1;F--)w[F]=s.appendChild(r.svg("g"));w[0]=s.appendChild(r.svg("g"));c.map=function(B){if(!arguments.length)return i;if(i){if(i==B){s.parentNode.appendChild(s);return c}i.off("move", +h).off("resize",h);s.parentNode.removeChild(s)}if(i=B){i.container().appendChild(s);c.init&&c.init(s);i.on("move",h).on("resize",h);h()}return c};c.container=function(){return s};c.id=function(B){if(!arguments.length)return l;l=B;s.setAttribute("id",B);return c};c.visible=function(B){if(!arguments.length)return k;(k=B)?s.removeAttribute("visibility"):s.setAttribute("visibility","hidden");i&&h();return c};c.transform=function(B){if(!arguments.length)return u;u=B;i&&h();return c};c.zoom=function(B){if(!arguments.length)return q; q=typeof B=="function"||B==null?B:function(){return B};i&&h();return c};c.tile=function(B){if(!arguments.length)return o;o=B;i&&h();return c};c.reload=function(){e.clear();i&&h();return c};c.dispatch=r.dispatch(c);c.on("load",function(B){if(B.tile.proxyRefs){for(var D in B.tile.proxyRefs){var x=B.tile.proxyRefs[D];--x.proxyCount<=0&&e.unload(D)&&x.element.parentNode.removeChild(x.element)}delete B.tile.proxyRefs}});return c};r.image=function(){var d=r.layer(function(a){var j=a.element=r.svg("image"), -h=d.map().tileSize();j.setAttribute("preserveAspectRatio","none");j.setAttribute("width",h.x);j.setAttribute("height",h.y);j.setAttribute("opacity",0);if(typeof f=="function")a.request=r.queue.image(j,f(a),function(c){delete a.request;a.ready=true;a.img=c;j.removeAttribute("opacity");d.dispatch({type:"load",tile:a})});else{a.ready=true;j.setAttributeNS(r.ns.xlink,"href",f);d.dispatch({type:"load",tile:a})}},function(a){a.request&&a.request.abort(true)}),f="about:blank";d.url=function(a){if(!arguments.length)return f; -f=typeof a=="string"&&/{.}/.test(a)?r.url(a):a;return d.reload()};return d};r.geoJson=function(d){function f(l){var g={lat:0,lon:0};return function(p){g.lat=p[1];g.lon=p[0];var n=l(g);p.x=n.x;p.y=n.y;return n}}function a(l,g){return l&&l.type in B&&B[l.type](l,g)}function j(l,g){var p=g(l),n=r.svg("circle");n.setAttribute("r",4.5);n.setAttribute("transform","translate("+p.x+","+p.y+")");return n}function h(l,g,p,n){n.push("M");for(var v=0;v9&&Math.abs(m.wheelDelta)/u>=50)ba=1;h=s}if(ba==1)i*=0.03;if(!c&&i){s= -Date.now();if(s-j>200){i=i>0?+1:-1;j=s}else i=0}if(i)switch(e){case "mouse":s=k.mouse(m);o||(o=k.pointLocation(s));k.off("move",d).zoomBy(i,s,o).on("move",d);break;case "location":k.zoomBy(i,k.locationPoint(o),o);break;default:k.zoomBy(i);break}m.preventDefault();return false}var a={},j=0,h=0,c=true,e="mouse",o,k,q;a.smooth=function(m){if(!arguments.length)return c;c=m;return a};a.zoom=function(m,i){if(!arguments.length)return e;e=m;o=i;if(k)e=="mouse"?k.on("move",d):k.off("move",d);return a};a.map= -function(m){if(!arguments.length)return k;if(k){q.removeEventListener("mousemove",d,false);q.removeEventListener("mousewheel",f,false);q.removeEventListener("DOMMouseScroll",f,false);q=null;k.off("move",d)}if(k=m){e=="mouse"&&k.on("move",d);q=k.container();q.addEventListener("mousemove",d,false);q.addEventListener("mousewheel",f,false);q.addEventListener("DOMMouseScroll",f,false)}return a};return a};var ba=/WebKit\/533/.test(navigator.userAgent)?-1:0;r.arrow=function(){function d(u){if(!(u.ctrlKey|| -u.altKey||u.metaKey)){var y=Date.now(),K=0,w=0;switch(u.keyCode){case 37:if(!c.left){e=y;c.left=1;c.right||(K=m)}break;case 39:if(!c.right){e=y;c.right=1;c.left||(K=-m)}break;case 38:if(!c.up){e=y;c.up=1;c.down||(w=m)}break;case 40:if(!c.down){e=y;c.down=1;c.up||(w=-m)}break;default:return}if(K||w)i.panBy({x:K,y:w});if(!o&&c.left|c.right|c.up|c.down)o=setInterval(j,q);u.preventDefault()}}function f(u){e=Date.now();switch(u.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(o&&!(c.left|c.right|c.up|c.down))o=clearInterval(o);u.preventDefault()}function a(u){switch(u.charCode){case 45:case 95:i.zoom(Math.ceil(i.zoom())-1);break;case 43:case 61:i.zoom(Math.floor(i.zoom())+1);break;default:return}u.preventDefault()}function j(){if(i)if(!(Date.now()9&&Math.abs(l.wheelDelta)/u>=50)ba=1;h=s}if(ba==1)i*=0.03;if(!c&&i){s= +Date.now();if(s-j>200){i=i>0?+1:-1;j=s}else i=0}if(i)switch(e){case "mouse":s=k.mouse(l);o||(o=k.pointLocation(s));k.off("move",d).zoomBy(i,s,o).on("move",d);break;case "location":k.zoomBy(i,k.locationPoint(o),o);break;default:k.zoomBy(i);break}l.preventDefault();return false}var a={},j=0,h=0,c=true,e="mouse",o,k,q;a.smooth=function(l){if(!arguments.length)return c;c=l;return a};a.zoom=function(l,i){if(!arguments.length)return e;e=l;o=i;if(k)e=="mouse"?k.on("move",d):k.off("move",d);return a};a.map= +function(l){if(!arguments.length)return k;if(k){q.removeEventListener("mousemove",d,false);q.removeEventListener("mousewheel",f,false);q.removeEventListener("DOMMouseScroll",f,false);q=null;k.off("move",d)}if(k=l){e=="mouse"&&k.on("move",d);q=k.container();q.addEventListener("mousemove",d,false);q.addEventListener("mousewheel",f,false);q.addEventListener("DOMMouseScroll",f,false)}return a};return a};var ba=/WebKit\/533/.test(navigator.userAgent)?-1:0;r.arrow=function(){function d(u){if(!(u.ctrlKey|| +u.altKey||u.metaKey)){var y=Date.now(),K=0,w=0;switch(u.keyCode){case 37:if(!c.left){e=y;c.left=1;c.right||(K=l)}break;case 39:if(!c.right){e=y;c.right=1;c.left||(K=-l)}break;case 38:if(!c.up){e=y;c.up=1;c.down||(w=l)}break;case 40:if(!c.down){e=y;c.down=1;c.up||(w=-l)}break;default:return}if(K||w)i.panBy({x:K,y:w});if(!o&&c.left|c.right|c.up|c.down)o=setInterval(j,q);u.preventDefault()}}function f(u){e=Date.now();switch(u.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(o&&!(c.left|c.right|c.up|c.down))o=clearInterval(o);u.preventDefault()}function a(u){switch(u.charCode){case 45:case 95:i.zoom(Math.ceil(i.zoom())-1);break;case 43:case 61:i.zoom(Math.floor(i.zoom())+1);break;default:return}u.preventDefault()}function j(){if(i)if(!(Date.now()l+g&&E.panBy(H)}function a(t){if(t.shiftKey){J={x0:E.mouse(t)};E.focusableParent().focus();return m(t)}}function j(t){if(J){J.x1=E.mouse(t); +location.hash?f():d()}return a};return a};r.interact=function(){var d={},f=r.drag(),a=r.wheel(),j=r.dblclick(),h=r.arrow();d.map=function(c){f.map(c);a.map(c);j.map(c);h.map(c);return d};return d};r.compass=function(){function d(t){F.setAttribute("class","compass active");I||(I=setInterval(f,p));H&&E.panBy(H);m=Date.now();return l(t)}function f(){H&&Date.now()>m+g&&E.panBy(H)}function a(t){if(t.shiftKey){J={x0:E.mouse(t)};E.focusableParent().focus();return l(t)}}function j(t){if(J){J.x1=E.mouse(t); P.setAttribute("x",Math.min(J.x0.x,J.x1.x));P.setAttribute("y",Math.min(J.x0.y,J.x1.y));P.setAttribute("width",Math.abs(J.x0.x-J.x1.x));P.setAttribute("height",Math.abs(J.x0.y-J.x1.y));P.removeAttribute("display")}}function h(){F.setAttribute("class","compass");if(J){if(J.x1){E.extent([E.pointLocation({x:Math.min(J.x0.x,J.x1.x),y:Math.max(J.x0.y,J.x1.y)}),E.pointLocation({x:Math.max(J.x0.x,J.x1.x),y:Math.min(J.x0.y,J.x1.y)})]);P.setAttribute("display","none")}J=null}if(I){clearInterval(I);I=0}}function c(t){return function(){t? -this.setAttribute("class","active"):this.removeAttribute("class");H=t}}function e(t){return function(C){F.setAttribute("class","compass active");var L=E.zoom();E.zoom(t<0?Math.ceil(L)-1:Math.floor(L)+1);return m(C)}}function o(t){return function(C){E.zoom(t);return m(C)}}function k(){this.setAttribute("class","active")}function q(){this.removeAttribute("class")}function m(t){t.stopPropagation();t.preventDefault();return false}function i(t){var C=Math.SQRT1_2*D,L=D*0.7,G=D*0.2,M=r.svg("g"),S=M.appendChild(r.svg("path")), -O=M.appendChild(r.svg("path"));S.setAttribute("class","direction");S.setAttribute("pointer-events","all");S.setAttribute("d","M0,0L"+C+","+C+"A"+D+","+D+" 0 0,1 "+-C+","+C+"Z");O.setAttribute("class","chevron");O.setAttribute("d","M"+G+","+(L-G)+"L0,"+L+" "+-G+","+(L-G));O.setAttribute("pointer-events","none");M.addEventListener("mousedown",d,false);M.addEventListener("mouseover",c(t),false);M.addEventListener("mouseout",c(null),false);M.addEventListener("dblclick",m,false);return M}function s(t){var C= +this.setAttribute("class","active"):this.removeAttribute("class");H=t}}function e(t){return function(C){F.setAttribute("class","compass active");var L=E.zoom();E.zoom(t<0?Math.ceil(L)-1:Math.floor(L)+1);return l(C)}}function o(t){return function(C){E.zoom(t);return l(C)}}function k(){this.setAttribute("class","active")}function q(){this.removeAttribute("class")}function l(t){t.stopPropagation();t.preventDefault();return false}function i(t){var C=Math.SQRT1_2*D,L=D*0.7,G=D*0.2,M=r.svg("g"),S=M.appendChild(r.svg("path")), +O=M.appendChild(r.svg("path"));S.setAttribute("class","direction");S.setAttribute("pointer-events","all");S.setAttribute("d","M0,0L"+C+","+C+"A"+D+","+D+" 0 0,1 "+-C+","+C+"Z");O.setAttribute("class","chevron");O.setAttribute("d","M"+G+","+(L-G)+"L0,"+L+" "+-G+","+(L-G));O.setAttribute("pointer-events","none");M.addEventListener("mousedown",d,false);M.addEventListener("mouseover",c(t),false);M.addEventListener("mouseout",c(null),false);M.addEventListener("dblclick",l,false);return M}function s(t){var C= D*0.4,L=C/2,G=r.svg("g"),M=G.appendChild(r.svg("path")),S=G.appendChild(r.svg("path")),O=G.appendChild(r.svg("path")),Q=G.appendChild(r.svg("path"));M.setAttribute("class","back");M.setAttribute("d","M"+-C+",0V"+-C+"A"+C+","+C+" 0 1,1 "+C+","+-C+"V0Z");S.setAttribute("class","direction");S.setAttribute("d",M.getAttribute("d"));O.setAttribute("class","chevron");O.setAttribute("d","M"+-L+","+-C+"H"+L+(t>0?"M0,"+(-C-L)+"V"+-L:""));Q.setAttribute("class","fore");Q.setAttribute("fill","none");Q.setAttribute("d", -M.getAttribute("d"));G.addEventListener("mousedown",e(t),false);G.addEventListener("mouseover",k,false);G.addEventListener("mouseout",q,false);G.addEventListener("dblclick",m,false);return G}function u(t){var C=D*0.2,L=D*0.4,G=r.svg("g"),M=G.appendChild(r.svg("rect")),S=G.appendChild(r.svg("path"));M.setAttribute("pointer-events","all");M.setAttribute("fill","none");M.setAttribute("x",-L);M.setAttribute("y",-0.75*L);M.setAttribute("width",2*L);M.setAttribute("height",1.5*L);S.setAttribute("class", -"chevron");S.setAttribute("d","M"+-C+",0H"+C);G.addEventListener("mousedown",o(t),false);G.addEventListener("dblclick",m,false);return G}function y(){var t=D+6,C=t,L=E.size();switch(n){case "top-left":break;case "top-right":t=L.x-t;break;case "bottom-left":C=L.y-C;break;case "bottom-right":t=L.x-t;C=L.y-C;break}t="translate("+t+","+C+")";N&&N.setAttribute("transform",t);A&&A.setAttribute("transform",t);for(var G in B)G==E.zoom()?B[G].setAttribute("class","active"):B[G].removeAttribute("class")}function K(){for(;F.lastChild;)F.removeChild(F.lastChild); +M.getAttribute("d"));G.addEventListener("mousedown",e(t),false);G.addEventListener("mouseover",k,false);G.addEventListener("mouseout",q,false);G.addEventListener("dblclick",l,false);return G}function u(t){var C=D*0.2,L=D*0.4,G=r.svg("g"),M=G.appendChild(r.svg("rect")),S=G.appendChild(r.svg("path"));M.setAttribute("pointer-events","all");M.setAttribute("fill","none");M.setAttribute("x",-L);M.setAttribute("y",-0.75*L);M.setAttribute("width",2*L);M.setAttribute("height",1.5*L);S.setAttribute("class", +"chevron");S.setAttribute("d","M"+-C+",0H"+C);G.addEventListener("mousedown",o(t),false);G.addEventListener("dblclick",l,false);return G}function y(){var t=D+6,C=t,L=E.size();switch(n){case "top-left":break;case "top-right":t=L.x-t;break;case "bottom-left":C=L.y-C;break;case "bottom-right":t=L.x-t;C=L.y-C;break}t="translate("+t+","+C+")";N&&N.setAttribute("transform",t);A&&A.setAttribute("transform",t);for(var G in B)G==E.zoom()?B[G].setAttribute("class","active"):B[G].removeAttribute("class")}function K(){for(;F.lastChild;)F.removeChild(F.lastChild); F.appendChild(P);if(z!="none"){N=F.appendChild(r.svg("g"));N.setAttribute("class","pan");var t=N.appendChild(r.svg("circle"));t.setAttribute("class","back");t.setAttribute("r",D);N.appendChild(i({x:0,y:-x})).setAttribute("transform","rotate(0)");N.appendChild(i({x:x,y:0})).setAttribute("transform","rotate(90)");N.appendChild(i({x:0,y:x})).setAttribute("transform","rotate(180)");N.appendChild(i({x:-x,y:0})).setAttribute("transform","rotate(270)");t=N.appendChild(r.svg("circle"));t.setAttribute("fill", "none");t.setAttribute("class","fore");t.setAttribute("r",D)}else N=null;if(v!="none"){A=F.appendChild(r.svg("g"));A.setAttribute("class","zoom");t=-0.5;if(v=="big"){B={};var C=E.zoomRange()[0];for(t=0;C<=E.zoomRange()[1];C++,t++)(B[C]=A.appendChild(u(C))).setAttribute("transform","translate(0,"+-(t+0.75)*D*0.4+")")}C=z=="none"?0.4:2;A.setAttribute("transform","translate(0,"+D*(/^top-/.test(n)?C+(t+0.5)*0.4:-C)+")");A.appendChild(s(+1)).setAttribute("transform","translate(0,"+-(t+0.5)*D*0.4+")"); -A.appendChild(s(-1)).setAttribute("transform","scale(-1)")}else A=null;y()}var w={},F=r.svg("g"),B={},D=30,x=16,l=0,g=250,p=50,n="top-left",v="small",A,z="small",I,H,N,J,P=r.svg("rect"),E,T,U;F.setAttribute("class","compass");P.setAttribute("class","back fore");P.setAttribute("pointer-events","none");P.setAttribute("display","none");w.radius=function(t){if(!arguments.length)return D;D=t;E&&K();return w};w.speed=function(t){if(!arguments.length)return D;x=t;return w};w.position=function(t){if(!arguments.length)return n; +A.appendChild(s(-1)).setAttribute("transform","scale(-1)")}else A=null;y()}var w={},F=r.svg("g"),B={},D=30,x=16,m=0,g=250,p=50,n="top-left",v="small",A,z="small",I,H,N,J,P=r.svg("rect"),E,T,U;F.setAttribute("class","compass");P.setAttribute("class","back fore");P.setAttribute("pointer-events","none");P.setAttribute("display","none");w.radius=function(t){if(!arguments.length)return D;D=t;E&&K();return w};w.speed=function(t){if(!arguments.length)return D;x=t;return w};w.position=function(t){if(!arguments.length)return n; n=t;E&&K();return w};w.pan=function(t){if(!arguments.length)return z;z=t;E&&K();return w};w.zoom=function(t){if(!arguments.length)return v;v=t;E&&K();return w};w.map=function(t){if(!arguments.length)return E;if(E){T.removeEventListener("mousedown",a,false);T.removeChild(F);T=null;U.removeEventListener("mousemove",j,false);U.removeEventListener("mouseup",h,false);U=null;E.off("move",y).off("resize",y)}if(E=t){T=E.container();T.appendChild(F);T.addEventListener("mousedown",a,false);U=T.ownerDocument.defaultView; U.addEventListener("mousemove",j,false);U.addEventListener("mouseup",h,false);E.on("move",y).on("resize",y);K()}return w};return w};r.grid=function(){function d(){var h=j.firstChild,c=a.size(),e=a.pointLocation(X);a.pointLocation(c);var o=Math.pow(2,4-Math.round(a.zoom()));e.lat=Math.floor(e.lat/o)*o;e.lon=Math.ceil(e.lon/o)*o;for(var k;(k=a.locationPoint(e).x)<=c.x;e.lon+=o){h||(h=j.appendChild(r.svg("line")));h.setAttribute("x1",k);h.setAttribute("x2",k);h.setAttribute("y1",0);h.setAttribute("y2", c.y);h=h.nextSibling}for(;(k=a.locationPoint(e).y)<=c.y;e.lat-=o){h||(h=j.appendChild(r.svg("line")));h.setAttribute("y1",k);h.setAttribute("y2",k);h.setAttribute("x1",0);h.setAttribute("x2",c.x);h=h.nextSibling}for(;h;){c=h.nextSibling;j.removeChild(h);h=c}}var f={},a,j=r.svg("g");j.setAttribute("class","grid");f.map=function(h){if(!arguments.length)return a;if(a){j.parentNode.removeChild(j);a.off("move",d).off("resize",d)}if(a=h){a.on("move",d).on("resize",d);a.container().appendChild(j);a.dispatch({type:"move"})}return f}; -return f};r.stylist=function(){function d(h){var c=h.features.length,e=f.length,o=a.length,k,q,m,i,s,u;for(s=0;s Date: Fri, 24 Sep 2010 22:35:33 -0700 Subject: [PATCH 2/2] Fix bug in KML parser example (missing type). --- examples/kml/kml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/kml/kml.js b/examples/kml/kml.js index 6c2e908..f4eb2d2 100644 --- a/examples/kml/kml.js +++ b/examples/kml/kml.js @@ -55,7 +55,7 @@ } if (f.geometry) features.push(f); } - return {features: features}; + return {type: "FeatureCollection", features: features}; } return kml;