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; diff --git a/polymaps.js b/polymaps.js index 3435d9a..8e2632e 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 + ")", @@ -1352,10 +1352,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 || []}); } } @@ -1396,14 +1396,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 3a01a0f..9bf03f9 100644 --- a/polymaps.min.js +++ b/polymaps.min.js @@ -1,6 +1,6 @@ if(!org)var org={};if(!org.polymaps)org.polymaps={}; (function(s){function fa(e){var g=e.indexOf(":");return g<0?e:{space:s.ns[e.substring(0,g)],local:e.substring(g+1)}}function S(){for(var e=0;eg.row){var c=e;e=g;g=c}return{x0:e.column,y0:e.row,x1:g.column,y1:g.row,dx:g.column-e.column,dy:g.row-e.row}}function ca(e,g,c,k,i){c=Math.max(c,Math.floor(g.y0)); -k=Math.min(k,Math.ceil(g.y1));if(e.x0==g.x0&&e.y0==g.y0?e.x0+g.dy/e.dy*e.dx0,q=g.dx<0;for(c=c;cg.dy){c=f;f=g;g=c}if(f.dy>e.dy){c=f;f=e;e=c}if(g.dy>e.dy){c=g;g=e;e=c}f.dy&&ca(e,f,k,i,a);g.dy&&ca(e,g,k,i,a)}s.version="2.2+1.0+1"; +k=Math.min(k,Math.ceil(g.y1));if(e.x0==g.x0&&e.y0==g.y0?e.x0+g.dy/e.dy*e.dx0,q=g.dx<0;for(c=c;cg.dy){c=f;f=g;g=c}if(f.dy>e.dy){c=f;f=e;e=c}if(g.dy>e.dy){c=g;g=e;e=c}f.dy&&ca(e,f,k,i,a);g.dy&&ca(e,g,k,i,a)}s.version="2.2+1.0+2"; var Y={x:0,y:0};s.ns={svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"};s.id=function(){var e=0;return function(){return++e}}();s.svg=function(e){return document.createElementNS(s.ns.svg,e)};s.transform=function(e,g,c,k,i,a){var f={},m,q,t;if(!arguments.length){e=1;g=i=c=0;k=1;a=0}f.zoomFraction=function(l){if(!arguments.length)return q;q=l;m=Math.floor(q+Math.log(Math.sqrt(e*e+g*g+c*c+k*k))/Math.log(2));t=Math.pow(2,-m);return f};f.apply=function(l){var j=Math.pow(2,-l.zoom), u=Math.pow(2,l.zoom-m);return{column:(e*l.column*j+c*l.row*j+i)*u,row:(g*l.column*j+k*l.row*j+a)*u,zoom:l.zoom-m}};f.unapply=function(l){var j=Math.pow(2,-l.zoom),u=Math.pow(2,l.zoom+m);return{column:(l.column*j*k-l.row*j*c-i*k+a*c)/(e*k-g*c)*u,row:(l.column*j*g-l.row*j*e-i*g+a*e)/(c*g-k*e)*u,zoom:l.zoom+m}};f.toString=function(){return"matrix("+[e*t,g*t,c*t,k*t].join(" ")+" 0 0)"};return f.zoomFraction(0)};s.cache=function(e,g){function c(j){l--;g&&g(j);delete f[j.key];if(j.next)j.next.prev=j.prev; else if(q=j.prev)q.next=null;if(j.prev)j.prev.next=j.next;else if(m=j.next)m.prev=null}function k(){for(var j=q;l>t;j=j.prev){if(!j)break;j.lock||c(j)}}var i={},a={},f={},m=null,q=null,t=64,l=0;i.peek=function(j){return f[[j.zoom,j.column,j.row].join("/")]};i.load=function(j,u){var y=[j.zoom,j.column,j.row].join("/"),A=f[y];if(A){if(A.prev){if(A.prev.next=A.next)A.next.prev=A.prev;else q=A.prev;A.prev=null;A.next=m;m=m.prev=A}A.lock=1;return a[y]=A}A={key:y,column:j.column,row:j.row,zoom:j.zoom,next:m, @@ -26,15 +26,15 @@ v=h.pointCoordinate(z,{x:d.x,y:0});n=h.pointCoordinate(z,d);h=h.pointCoordinate( M[F];if(v.element.parentNode!=C[v.level]){C[v.level].appendChild(v.element);a.show&&a.show(v)}}f.flush();a.dispatch({type:"move"})}var a={},f=a.cache=s.cache(e,g).size(512),m=true,q=true,t,l,j,u=s.svg("g"),y,A,C={};u.setAttribute("class","layer");for(var E=-4;E<=-1;E++)C[E]=u.appendChild(s.svg("g"));for(E=2;E>=1;E--)C[E]=u.appendChild(s.svg("g"));C[0]=u.appendChild(s.svg("g"));a.map=function(B){if(!arguments.length)return j;if(j){if(j==B){u.parentNode.appendChild(u);return a}j.off("move",i).off("resize", i);u.parentNode.removeChild(u)}if(j=B){j.container().appendChild(u);a.init&&a.init(u);j.on("move",i).on("resize",i);i()}return a};a.container=function(){return u};a.levels=function(){return C};a.id=function(B){if(!arguments.length)return l;l=B;u.setAttribute("id",B);return a};a.visible=function(B){if(!arguments.length)return q;(q=B)?u.removeAttribute("visibility"):u.setAttribute("visibility","hidden");j&&i();return a};a.transform=function(B){if(!arguments.length)return y;y=B;j&&i();return a};a.zoom= function(B){if(!arguments.length)return t;t=typeof B=="function"||B==null?B:function(){return B};j&&i();return a};a.tile=function(B){if(!arguments.length)return m;m=B;j&&i();return a};a.reload=function(){f.clear();j&&i();return a};a.dispatch=s.dispatch(a);a.on("load",function(B){if(B.tile.proxyRefs){for(var K in B.tile.proxyRefs){var h=B.tile.proxyRefs[K];--h.proxyCount<=0&&f.unload(K)&&h.element.parentNode.removeChild(h.element)}delete B.tile.proxyRefs}});return a};s.image=function(){var e=s.layer(function(c){var k= -c.element=s.svg("image"),i=e.map().tileSize();k.setAttribute("preserveAspectRatio","none");k.setAttribute("width",i.x);k.setAttribute("height",i.y);k.setAttribute("opacity",0);if(typeof g=="function")c.request=s.queue.image(k,g(c),function(a){delete c.request;c.ready=true;c.img=a;k.removeAttribute("opacity");e.dispatch({type:"load",tile:c})});else{c.ready=true;k.setAttributeNS(s.ns.xlink,"href",g);e.dispatch({type:"load",tile:c})}},function(c){c.request&&c.request.abort(true)}),g="about:blank";e.url= -function(c){if(!arguments.length)return g;g=typeof c=="string"&&/{.}/.test(c)?s.url(c):c;return e.reload()};return e};s.geoJson=function(e){function g(h){var n={lat:0,lon:0};return function(w){n.lat=w[1];n.lon=w[0];var d=h(n);w.x=d.x;w.y=d.y;return d}}function c(h,n){return h&&h.type in C&&C[h.type](h,n)}function k(h,n,w){return h.type in E&&E[h.type](h,n,w)}function i(){var h=a.map().zoom(),n=a.cache.locks(),w,d,r,o,z,v,L;if(y=="fixed")for(w in n){if((d=n[w]).scale!=h){L="scale("+Math.pow(2,d.zoom- -h)+")";o=-1;for(z=(r=d.features).length;++o