-
Notifications
You must be signed in to change notification settings - Fork 0
/
seajax-utils.js
5 lines (5 loc) · 3.43 KB
/
seajax-utils.js
1
2
3
4
5
No5={};No5.Seajax={};No5.Seajax.Shapes={};No5.Seajax.Tilesource={};No5.Seajax.toImageCoordinates=function(a,b,c){a=No5.Seajax.Dimension(a);return new Seadragon.Point(b*a,c*a)};No5.Seajax.toWorldCoordinates=function(a,b,c){a=No5.Seajax.Dimension(a);return new Seadragon.Point(b/a,c/a)};No5.Seajax.Dimension=function(a){return a.source.width>a.source.height?a.source.width:a.source.height};No5.Seajax.Shapes.Marker=function(a){this.img=document.createElement("img");this.img.src=a};No5.Seajax.Shapes.Marker.prototype.attachTo=function(a,b,c){b=No5.Seajax.toWorldCoordinates(a,b,c);a.drawer.addOverlay(this.img,b,Seadragon.OverlayPlacement.BOTTOM)};No5.Seajax.Shapes.Marker.prototype.addEventListener=function(a,b){Seadragon.Utils.addEvent(this.img,a,Seadragon.Utils.stopEvent);this.img.addEventListener(a,b,!1)};No5.Seajax.Shapes.Ellipse=function(a,b){this.width=a;this.height=b;this.div=document.createElement("div");var c=Raphael(this.div,a,b),e=viewer.viewport.getMaxZoom();this.ellipse=c.ellipse(a/(2*e),b/(2*e),a/(2*e),b/(2*e));this.ellipse.node.style.cursor="pointer"};
No5.Seajax.Shapes.Ellipse.prototype.attachTo=function(a,b,c){b=No5.Seajax.toWorldCoordinates(a,b,c);c=No5.Seajax.toWorldCoordinates(a,this.width,this.height);a.drawer.addOverlay(this.div,new Seadragon.Rect(b.x,b.y,c.x,c.y));var e=this.ellipse;a.addEventListener("animation",function(){var b=a.viewport.getZoom(!0);e.scale(b,b,0,0)})};No5.Seajax.Shapes.Ellipse.prototype.getElement=function(){return this.ellipse};
No5.Seajax.Shapes.Ellipse.prototype.redraw=function(a){a=a.viewport.getZoom(!0);this.ellipse.scale(a,a,0,0)};No5.Seajax.Shapes.Ellipse.prototype.addEventListener=function(a,b){Seadragon.Utils.addEvent(this.div,a,Seadragon.Utils.stopEvent);this.img.addEventListener(a,b,!1)};No5.Seajax.Shapes.Polygon=function(a){for(var b=a[0].x,c=b,e=a[0].y,f=e,d=1,g=a.length;d<g;++d){if(a[d].x<b)b=a[d].x;if(a[d].x>c)c=a[d].x;if(a[d].y<e)e=a[d].y;if(a[d].y>f)f=a[d].y}this.origin=new Seadragon.Point(b,e);this.width=c-b;this.height=f-e;c=viewer.viewport.getMaxZoom();this.normWidth=2*this.width/c;this.normHeight=2*this.height/c;this.div=document.createElement("div");this.paper=Raphael(this.div);for(var f=2*(a[0].x-b)/c+" "+2*(a[0].y-e)/c,h="M"+f,d=1,g=a.length;d<g;++d)h+="L"+2*(a[d].x-
b)/c+" "+2*(a[d].y-e)/c;h+="L"+f;this.path=this.paper.path(h);this.paper.setSize(this.normWidth,this.normHeight)};No5.Seajax.Shapes.Polygon.prototype.attachTo=function(a){var b=No5.Seajax.toWorldCoordinates(a,this.origin.x,this.origin.y);a.drawer.addOverlay(this.div,new Seadragon.Rect(b.x,b.y,0,0));var c=this.paper,e=this.path,f=this.normWidth,d=this.normHeight;a.addEventListener("animation",function(){var b=a.viewport.getZoom(!0);c.setSize(f*b,d*b);e.scale(b,b,0,0)})};
No5.Seajax.Shapes.Polygon.prototype.getElement=function(){return this.path};No5.Seajax.Shapes.Polygon.prototype.redraw=function(a){a=a.viewport.getZoom(!0);this.paper.setSize(this.normWidth*a,this.normHeight*a);this.path.scale(a,a,0,0)};No5.Seajax.Shapes.Polygon.prototype.addEventListener=function(a,b){Seadragon.Utils.addEvent(this.div,a,Seadragon.Utils.stopEvent);this.div.addEventListener(a,b,!1)};No5.Seajax.Tilesource.OSM=function(){var a=new Seadragon.TileSource(65572864,65572864,256,0);a.getTileUrl=function(a,c,e){return"http://tile.openstreetmap.org/"+(a-8)+"/"+c+"/"+e+".png"};return a};No5.Seajax.Tilesource.TMS=function(a,b,c){b=new Seadragon.TileSource(b,c,256,0);b.getTileUrl=function(b,c,d){return a+(b-8)+"/"+c+"/"+(Math.pow(2,b-10)-1-d)+".jpg"};return b};