/***
|''Name:''|Jon Robson's VismoLibrary|
|''Description:''|An opensource library of javascript code designed to create clickable graphics in canvas with VML alternative for Internet Explorer browsers. The purpose of this is to provide hackable, extendable graphics based plugins without being locked in to consumer products such as Flash.|
|''Author:''|JonRobson (http://www.jonrobson.me.uk/Vismo)|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/JonRobson/Library/Vismo/|
|''Version:''|0.95 |
|''Dependencies:''| Requires jQuery|
|''Comments:''|Please raise questions and make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[BSD License|http://www.opensource.org/licenses/bsd-license.php]] |
|''Contributors:''"|
Graph algorithms for VismoGraphs come from uses code from ECO Tree http://www.codeproject.com/KB/scripting/graphic_javascript_tree.aspx#quick|
and Nicolas Belmonte's JIT library (http://thejit.org/)
|
"|''Usage:''|
Not much good on it's own - it provides some nice functions to create graphicsy plugins.
Currently provides horsepower to the following plugins amongst others:
GeoTiddlyWiki (http://www.jonrobson.me.uk/workspaces/tiddlers/GeoTiddlyWiki/), ImageTaggingPlugin, TiddlyTagMindMap (http://tiddlytagmindmap.tiddlyspot.com)
!Wouldn't have been possible without..
http://spatialreference.org/ref/sr-org/google-projection/ for help with google projection hack
***/
Array.prototype.contains=function(a){return this.indexOf(a)!=-1};Array.prototype.clone=function(){var b=new Array();for(var c in this){b[c]=typeof(this[c])=="object"?this[c].clone():this[c]}return b};if(!Array.indexOf){Array.prototype.indexOf=function(b,c){if(!c){c=0}for(var a=c;a<this.length;a++){if(this[a]===b){return a}}return -1}}var VismoShapeUtils={randomColor:function(h){var f=parseInt(Math.random()*255);var e=parseInt(Math.random()*255);var c=parseInt(Math.random()*255);var d;if(h){var d=parseInt(Math.random()*255)}else{d=1}return"rgba("+f+","+e+","+c+","+d+")"},_isCoordinate:function(a){if(a=="M"||a=="q"||a=="c"){return false}else{if(typeof(a)=="number"){return true}}},toHex:function(a){if(a.indexOf("rgba")==0){a=a.replace("rgba(","");a=a.replace(")","")}else{if(a.indexOf("rgb")==0){a=a.replace("rgb(","")}}a=a.replace(")","");a=a.split(",");return"#"+this._tohexadecimal(a[0])+this._tohexadecimal(a[1])+this._tohexadecimal(a[2])},_tohexadecimal:function(a){if(a==null){return"00"}a=parseInt(a);if(a==0||isNaN(a)){return"00"}a=Math.max(0,a);a=Math.min(a,255);a=Math.round(a);return["0123456789ABCDEF".charAt((a-a%16)/16),"0123456789ABCDEF".charAt(a%16)].join("")},opacityFrom:function(c){var a=c.replace("rgba(","");a=a.replace(")","");a=a.split(",");var b=0;if(a.length<4){b=1}else{b=a[3]}return b},toRgb:function(f,c){var b={};if(f.indexOf("#")==0&&f.indexOf(",")==-1){var d=f;var e=d.substring(1);b.red=this._hexToR(e);b.blue=this._hexToB(e);b.green=this._hexToG(e)}else{if(f.indexOf("rgba")!=-1){var a=f.replace("rgba(","");a=a.replace(")","");a=a.split(",");b.red=a[0];b.green=a[1];b.blue=a[2];c=a[3]}}return{rgb:"rgb("+b.red+","+b.green+","+b.blue+")",opacity:c}},toRgba:function(c,b){var a={};if(c.indexOf("#")==0&&c.indexOf(",")==-1){var d=c.substring(1);a.red=this._hexToR(d);a.blue=this._hexToB(d);a.green=this._hexToG(d)}if(!b){b="1.0"}return"rgba("+a.red+","+a.green+","+a.blue+","+b+")"},_cutHex:function(a){return(a.charAt(0)=="#")?a.substring(1,7):a},_hexToR:function(a){return parseInt((this._cutHex(a)).substring(0,2),16)},_hexToG:function(a){return parseInt((this._cutHex(a)).substring(2,4),16)},_hexToB:function(a){return parseInt((this._cutHex(a)).substring(4,6),16)}};var VismoUtils={canvasSupport:false,userAgent:navigator.userAgent.toLowerCase(),clone:function(c){if(!c){return c}if(c.appendChild){return c}if(c==null||typeof(c)!="object"){return c}var a=new c.constructor();for(var b in c){a[b]=VismoUtils.clone(c[b])}return a},invertYCoordinates:function(d){var c=[];for(var b=0;b<d.length;b++){var a=d[b][0];var e=d[b][1];c.push([a,-e])}return c},scrubNode:function(f){if(!VismoUtils.browser.isIE){return}var a=f.attributes;if(a){for(var d=0;d<a.length;d++){var h=a[d].name;if(h!=="style"&&(typeof f[h]==="function"||(typeof f[h]==="object"&&f[h]!=null))){try{f[h]=null}catch(b){}}}}var g=f.firstChild;while(g){VismoUtils.scrubNode(g);g=g.nextSibling}f.parentNode.removeChild(f)},mergejsons:function(d,c){var b={};var a;for(a in d){b[a]=d[a]}for(a in c){b[a]=d[a]}return b},init:function(){var a=document.createElement("canvas");if(a.getContext){VismoUtils.canvasSupport=true}}};VismoUtils.init();VismoUtils.browser={isIE:VismoUtils.userAgent.indexOf("msie")!=-1&&VismoUtils.userAgent.indexOf("opera")==-1,isGecko:VismoUtils.userAgent.indexOf("gecko")!=-1,ieVersion:/MSIE (\d.\d)/i.exec(VismoUtils.userAgent),isSafari:VismoUtils.userAgent.indexOf("applewebkit")!=-1,isBadSafari:!((new RegExp("[\u0150\u0170]","g")).test("\u0150")),firefoxDate:/gecko\/(\d{8})/i.exec(VismoUtils.userAgent),isOpera:VismoUtils.userAgent.indexOf("opera")!=-1,isLinux:VismoUtils.userAgent.indexOf("linux")!=-1,isUnix:VismoUtils.userAgent.indexOf("x11")!=-1,isMac:VismoUtils.userAgent.indexOf("mac")!=-1,isWindows:VismoUtils.userAgent.indexOf("win")!=-1};if(VismoUtils.browser.isIE&&VismoUtils.browser.ieVersion[1]=="6.0"){VismoUtils.browser.isIE6=true}if(VismoUtils.browser.isIE){if(!document.namespaces.vismoShapeVml_){document.namespaces.add("vismoShapeVml_","urn:schemas-microsoft-com:vml")}document.namespaces.add("xmlns","http://www.w3.org/1999/xhtml");document.namespaces.add("svg","http://www.w3.org/2000/svg");document.namespaces.add("xlink","http://www.w3.org/1999/xlink");if(!document.styleSheets.vismoShape){var ss=document.createStyleSheet();ss.owningElement.id="vismoShape";ss.cssText="canvas{display:inline;overflow:hidden;text-align:left;}vismoShapeVml_\\: * {behavior:url(#default#VML);}"}}VismoUtils.svgSupport=function(){if(VismoUtils.browser.isIE){try{var b=new ActiveXObject("Adobe.SVGCtl");return true}catch(a){}}else{if(document.implementation){if(VismoUtils.browser.isSafari){return true}return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape","1.0")}}return true};var VismoShape=function(a,b){this._isVismoShape=true;this._iemultiplier=1000;this.options={};if(!b){b=a.coordinates;delete a.coordinates}this._optimise_cache={};this.coordinates={projected:false,normal:[],optimised:{},optimisedandprojected:{}};this.grid={};this.width=0;this.height=0;this.properties={};this.setProperties(a);if(b[0]&&b[0].length==2){b=VismoOptimisations.unpackCoordinates(b)}this._construct(a,b);this.browser=false;this.currentResolution=false;this.vml=false;this.unique_id=[Math.random(),"_",this.properties.id].join("");this._scale={x:1,y:1}};VismoShape.prototype={_commands:{M:true,c:true,q:true,XE:true},isCommand:function(a){return this._commands[a]},clone:function(){var b=this.getCoordinates("normal");var a=this.getProperties();var d=VismoUtils.clone(a);d.coordinates=b;try{return new VismoShape(d)}catch(c){throw c}},translate:function(a,h){var g=this.getCoordinates("normal");var e=[];for(var b=0;b<g.length;b+=2){if(this.isCommand(g[b])){b+=1}var f,d;f=g[b]+a;d=g[b+1]+h;e.push(f);e.push(d)}this.setCoordinates(e)},scale:function(a,h){this._scale.x=a;this._scale.y=h;var g=this.getCoordinates("normal");var e=[];for(var b=0;b<g.length;b+=2){if(this.isCommand(g[b])){b+=1}var f,d;f=g[b]*a;d=g[b+1]*h;e.push(f);e.push(d)}this.setCoordinates(e);return true},resize:function(n,m){var k=this.getBoundingBox();var f=n*k.width;var a=m*k.height;var d=(k.center.x*n)-k.center.x;var b=(k.center.y*m)-k.center.y;this._scale.x=n;this._scale.y=m;var l=this.getCoordinates("normal");var g=[];for(var e=0;e<l.length;e+=2){var j,h;j=l[e]*n;h=l[e+1]*m;j-=d;h-=b;g.push(j);g.push(h)}this.setCoordinates(g);return true},_validDomElements:{image:true,domElement:true},_path:{path:true},_pathbased:{polygon:true,path:true},_arcbased:{circle:true,point:true},_isDomElement:function(a){return this._validDomElements[a]},_isPath:function(a){return this._path[a]},_isPathBased:function(a){return this._pathbased[a]},_isArcBased:function(a){return this._arcbased[a]},moveTo:function(h,g){var l=this.properties.shape;var b=this.getDimensions();if(this._isArcBased(l)){this.setCoordinates([h,g,b.width/2,b.height/2])}else{if(this._isPathBased(l)){var e=this.getBoundingBox();var k=h-e.center.x;var j=g-e.center.y;var f=this.getCoordinates("normal");var d=[];for(var a=0;a<f.length;a+=2){if(this.isCommand(f[a])){a+=1}d.push(f[a]+k);d.push(f[a+1]+j)}this.setCoordinates(d)}}},getShape:function(){return this.getProperty("shape")},setProperties:function(c){var a=VismoUtils.clone(c);var b;for(b in a){this.setProperty(b,a[b])}if(!a["z-index"]){this.setProperty("z-index","0")}if(!a.stroke){this.setProperty("stroke","#000000")}},getBoundingBox:function(){return this.grid},render:function(d,f,c,b,a,e){VismoTimer.start("VismoShape.render");var g=this.properties.lineWidth;if(c){this._applyProjection(c,f)}var h=this.getRenderMode(d);if(VismoUtils.canvasSupport){this.render_canvas(d,f,c,b)}else{this.render_ie(d,f,c,b,a,e)}this.properties.lineWidth=g;VismoTimer.end("VismoShape.render")},render_ie:function(e,g,d,c,b,f){VismoTimer.start("VismoShape.render_ie");var a=this.vml;if(this.properties.hidden){if(a){a.clear()}return}if(a===false){a=new VismoVector(this,e,f);this.donevml=true}a.render(e,g,d);this.vml=a;VismoTimer.end("VismoShape.render_ie");return},render_canvas:function(d,h,e,l){VismoTimer.start("VismoShape.render_canvas");var g;if(this.properties.hidden){return}var j=this;var k=d.getContext("2d");if(!k){return}k.save();if(h){var b=h.origin;var f=h.translate;var m=h.scale;var a=h.rotate;if(b){k.translate(b.x,b.y)}if(m){k.scale(m.x,m.y)}if(f){k.translate(f.x,f.y)}if(a&&a.x){k.rotate(a.x)}}VismoCanvasRenderer.renderShape(d,j);k.restore();VismoTimer.end("VismoShape.render_canvas")},getTransformation:function(){var a=this.getProperty("transformation");if(!a){a={translate:false,scale:false}}if(!a.translate){a.translate={x:0,y:0}}if(!a.translate.x){a.translate.x=0}if(!a.translate.y){a.translate.y=0}if(!a.scale){a.scale={x:1,y:1}}if(!a.scale.x){a.scale.x=1}if(!a.scale.y){a.scale.y=1}return a},setTransformation:function(a){this.setProperty("transformation",a);this._calculateBounds()},setCoordinates:function(n,l){VismoTimer.start("VismoShape.setCoordinates");var d=this.properties;var g=this.coordinates;var b=d.shape;var o=g.normal;if(b=="circle"||b=="point"){if(n.length==2&&o){n.push(o[2]);n.push(o[3])}}var e=[];var m=n.length;for(var h=0;h<m;h++){var k=n[h];if(!this.isCommand(k)){k=parseFloat(k)}e.push(k)}if(e.length<2){throw"cannot set coordinates for VismoShape not enough good coordinates given (coordinates may contain non-number elements)"+n.toString()}n=e;if(l=="projected"){g.projected=n;this._calculateBounds(n);return}this.coordinates.normal=n;var a=this.vml;if(a){a.coordinatesHaveChanged()}this.coordinates.projected=false;var h;for(h in this.coordinates_optimised){delete this.coordinates_optimised[h]}var f;for(f in this.coordinates.optimisedandprojected){delete this.coordinates.optimisedandprojected[f]}this.grid={};if(a){a.path=false}var p=this.getShape();if(this._isArcBased(p)){this.setRadius(n[2],n[3])}this._calculateBounds();VismoTimer.end("VismoShape.setCoordinates")},getCoordinates:function(c){VismoTimer.start("VismoShape.getCoordinates");if(!c){if(this.coordinates.projected){VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.projected}else{VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.normal}}if(c=="normal"){VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.normal}if(c=="projected"){VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.projected}var a=this.currentResolution;if(this.coordinates.projected){if(this.browser!="ie"&&a){var d=this._simplifyCoordinates(a,this.coordinates.projected);VismoTimer.end("VismoShape.getCoordinates");return d}VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.projected}else{if(this.browser!="ie"&&a){var b=this.coordinates.optimised;if(!b[a]){b[a]=this._simplifyCoordinates(a,this.coordinates.normal)}VismoTimer.end("VismoShape.getCoordinates");return b[a]}VismoTimer.end("VismoShape.getCoordinates");return this.coordinates.normal}},getProperties:function(){return this.properties},getRenderMode:function(a){return VismoUtils.canvasSupport},setProperty:function(a,b){this.properties[a]=b;if(this.vml){this.vml.nochange=false}if(a=="z-index"){if(Vismo.store.Canvas[this._canvasref]){Vismo.store.Canvas[this._canvasref].needsSort=true}}},getProperty:function(a){return this.properties[a]},_calculateBounds:function(z){VismoTimer.start("VismoShapes._calculateBounds");var h=this;var v=this.getShape();var m=this.getTransformation();if(this._isPath(v)){this.grid={x1:0,x2:1,y1:0,y2:1,center:{x:0,y:0}};return}else{if(this._isPathBased(v)){if(!z){z=this.getCoordinates()}var n=z.length;if(n<2){return}var C=z[0];var d=z[1];var B=z[0];var b=z[1];var g,e;var f=0;g=z[0];e=z[1];for(var A=0;A<n-1;A+=2){var l=z[A];var q=z[A+1];if(l<C){C=l}if(q<d){d=q}if(l>B){B=l}if(q>b){b=q}g=l;e=q}var t=(B-C);var p=(b-d);var c=(B-C)/2+C;var a=(b-d)/2+d;t*=m.scale.x;p*=m.scale.y;c+=m.translate.x;a+=m.translate.y;var o=t/2;var D=p/2;C=c-o;B=c+o;d=a-D;b=a+D;this.grid={x1:C,x2:B,y1:d,y2:b,center:{x:c,y:a},width:t,height:p}}else{if(this._isArcBased(v)|this._isDomElement(v)){var z=this.getCoordinates("normal").clone();var k=z[0];var j=z[1];var w=this.getDimensions();var E={x:k,y:j};if(m){if(m.translate){var u=m.translate.x;var s=m.translate.y;E.x+=u;E.y+=s}if(m.scale){w.width*=m.scale.x;w.height*=m.scale.y}}var r=w.width/2;var F=w.height/2;this.grid={x1:k-r,x2:k+r,y1:j-F,y2:j+F,center:E,width:w.width,height:w.height}}}}VismoTimer.end("VismoShapes._calculateBounds")},getCanvas:function(){return this.vismoCanvas},setRadius:function(b,a){if(!a){a=b}this.setDimensions(b*2,a*2)},getRadius:function(){if(this.width){return this.width/2}else{var a=this.getBoundingBox();return a.width/2}},setDimensions:function(d,a){this.width=d;this.height=a;if(this.properties.shape=="circle"){for(var b in this.coordinates){var e=this.coordinates[b];if(e){e[2]=d/2}}}else{}if(this.vml){this.vml.path=false}this._calculateBounds()},getDimensions:function(){return{width:this.width,height:this.height}},_construct:function(f,k){VismoTimer.start("VismoShapes._construct");var a=f.shape;if(!a){a="polygon"}if(this._isPathBased(a)){this.setCoordinates(k)}else{if(this._isArcBased(a)){var j,d;if(k[2]){j=k[2]}else{j=2.5}if(k[3]){d=k[3]}else{d=j}this.setDimensions(j*2,d*2);this.setCoordinates([k[0],k[1],j,d])}else{if(this._isDomElement(a)){var l=jQuery(this.getProperty("element")).width();var e=jQuery(this.getProperty("element")).height();this.setDimensions(l,e);this.setCoordinates(k)}else{if(a=="image"){var b=this.getProperty("src");if(!b){throw"all images must carry a property src at minimum"}var c=new Image();c.src=b;this.image=c;var g=this;var l=g.getProperty("width");e=g.getProperty("height");if(k.length>2){l=k[2];e=k[3]}c.onload=function(){if(!l&&!e){g.setDimensions(l,e);g.setCoordinates([k[0],k[1]])}g.ready=true};if(c.complete){g.ready=true}g.setDimensions(l,e);g.setCoordinates([k[0],k[1]])}else{console.log("don't know how to construct basic shape "+f.shape)}}}}VismoTimer.end("VismoShapes._construct")},_applyProjection:function(e,k){VismoTimer.start("VismoShapes._applyProjection");var h=this.getCoordinates("normal");if(!e||!e.xy){return h}if(e.init){e.init()}var d=[];for(var b=0;b<h.length-1;b+=2){var l=false;if(!VismoShapeUtils._isCoordinate(h[b])){b+=1}var m=parseFloat(h[b]);var j=parseFloat(h[b+1]);var g,f;var a=e.xy(h[b],h[b+1],k);if(a.x&&a.y){g=a.x;f=a.y;if(a.move){l=true}cok=true;if(!e.nowrap){var n;if(g>m){n=g-m}if(m>g){n=m-g}if(n>100){cok=false}}if(cok){if(VismoShapeUtils._isCoordinate(m)&&VismoShapeUtils._isCoordinate(j)){if(l){d.push("M")}d.push(g);d.push(f)}}}}if(d.length<2){return}this.setCoordinates(d,"projected");this._calculateBounds(d);VismoTimer.end("VismoShapes._applyProjection");return d},optimise:function(e,k,f,b){VismoTimer.start("VismoShapes.optimise");var d=this._optimise_cache;var h=k.cache["id1"];var c=k.cache["id2"];if(this._scale.x>1){var j,g;j=this._scale.x*k.scale.x;g=this._scale.y*k.scale.y;h=j+","+g}if(!d[h]){d[h]={}}if(typeof(d[h][c])!="undefined"){return d[h][c]}var a=this.properties.shape;if(a=="path"){d[h][c]=true;VismoTimer.end("VismoShapes.optimise");return true}if(k&&k.scale){this.currentResolution=Math.min(k.scale.x,k.scale.y)}if(a!="point"&&a!="path"&&a!="domElement"){if(VismoOptimisations.vismoShapeIsTooSmall(this,k)){if(!b&&this.vml){this.vml.clear()}d[h][c]=false;VismoTimer.end("VismoShapes.optimise");return false}}if(!VismoOptimisations.vismoShapeIsInVisibleArea(this,e,k,f)){if(!b&&this.vml){this.vml.clear()}d[h][c]=false;VismoTimer.end("VismoShapes.optimise");return false}d[h][c]=true;VismoTimer.end("VismoShapes.optimise");return true},optimise_ie:function(c,e,a){VismoTimer.start("VismoShape.optimise_ie");var b=this._optimise_cache;var f=e.cache["id1"];if(typeof(b[f])!="undefined"){return b[f]}VismoOptimisations.minradius=6;var d=this.properties.shape;if(d=="path"||d=="point"){b[f]=true;return true}if(VismoOptimisations.vismoShapeIsTooSmall(this,e)){if(this.vml){this.vml.clear()}VismoTimer.end("VismoShape.optimise_ie");b[f]=false;return false}b[f]=true;VismoTimer.end("VismoShape.optimise_ie");return true},_simplifyCoordinates:function(c,h){VismoTimer.start("VismoShapes._simplifyCoordinates");if(this.getProperty("shape")=="path"){return h}if(!h){throw"give me some coordinates!"}var a=h;var b;var g=this.getBoundingBox();var f;if(g.width<g.height){f=g.width}else{f=g.height}b=(f/4)/c;h=VismoOptimisations.packCoordinates(h);h=VismoOptimisations.douglasPeucker(h,b);h=VismoOptimisations.unpackCoordinates(h);var e=a.length-h.length;VismoTimer.end("VismoShapes._simplifyCoordinates");if(e<10){return a}else{return h}}};var VismoCanvasRenderer={renderShape:function(c,b){var a=c.getContext("2d");var d=b.properties.shape;if(b.properties.lineWidth){a.lineWidth=b.getProperty("lineWidth")}a.save();a.beginPath();if(d=="point"||d=="circle"){this.renderPoint(a,b)}else{if(d=="image"){this.renderImage(a,b)}else{if(d=="path"){this.renderPath(a,b)}else{this.renderPath(a,b,true);a.closePath()}}}a.strokeStyle=b.getProperty("stroke");if(typeof b.getProperty("fill")=="string"){fill=b.getProperty("fill")}else{fill="#ffffff"}a.stroke();if(d!="path"){a.fillStyle=fill;a.fill()}a.restore()},renderPath:function(s,q,d){var e=true,f=false,j=false;var m=q.getCoordinates();var r=q.getProperty("transformation");if(!r){r={}}if(!r.translate){r.translate={x:0,y:0}}if(!r.scale){r.scale={x:1,y:1}}if(!r.translate.y){r.translate.y=0}if(!r.translate.x){r.translate.x=0}if(!r.scale.x){r.scale.x=1}if(!r.scale.y){r.scale.y=1}var k=q.grid;if(k.center){s.translate(k.center.x-(k.center.x*r.scale.x),k.center.y-(k.center.y*r.scale.y));s.scale(r.scale.x,r.scale.y);s.translate(r.translate.x,r.translate.y)}var k=q.grid;for(var g=0;g<m.length-1;g+=2){var h=VismoShapeUtils._isCoordinate(m[g]);if(!h){if(m[g]=="M"){e=true}else{if(m[g]=="q"){f=true}else{if(m[g]=="c"){j=true}}}g+=1}var p=parseFloat(m[g]);var o=parseFloat(m[g+1]);if(e){s.moveTo(p,o);e=false}else{if(f){var b=parseFloat(m[g+2]);var n=parseFloat(m[g+3]);g+=2;s.quadraticCurveTo(p,o,b,n)}else{if(j){var b=parseFloat(m[g+2]);var n=parseFloat(m[g+3]);var a=parseFloat(m[g+4]);var l=parseFloat(m[g+5]);g+=4;s.bezierCurveTo(p,o,b,n,a,l)}else{s.lineTo(p,o)}}}}},renderPoint:function(j,h){var d=h.getBoundingBox();var b=h.getDimensions();var g=b.width/2;var f=b.height/2;var a=h.getTransformation();if(a&&a.scale){g*=a.scale.x}var k=h.properties.pointType;var e=h.getCoordinates();j.arc(e[0],e[1],g,0,Math.PI*2,true)},renderImage:function(d,b){var f=b.getCoordinates();var e=b.getBoundingBox();var a=function(){if(b.ready){d.drawImage(b.image,e.x1,e.y1,e.width,e.height)}else{window.setTimeout(a,100)}};a()}};var VismoController=function(b,q){if(b.length){var s=[];for(var d=0;d<b.length;d++){var o=new VismoController(b[d],q);s.push(o)}return o}if(!q){q={}}if(!q.zoomfactor){q.zoomfactor=2}if(b.vismoController){throw"this already has a vismo controller!"}b.vismoController=true;this.enabledControls=[];if(typeof b=="string"){b=document.getElementById(b)}this.setLimits({});this.wrapper=b;this.handler=q.handler;this.defaultCursor="";var n=b.onmousedown;var r=b.onmouseup;var c=b.onmousemove;for(var d=0;d<b.childNodes.length;d++){var a=b.childNodes[d];try{a.onmousedown=function(f){if(n){n(f)}};a.onmouseup=function(f){if(r){r(f)}};a.onmousemove=function(f){if(c){c(f)}}}catch(m){}}controlDiv=document.createElement("div");controlDiv.style.position="absolute";controlDiv.style.top="0";controlDiv.style.left="0";controlDiv.className="vismoControls";jQuery(controlDiv).css({"z-index":10000,height:"120px",width:"60px"});this.wrapper.appendChild(controlDiv);this.controlDiv=controlDiv;this.controlCanvas=new VismoCanvas(this.controlDiv);jQuery(this.controlDiv).mouseover(function(f){f.stopPropagation();f.preventDefault()});var h=this;var g=function(f){if(f&&f.stopPropagation){f.stopPropagation()}else{f.cancelBubble=true}return false};var l=this;var k=function(u,t){var f=l;f._panzoomClickHandler(u,t,f);return g(u)};this.controlCanvas.mouse({up:g,down:k,dblclick:g});var j=q.transformation;if(j){if(!j.origin){j.origin={}}this.transformation=j}else{this.transformation={translate:{x:0,y:0},scale:{x:1,y:1},rotate:{x:0,y:0,z:0},origin:{}}}this.transformation.origin.x=jQuery(b).width()/2;this.transformation.origin.y=jQuery(b).height()/2;var p=this.transformation;if(!this.handler){alert("no transform handler function defined")}this.enabled=true;if(!q){q={}}if(!q.controls){q.controls=["pan","zoom","mousepanning","mousewheelzooming"]}this.options=q;if(!this.options.controlStroke){this.options.controlStroke="#000000"}if(!this.options.controlFill){this.options.controlFill="rgba(150,150,150,0.7)"}this.addControls(this.options.controls);this.limits={scale:{}};if(this.options.maxZoom){this.limits.scale.x=this.options.maxZoom;this.limits.scale.y=this.options.maxZoom}if(this.options.minZoom){this.limits.scale.minx=this.options.minZoom;this.limits.scale.miny=this.options.minZoom}this.pansensitivity=100;if(this.options.pansensitivity){this.pansensitivity=this.options.pansensitivity}jQuery(window).unload(function(){l.controlCanvas=null;l.controlDiv=null})};VismoController.prototype={setLimits:function(a){this.limits=a},getHandler:function(){return this.handler},setHandler:function(a){this.handler=a;a(this.transformation)},getEnabledControls:function(){return this.enabledControls},_addEnabledControl:function(a){this.enabledControls.push(a)},applyLayer:function(){var d=this;var a=function(){var g=d.controlCanvas.getMemory();for(var h=0;h<g.length;h++){g[h].setProperty("hidden",true)}d.controlCanvas.render()};this.controlCanvas.render();if(this.options.hidebuttons){a();return}if(VismoUtils.browser.isIE6){return}var b=this.getEnabledControls();var e,c;if(b.contains("pan")){e=true}if(b.contains("zoom")){c=true}var f=function(h){if(!h){return}if(!VismoUtils.svgSupport()){return}var g;if(false==true){g=document.createElement("div");g.innerHTML=h}else{g=document.createElement("object");g.setAttribute("codebase","http://www.adobe.com/svg/viewer/install/");if(VismoUtils.browser.isIE){g.setAttribute("classid","15")}g.setAttribute("style","overflow:hidden;position:absolute;z-index:0;width:60px;height:120px;");g.setAttribute("type","image/svg+xml");var j="data:image/svg+xml,"+h;g.setAttribute("data",j);jQuery(g).css({width:60,height:120})}d.controlDiv.appendChild(g);jQuery(d.controlDiv).css({"background-image":"none"});a()};if(e&&c){f(this.panzoomcontrolsSVG)}},getTransformation:function(){return this.transformation},translate:function(a,c){var b=this.getTransformation();b.translate.x=a;b.translate.y=c;this.transform()},addMouseWheelZooming:function(){var f=this;this._addEnabledControl("mousewheelzooming");this.crosshair={lastdelta:false};this.crosshair.pos={x:0,y:0};var j=this.getTransformation();var h=this.wrapper.onmousewheel;var f=this;var c=this.wrapper.onmousemove;var g=false;var b=false;var a=function(){if(VismoUtils.browser.isIE6){f.wrapper.style.cursor=""}else{jQuery(f.wrapper).removeClass("zooming")}};jQuery(this.wrapper).mousedown(function(l){b=true;if(VismoUtils.browser.isIE6){this.style.cursor="crosshair"}else{if(!jQuery(f.wrapper).hasClass("panning")){jQuery(f.wrapper).addClass("zooming")}}window.setTimeout(a,2000)});jQuery(this.wrapper).mouseout(function(l){var m;if(l.toElement){m=l.toElement}else{m=l.relatedTarget}if(jQuery(m,f.wrapper).length==0){b=false}a()});var k=function(r){if(!f.enabled){return}var A=0;if(!f.goodToTransform(r)){g=false;return false}var B=VismoClickingUtils.resolveTargetWithVismo(r);if(B!=f.wrapper&&B.parentNode!=f.wrapper){return false}if(r.wheelDelta){A=r.wheelDelta/120;if(window.opera){A=-A}}else{if(r.detail){A=-r.detail/3}}var n=0.4;var m=f.getTransformation();var o=m.scale;var z=m.origin;var v=VismoClickingUtils.getMouseFromEvent(r);var u=parseInt(f.wrapper.style.width)/2;var p=parseInt(f.wrapper.style.height)/2;var l=VismoTransformations.undoTransformation(v.x,v.y,f.transformation);m.translate={x:-l.x,y:-l.y};m.origin={x:v.x,y:v.y};if(A>f.crosshair.lastdelta+n||A<f.crosshair.lastdelta-n){var s,q;if(A>0){s=parseFloat(o.x)*2;q=parseFloat(o.y)*2}else{s=parseFloat(o.x)/2;q=parseFloat(o.y)/2}if(s>0&&q>0){o.x=s;o.y=q;f.setTransformation(m)}}f.crosshair.lastdelta=A;g=false;return false};var d=function(m){if(!VismoUtils.browser.isIE){jQuery(f.wrapper).addClass("zooming")}if(m.preventDefault){m.preventDefault()}if(m&&m.stopPropagation){m.stopPropagation()}m.cancelBubble=true;if(!b){return false}if(!g){var l=function(){k(m);return false};window.setTimeout(l,50);g=true}return false};var e=this.wrapper;if(VismoUtils.browser.isIE){document.onmousewheel=function(m){if(!m){m=window.event}var l=m.target;if(!l){return}while(l!=e){if(l==e){d(m);return false}l=l.parentNode}return};window.onmousewheel=document.onmousewheel;return}else{if(e.addEventListener){e.onmousewheel=d;e.addEventListener("DOMMouseScroll",d,false)}else{if(e.attachEvent){e.attachEvent("onmousewheel",d)}else{}}}},disable:function(){jQuery(".vismoControls",this.wrapper).css({display:"none"});this.enabled=false},enable:function(){this.enabled=true;jQuery(".vismoControls",this.wrapper).css({display:""})},goodToTransform:function(b){var a=VismoClickingUtils.resolveTarget(b);switch(a.tagName){case"INPUT":return false;case"SELECT":return false;case"OPTION":return false}if(a&&a.getAttribute("class")=="vismoControl"){return false}return true},addMousePanning:function(){this._addEnabledControl("mousepanning");var e=this;var a=e.wrapper;var h=a.onmousedown;var k=a.onmouseup;var d=a.onmousemove;var f=false;var c=100;if(VismoUtils.browser.isIE6){c=300}var b;var j=function(l){if(b){window.clearInterval(b)}f=false;e.transform();if(!VismoUtils.browser.isIE6){jQuery(e.wrapper).removeClass("panning")}e.wrapper.onmousemove=d;return false};jQuery(e.controlDiv).mousedown(function(l){j()});var g=function(n){if(n&&n.shiftKey){return false}if(d){d(n)}if(!e.enabled){return}if(!f){return}if(!VismoUtils.browser.isIE&&!jQuery(e.wrapper).hasClass("panning")){jQuery(e.wrapper).addClass("panning")}if(!e.goodToTransform(n)){return}var q=VismoClickingUtils.getMouseFromEventRelativeToElement(n,f.clickpos.x,f.clickpos.y,f.elem);if(!q){return}var l=e.getTransformation();var p=l.scale;var m=parseFloat(q.x/p.x);var o=parseFloat(q.y/p.y);l.translate.x=f.translate.x+m;l.translate.y=f.translate.y+o;if(!VismoUtils.browser.isIE6){jQuery(e.wrapper).removeClass("zooming")}if(q.x>5||q.y>5){f.isClick=false}if(q.x<5||q.y<5){f.isClick=false}return false};jQuery(this.wrapper).mousedown(function(q){q.preventDefault();var l=jQuery(e.wrapper);if(f){return}if(h){h(q)}if(!e.enabled){return}b=window.setInterval(function(){e.transform()},c);if(!VismoUtils.browser.isIE6){l.addClass("panning")}var p=VismoClickingUtils.resolveTarget(q);p=a;if(!p){return}var n=e.transformation.translate;var r=e.transformation.scale;var o=VismoClickingUtils.getMouseFromEvent(q);if(!o){return}var m=VismoClickingUtils.resolveTargetWithVismo(q);m=a;f={clickpos:o,translate:{x:n.x,y:n.y},elem:m,isClick:true};e.wrapper.onmousemove=g});jQuery(document).mouseup(function(l){l.preventDefault();if(f.isClick&&k){k(l)}if(f){j(l)}});jQuery(document).mousemove(function(m){if(f){g(m);var l=m.target;while(l.parentNode){l=l.parentNode;if(l==e.wrapper){return}}}})},setTransformation:function(b){if(this.limits){if(this.limits.scale){if(b.scale.x>this.limits.scale.x){b.scale.x=this.limits.scale.x}if(b.scale.y>this.limits.scale.y){b.scale.y=this.limits.scale.y}if(b.scale.x<this.limits.scale.minx){b.scale.x=this.limits.scale.minx}if(b.scale.y<this.limits.scale.miny){b.scale.y=this.limits.scale.miny}}}if(!b.origin){var a=jQuery(this.wrapper).width();var c=jQuery(this.wrapper).height();b.origin={x:a/2,y:c/2}}if(this.enabled){if(!b.scale&&!b.translate&&!b.rotate){alert("bad transformation applied - any call to setTransformation must contain translate,scale and rotate")}this.transformation=b;try{this.handler(b)}catch(d){}}},createButtonLabel:function(d,c,f){var b={shape:"path",stroke:this.options.controlStroke,lineWidth:"1","z-index":"2"};b.actiontype=c;var e=[];if(c=="E"){e=[d,0,-d,0,"M",d,0,0,-d,"M",d,0,0,d]}else{if(c=="W"){e=[-d,0,d,0,"M",-d,0,0,d,"M",-d,0,0,-d]}else{if(c=="S"){e=[0,-d,0,d,"M",0,d,-d,0,"M",0,d,d,0]}else{if(c=="N"){e=[0,-d,0,d,"M",0,-d,d,0,"M",0,-d,-d,0]}else{if(c=="in"){e=[-d,0,d,0,"M",0,-d,0,d]}else{if(c=="out"){e=[-d,0,d,0]}}}}}}for(var a=0;a<e.length;a+=2){if(e[a]=="M"){a+=1}e[a]+=f.x;e[a+1]+=f.y}return new VismoShape(b,e)},createButton:function(b,j,d,g){var c=this.controlCanvas;if(!c){throw"no canvas to create on.."}if(!b){b=120}var a=b/2;d={x:d.x||0,y:d.y||0};var k;if(this.options.controlShape&&this.options.controlShape=="circle"){k=[d.x,d.y,b/2];g.shape="circle"}else{k=[d.x,d.y,d.x+b,d.y,d.x+b,d.y+b,d.x,d.y+b];g.shape="polygon"}g.fill=this.options.controlFill;g.stroke=this.options.controlStroke;var e=new VismoShape(g,k);var f=e.getBoundingBox();buttoncenter={x:f.center.x,y:f.center.y};var h=this.createButtonLabel(a-2,g.actiontype,buttoncenter);c.add(h);c.add(e);return e},addControls:function(b){for(var a=0;a<b.length;a++){this.addControl(b[a])}},addControl:function(a){switch(a){case"pan":this.addPanningActions();break;case"zoom":this.addZoomingActions();break;case"mousepanning":this.addMousePanning();break;case"mousewheelzooming":this.addMouseWheelZooming();break;case"rotation":this.addRotatingActions();break;default:break}},addPanningActions:function(a){this._addEnabledControl("pan");this.createButton(12,180,{x:-6,y:-54},{actiontype:"N",name:"pan north",buttonType:"narrow"});this.createButton(12,270,{x:10,y:-38},{actiontype:"E",name:"pan east",buttonType:"earrow"});this.createButton(12,90,{x:-22,y:-38},{actiontype:"W",name:"pan west",buttonType:"warrow"});this.createButton(12,0,{x:-6,y:-20},{actiontype:"S",name:"pan south",buttonType:"sarrow"});this.applyLayer()},addRotatingActions:function(){},addZoomingActions:function(){this._addEnabledControl("zoom");this.createButton(12,180,{x:-6,y:12},{actiontype:"in",name:"zoom in",buttonType:"plus"});this.createButton(12,180,{x:-6,y:42},{actiontype:"out",name:"zoom out",buttonType:"minus"});this.applyLayer()},zoom:function(a,c){var b=this.getTransformation();b.scale.x=a;if(!c){c=a}b.scale.y=c;this.setTransformation(b)},panTo:function(m,k){var n=this.getTransformation();var b=-m;var a=-k;var e,d;var l={};var c={};e=n.translate.x;d=n.translate.y;c.x=e-b;c.y=d-a;l.x=-c.x/5;l.y=-c.y/5;var j=true;var h=this;var g=function(){j={x:false,y:false};if(e>b&&e+l.x>b){e+=l.x;j.x=true}else{if(e<b&&e+l.x<b){e+=l.x;j.x=true}else{n.translate.x=b}}if(d>a&&d+l.y>a){d+=l.y;j.y=true}else{if(d<a&&d+l.y<a){d+=l.y;j.y=true}else{j.x=true;n.translate.y=a}}if(j.x){n.translate.x=e}else{n.translate.x=b}if(j.y){n.translate.y=d}else{n.translate.y=a}if(n.translate.x!=b&&n.translate.y!=a){h.setTransformation(n);window.setTimeout(g,5)}else{h.setTransformation(n)}};g()},transform:function(){if(this.enabled){var b=this.getTransformation();var c=b.scale;var d=b.translate;if(c.x<=0){c.x=0.1125}if(c.y<=0){c.y=0.1125}var a=true;var e=this.limits;if(e.scale){if(c.y<e.scale.miny){b.scale.y=e.scale.miny}if(c.x<e.scale.minx){b.scale.x=e.scale.minx}if(c.y>e.scale.y){b.scale.y=e.scale.y}if(c.x>e.scale.x){b.scale.x=e.scale.x}}this.handler(this.transformation)}},_panzoomClickHandler:function(f,c,a){if(!c){return}var h={};var b=a.getTransformation();if(!b.scale){b.scale={x:1,y:1}}if(!b.translate){b.translate={x:0,y:0}}if(!b.rotate){b.rotate={x:0,y:0,z:0}}var g=b.scale;h.x=parseFloat(this.pansensitivity/g.x);h.y=parseFloat(this.pansensitivity/g.y);switch(c.getProperty("actiontype")){case"W":b.translate.x+=h.x;break;case"O":b.translate.x=0;b.translate.y=0;break;case"E":b.translate.x-=h.x;break;case"N":b.translate.y+=h.y;break;case"S":b.translate.y-=h.y;break;case"in":g.x*=this.options.zoomfactor;g.y*=this.options.zoomfactor;break;case"out":g.x/=this.options.zoomfactor;g.y/=this.options.zoomfactor;break;case"rotatezright":if(!b.rotate.z){b.rotate.z=0}b.rotate.z-=0.1;var d=6.28318531;if(b.rotate.z<0){b.rotate.z=d}break;case"rotatezup":if(!b.rotate.y){b.rotate.y=0}b.rotate.y+=0.1;break;case"rotatezdown":if(!b.rotate.y){b.rotate.y=0}b.rotate.y-=0.1;break;case"rotatezleft":if(!b.rotate.z){b.rotate.z=0}b.rotate.z+=0.1;break;default:break}a.transform();return false}};var VismoGlobe=function(b){var a;for(a in VismoGlobe.prototype){b[a]=VismoGlobe.prototype[a]}b.setGlobeProjection("GLOBE");return b};VismoGlobe.prototype={setGlobeProjection:function(){var b=this;b._fittocanvas=false;this.settings.beforeRender=function(d){b._createGlobe(b.getProjection().getRadius(d.scale))};this.settings.projection={name:"GLOBE",nowrap:true,radius:10,direction:0,init:function(){this.direction=0},getRadius:function(){return this.radius},inversexy:function(e,h,g){var d=this.getRadius(g.scale);var f=VismoMapUtils._undospherify(e,h,g,d);return f},xy:function(e,h,g){var d=this.getRadius(g.scale);if(!d||!e||!h||!g){return{x:e,y:h}}var f=VismoMapUtils._spherifycoordinate(e,h,g,d);return f}};var c=parseInt(b.wrapper.style.height)/2;var a=parseInt(b.wrapper.style.width)/2;if(a>c){this.settings.projection.radius=c}else{this.settings.projection.radius=a}},toggleSpin:function(){var b=this;var a=function(){var c=b.controller.transformation;if(!c.rotate){c.rotate={}}if(!c.rotate.z){c.rotate.z=0}c.rotate.z+=0.3;b.controller.setTransformation(c);window.setTimeout(a,600)};a()},_createGlobe:function(a){if(VismoUtils.browser.isIE){return}var c=this.vismoClicking.canvas.getContext("2d");if(!c){return}var d=this.controller.transformation;var f=d.translate;var e=d.scale;var g=d.origin;c.save();c.translate(g.x,g.y);c.scale(e.x,e.y);c.translate(f.x,f.y);var b=c.createRadialGradient(0,0,10,0,0,a);b.addColorStop(0,"#AFDCEC");b.addColorStop(0.5,"#00C9FF");b.addColorStop(1,"#00B5E2");b.addColorStop(1,"rgba(0,201,255,0)");c.beginPath();c.arc(0,0,a,0,Math.PI*2,true);c.closePath();c.fillStyle=b;c.fill();c.restore()}};var VismoSlippyMap=function(a){this.loadedurls={};this.tileserverurl="http://tile.openstreetmap.org/";this.setupSlippyStaticMapLayer(a);a.oldDrawFromGeojson=a.drawFromGeojson;a.drawFromGeojson=function(c,b){a.oldDrawFromGeojson(c,false)};return a};VismoSlippyMap.prototype={getGoogleMercatorProjection:function(b){var c={};c.source=new Proj4js.Proj("WGS84");c.dest=new Proj4js.Proj("GOOGLE");c.resultCache={};var a=this;c.getTileServerUrl=function(){return a.tileserverurl};c.tilesize=256;c.googleHack=1/((2*Math.PI*6378137)/c.tilesize);c.inversexy=function(d,g){d/=this.googleHack;g/=this.googleHack;var e=new Proj4js.Point(d,g);var f=Proj4js.transform(c.dest,c.source,e);return f};c.calculatescalefactor=function(f,e){if(!e){if(f<=1){return 0}else{e=0}}if(f<=1){return e}else{var d=f/2;e+=1;return this.calculatescalefactor(d,e)}};c.xy=function(d,k,f){if(this.resultCache[d+"|"+k]){return this.resultCache[d+"|"+k]}var e=new Proj4js.Point(d,k);var g=Proj4js.transform(c.source,c.dest,e);var j=g.x;var h=g.y;j*=this.googleHack;h*=this.googleHack;this.resultCache[d+"|"+k]={x:j,y:h};return this.resultCache[d+"|"+k]};return c},setupSlippyStaticMapLayer:function(f){var a=this.getGoogleMercatorProjection(f);f.setTransparency(0.7);f.settings.projection=a;var c=this;var d=parseInt(f.wrapper.style.height);var e=parseInt(f.wrapper.style.width);var g={x:e/a.tilesize+1,y:(d/a.tilesize)+1};var b=this._createTiles(f,g.x,g.y);var f=f;f.settings.afterRender=function(v){var L=v.origin;jQuery(c.tilesWrapper).css({top:L.y,left:L.x});var A=false;if(f.settings.lastScale>v.scale.x){A=true}f.settings.lastScale=v.scale.x;var u=0,t=0,s,E,w=v.translate,N=v.scale;f.wrapper.style.backgroundImage="none";var D=a.calculatescalefactor(N.x);var G=parseInt(f.wrapper.style.height);var z=parseInt(f.wrapper.style.width);var M=b.main;var m=(N.x*w.x);var B=(N.y*w.y);B+=(L.y-128);m+=(L.x-128);M.style.top=B+"px";M.style.left=m+"px";if(D==0){var I;for(I in b){b[I].style.backgroundImage="none"}D=0;J=0;H=0;var h=a.getTileServerUrl()+D+"/"+J+"/"+H+".png";c.renderTile(h,D,J,H,M)}else{b.main.style.backgroundImage="none";var K={x:(w.x),y:(w.y)};K.x*=N.x;K.y*=N.y;K.x+=(L.x);K.y+=(L.y);var k=K.x;var o=K.y;k=K.x%256;o=K.y%256;if(o>0){o-=256}if(o<-256){o+=256}if(k<-256){k+=256}if(k>0){k-=256}var l;l=VismoMapUtils.getLongLatAtXY(k+128,o+128,f);var F=VismoMapUtils.getSlippyTileNumber(l.longitude,l.latitude,D,f);for(var q=0;q<g.x;q++){for(var n=0;n<g.y;n++){var j=q;var p=n;var r=q+"|"+n;var M=b[r];var B=o+(256*n);var m=k+(256*q);var J=F.x+q;var H=F.y+n;var C=Math.pow(2,D);if(J<0){J=C+J}if(H<0){H=C+H}if(J>=C){J-=C}if(H>=C){H-=C}M.style.left=m+"px";M.style.top=B+"px";M.title=D+"/"+J+"/"+H;var h="http://tile.openstreetmap.org/"+D+"/"+J+"/"+H+".png";c.renderTile(h,D,J,H,M)}}}}},renderTile:function(b,c,k,j,h){var f=this;var a=function(e){h.style.backgroundImage="none";var m="url('"+e+"')";if(m==h.style.backgroundImage){return}h.style.backgroundImage=m};var l=function(e){var m="url('"+e+"')";h.style.backgroundImage="none";if(m==h.style.backgroundImage){return}h.style.backgroundImage=m};try{var d=c+"_"+k+"_"+j+".png";if(d!=h.style.backgroundImage){if(f.loadedurls[d]){a(d)}else{h.style.backgroundImage="none";VismoFileUtils.saveImageLocally(b,d,a,l);f.loadedurls[d]=true}}}catch(g){h.style.backgroundImage="none"}},_createTiles:function(f,j,h){var d={};var k=document.createElement("div");k.style.overflow="hidden";k.className="VismoTileWrapper";k.style.position="absolute";k.style.width=f.wrapper.style.width;k.style.height=f.wrapper.style.height;var a=document.createElement("div");a.style.position="absolute";a.style.width="256px";a.style.height="256px";k.appendChild(a);for(var e=0;e<h;e++){for(var g=0;g<j;g++){var c=document.createElement("div");c.className="tile_"+g+"_"+e;c.style.position="absolute";c.style.width="256px";c.style.height="256px";var b=g+"|"+e;k.appendChild(c);d[b]=c}}f.wrapper.appendChild(k);d.main=a;return d}};var VismoMapUtils={googlelocalsearchurl:"http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=",optimiseForIE6:function(a){var e=[];for(var g=0;g<a.features.length;g++){var k=a.features[g];var m=k.geometry.coordinates;var h=[];var b=false;if(m.length<2){b=true}for(var c=0;c<m.length;c++){var d=m[c]}var l=k.geometry.bbox;if(l){var o=l[2]-l[0];var n=l[3]-l[1];if(n<0){n=-n}if(o<0){o=-o}if(o<1||n<1){b=false}}if(b){e.push(k)}}a.features=e;return a},addBoundingBoxes:function(a){var v=a;for(var p=0;p<a.features.length;p++){var r=a.features[p];var q=r.geometry;var s=q.coordinates;if(q.type.toLowerCase()=="multipolygon"){var e,z,d,u;var b={belowzero:0,abovezero:0};var m={belowzero:0,abovezero:0};for(var o=0;o<s.length;o++){for(var n=0;n<s[o].length;n++){for(var h=0;h<s[o][n].length;h++){var w=s[o][n][h][0];var t=s[o][n][h][1];if(!e){e=w}if(!d){d=w}if(!z){z=t}if(!u){u=t}if(t>u){u=t}if(t<z){z=t}if(w<e){e=w}if(w>d){d=w}if(w>0){b.abovezero+=1}else{b.belowzero+=1}if(t>0){m.abovezero+=1}else{m.belowzero+=1}}}}q.bbox=[];q.bbox.push(e);q.bbox.push(z);q.bbox.push(d);q.bbox.push(u);e=false;d=false;z=false;u=false}}return v},tile2long:function(a,b){return(a/Math.pow(2,b)*360-180)},tile2lat:function(c,a){var b=Math.PI-2*Math.PI*c/Math.pow(2,a);return(180/Math.PI*Math.atan(0.5*(Math.exp(b)-Math.exp(-b))))},getLongLatAtXY:function(a,d,c){var b=VismoMapUtils.getLongLatFromMouse(a,d,c);return b},getSlippyTileNumber:function(b,e,d,f){var g=Math.pow(2,d);var a=b;var c=((b+180)/360)*g;c=Math.floor(c);tiley=(Math.floor((1-Math.log(Math.tan(e*Math.PI/180)+1/Math.cos(e*Math.PI/180))/Math.PI)/2*Math.pow(2,d)));return{x:c,y:tiley}},getLocationsFromQuery:function(query,callback){var that=this;var fileloadedcallback=function(status,params,responseText,url,xhr){var response=eval("("+responseText+")");if(response.responseStatus==200){var results=response.responseData.results;callback(results);return}};VismoFileUtils.loadRemoteFile(that.googlelocalsearchurl+query,fileloadedcallback)},getLongLatFromMouse:function(a,g,b){var c=b.getTransformation();var f=VismoClickingUtils.undotransformation(a,g,c);if(b.settings.projection){f=b.settings.projection.inversexy(f.x,f.y,c)}var d=f.x;var e=-f.y;return{latitude:e,longitude:d}},_radToDeg:function(a){return a/(Math.PI/180)},_degToRad:function(a){return(a*Math.PI)/180},fitgeojsontocanvas:function(u,a){var m={};var t=u.features;for(var s=0;s<t.length;s++){var w=t[s].geometry.coordinates;for(var r=0;r<w.length;r++){for(var q=0;q<w[r].length;q++){for(var p=0;p<w[r][q].length;p++){var d=w[r][q][p][0];var b=w[r][q][p][1];if(!m.x1||d<m.x1){m.x1=d}else{if(!m.x2||d>m.x2){m.x2=d}}if(!m.y1||b<m.y1){m.y1=b}else{if(!m.y2||b>m.y2){m.y2=b}}}}}}if(!u.transform){u.transform={}}if(!u.transform.scale){u.transform.scale={x:1,y:1}}if(!u.transform.translate){u.transform.translate={x:0,y:0}}var o=parseFloat(a.style.width);var n=parseFloat(a.style.height);m.center={};m.width=(m.x2-m.x1);m.height=(m.y2-m.y1);m.center.x=m.x2-(m.width/2);m.center.y=m.y2-(m.height/2);var z=1,v;var h=parseFloat(o/m.width);var e=parseFloat(n/m.height);if(h<e){v=h}else{v=e}var g={scale:{},translate:{}};g.scale.x=v;g.scale.y=v;g.boundingBox=m;g.translate.x=-m.center.x;g.translate.y=m.center.y;return g},_testCanvas:function(a){a.beginPath();a.arc(75,75,50,0,Math.PI*2,true);a.moveTo(110,75);a.arc(75,75,35,0,Math.PI,false);a.moveTo(65,65);a.arc(60,65,5,0,Math.PI*2,true);a.moveTo(95,65);a.arc(90,65,5,0,Math.PI*2,true);a.stroke()},_undospherify:function(k,f,j,d){var g=this._spherifycoordinate(k,f,j);var h=Math.asin(f/d);var a=Math.asin(parseFloat(k/d)/Math.cos(h));if(j.rotate){var b=j.rotate.z;a+=b}var c=VismoMapUtils._radToDeg(a);var e=VismoMapUtils._radToDeg(h);return{x:c,y:e}},_spherifycoordinate:function(c,h,k,f){var l=VismoMapUtils;var g={};var b=VismoMapUtils._degToRad(c);var j=VismoMapUtils._degToRad(h);var e=false;if(k&&k.rotate){var m=k.rotate.z;if(m){var a=parseFloat(m);var d=parseFloat(b+a);b+=a}if(k.rotate.y){j+=parseFloat(k.rotate.y)}}b=b%6.28318531;g.y=(f)*Math.sin(j);if(b<1.57079633||b>4.71238898){g.x=(f)*Math.cos(j)*Math.sin(b)}else{g.x=false}return g}};var VismoConversion={niaveGeoJsonFlatten:function(a,b){var o=a;var d=0;for(var h=0;h<o.features.length;h++){var m=o.features[h].geometry;if(m.type=="MultiPolygon"){for(var s=0;s<m.coordinates.length;s++){for(var f=0;f<m.coordinates[s].length;f++){var n=[];var l=0;if(m.coordinates[s][f].length>50){for(var e=0;e<m.coordinates[s][f].length;e++){var p=m.coordinates[s][f][e];if(l==0){var r=parseFloat(p[0]);var q=parseFloat(p[1]);n.push([r,q]);l=b}else{l-=1}}d+=(m.coordinates[s][f].length-n.length);m.coordinates[s][f]=n}}}}}console.log(d,"dropped");return o},svgToGeoJson:function(a,c){var b=VismoFileUtils._getXML(a);var d=VismoMapSVGUtils.convertSVGToMultiPolygonFeatureCollection(b);return d},_kmlPolygonToFeature:function(u,v){var b=[];var p=u.childNodes;for(var j=0;j<p.length;j++){var f=true;if(p[j].tagName=="outerBoundaryIs"){var c=p[j].childNodes;for(var h=0;h<c.length;h++){if(c[h].tagName=="LinearRing"){var g=c[h].childNodes;for(var e=0;e<g.length;e++){if(g[e].tagName=="coordinates"){var r=VismoFileUtils.getChildNodeValue(g[e]);r=r.trim();var s=r.split(" ");for(var d=0;d<s.length;d+=1){var t=s[d].split(",");var a=parseFloat(t[0]);var q=parseFloat(t[1]);var o=parseFloat(t[2]);b.push([a,q])}if(s.length==0){return false}else{f=false}v.geometry.coordinates.push([b])}}}}}}if(!v){f=true}else{if(v.geometry.coordinates[0].length==0){f=true}else{if(v.geometry.coordinates[0][0].length==1){f=true}}}if(f){return false}else{return v}},kmlToGeoJson:function(l){var a={type:"FeatureCollection",features:[]};var g=VismoFileUtils._getXML(l);var h=g.getElementsByTagName("Placemark");for(var f=0;f<h.length;f++){var o={type:"Feature",geometry:{type:"MultiPolygon",coordinates:[]},properties:{name:"georss"}};var m=h[f].childNodes;for(var e=0;e<m.length;e++){var c=false;if(m[e].tagName=="name"&&m[e].firstChild){o.properties.name=m[e].firstChild.nodeValue}if(m[e].tagName=="Polygon"){var n=this._kmlPolygonToFeature(m[e],o);if(n){o=n}else{c=true}}if(m[e].tagName=="MultiGeometry"){var b=m[e].childNodes;for(var d=0;d<b.length;d++){if(b[d].tagName=="Polygon"){var n=this._kmlPolygonToFeature(b[d],o);if(n){o=n}else{c=true}}}}}if(!c&&o&&o.geometry.coordinates.length>0){a.features.push(o)}}return a},geoRssToGeoJson:function(l){var b={type:"FeatureCollection",features:[]};var h=VismoFileUtils._getXML(l);var m=h.getElementsByTagName("item");for(var g=0;g<m.length;g++){var r={type:"Feature",geometry:{type:"MultiPolygon",coordinates:[]},properties:{name:"georss"}};var d=false;var n=m[g].childNodes;for(var f=0;f<n.length;f++){if(n[f].tagName=="title"&&n[f].firstChild){r.properties.name=n[f].firstChild.nodeValue}if(n[f].tagName=="description"&&n[f].firstChild){r.properties.description=n[f].firstChild.nodeValue}if(n[f].tagName=="georss:polygon"){var c=[];var p=VismoFileUtils.getChildNodeValue(n[f]);p=p.trim();p=p.replace(/  +/g," ");p=p.replace(/\n/g,"");var q=p.split(" ");if(q[0]!=q[q.length-2]|q[1]!=q[q.length-1]){q.push(q[0]);q.push(q[1])}for(var e=0;e<q.length-1;e+=2){var o=parseFloat(q[e]);var a=parseFloat(q[e+1]);c.push([a,o])}r.geometry.coordinates.push([c])}}if(!d){b.features.push(r)}else{}}return b}};var VismoClickingUtils={inVisibleArea:function(b,a){var c=a.getBoundingBox();return true},scrollXY:function(){var b=0,a=0;if(typeof(window.pageYOffset)=="number"){a=window.pageYOffset;b=window.pageXOffset}else{if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){a=document.body.scrollTop;b=document.body.scrollLeft}else{if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){a=document.documentElement.scrollTop;b=document.documentElement.scrollLeft}}}return{x:b,y:a}},getRealXYFromMouse:function(c,a){var b=VismoClickingUtils.getMouseFromEvent(c);b=VismoClickingUtils.undotransformation(b.x,b.y,a);return b},undotransformation:function(a,c,b){return VismoTransformations.undoTransformation(a,c,b)},resolveTarget:function(c){if(!c){c=window.event}var b;if(c&&c.srcElement){b=c.srcElement}else{if(c.target){b=c.target}else{b=false}}try{var a=b.parentNode}catch(c){return false}return b},getMouseFromEvent:function(d,c){if(!d){d=window.event}if(!c){var c=this.resolveTargetWithVismo(d);if(!c){return false}}var f=jQuery(c).offset();var b;if(typeof(f.left)!="number"){return false}var a=this.scrollXY(d);x=d.clientX+a.x;y=d.clientY+a.y;x-=f.left;y-=f.top;return{x:x,y:y}},getMouseFromEventRelativeToTarget:function(c,b){if(!c){c=window.event}if(!b){return false}var d=jQuery(b).offset();if(!d.left){return false}var a=this.scrollXY();x=c.clientX+a.x-d.left;y=c.clientY+a.y-d.top;return{x:x,y:y}},resolveTargetWithVismo:function(c){var b=VismoClickingUtils.resolveTarget(c);if(!b){return false}var a=false;while(!a&&b!=document&&b.parentNode&&b.parentNode!=document){if(b.vismoCanvas||b.vismoController||b.vismoClicking){a=true}else{b=b.parentNode}}if(!b){return false}return b},getMouseFromEventRelativeToElement:function(d,b,h,c){if(!d){d=window.event}var f=jQuery(c).offset();if(f.left===false){return false}var a=this.scrollXY();oldx=d.clientX+a.x-f.left;oldy=d.clientY+a.y-f.top;var g={x:oldx,y:oldy};if(!g){return false}g.x-=b;g.y-=h;return g},getMouseFromEventRelativeTo:function(b,a,d){var c=this.getMouseFromEvent(b);if(!c){return false}c.x-=a;c.y-=d;return c},getMouseFromEventRelativeToElementCenter:function(d){var a,b;var c=this.resolveTargetWithVismo(d);if(!c){return}if(c.style.width){a=parseInt(c.style.width)}else{if(c.width){a=parseInt(c.width)}}if(c.style.height){b=parseInt(c.style.height)}else{if(c.height){b=parseInt(c.height)}}if(!a||!b){throw"target has no width or height (vismomaputils)"}return this.getMouseFromEventRelativeTo(d,a/2,b/2)}};var Vismo={store:{Canvas:{}}};var VismoCanvas=function(b,d){if(!VismoUtils.browser.isIE6){this._renderSpeed=5}this._referenceid=Math.random();Vismo.store.Canvas[this._referenceid]=this;this._lastTransformation={scale:{}};if(b.length){var j=[];for(var r=0;r<b.length;r++){var h=new VismoCanvas(b[r],d);j.push(h)}return h}this.className="VismoCanvas";this._idtoshapemap={};if(!d){d={}}if(typeof b=="string"){b=document.getElementById(b)}if(!b){throw"Element doesn't exist!"}var n=jQuery(b).width();var o=jQuery(b).height();b.style.width=n;b.style.height=o;if(b.vismoClicking){var g=b.vismoClicking;return g}if(!d.pointsize){d.pointsize=5}this.id=b.id;this.options=d;var e=b;this.settings={};this.settings.browser=!VismoUtils.browser.isIE?"good":"ie";this.settings.globalAlpha=1;var c;var q;if(this.settings.browser=="good"){c=document.createElement("canvas");c.className="VismoCanvasRenderer";q=document.createElement("div");q.appendChild(c)}else{var m=jQuery(".VismoIECanvas",e);if(m.length>0){c=m[0];jQuery(c).addClass("VismoCanvasRenderer");q=c.parentNode;this._flag_load_existing_vml=true}else{q=document.createElement("div");c=document.createElement("div");c.className="VismoIECanvas VismoCanvasRenderer";q.appendChild(c)}c.style.setAttribute("cssText","position:absolute;left:0px;top:0px;",0)}var p=parseInt(e.style.width);var l=parseInt(e.style.height);c.width=p;c.height=l;var a=this;this.wrapper=e;if(d.vismoController){if(!d.vismoController.handler){d.vismoController.handler=function(u){if(a.memory.length>0){a.transform(u)}}}this.vismoController=new VismoController(this.getDomElement(),d.vismoController)}else{this.setTransformation({translate:{x:0,y:0},scale:{x:1,y:1},origin:{x:n/2,y:o/2}})}if(!b.className){b.className="VismoCanvas"}jQuery(c).css({width:p,height:l,"z-index":1,position:"absolute"});b.appendChild(q);jQuery(q).css({width:p,height:l,position:"absolute",overflow:"hidden",left:"0px",top:"0px"});var s=document.createElement("div");jQuery(s).css({position:"absolute",width:"100%",height:"100%","z-index":9});s.className="VismoLabels";q.appendChild(s);this.labelHolder=s;this.labels=[];this.canvas=c;this.memory=[];b.vismoClicking=true;jQuery(this.canvas).mousedown(function(t){t.preventDefault()});this._setupMouse();this.mouse({down:d.mousedown,up:d.mouseup,move:d.move,dblclick:d.dblclick,keypress:d.keypress});var k;if(d.tooltipfunction){if(typeof d.tooltipfunction=="boolean"){k=function(u,t){if(t){u.innerHTML="cool"+t.getProperty("id")}}}else{k=d.tooltipfunction}this.addTooltip(k)}if(d.shapes){for(var r=0;r<d.shapes.length;r++){this.add(d.shapes[r])}this.render()}var f=this;jQuery(window).unload(function(){f.labelHolder=null;f.canvas=null;f.tooltip=null;f.wrapper=null;q=null})};VismoCanvas.prototype={_renderSpeed:100,teardown:function(){VismoUtils.scrubNode(this.canvas);VismoUtils.scrubNode(this.labelHolder);jQuery(this.canvas).unbind("mousedown");this.wrapper.onmouseout=null;this.wrapper.onmouseover=null},getDomElement:function(a){return this.wrapper},addTooltip:function(d){var h=arguments[0];var g=this.wrapper;if(h){this.tooltipAddContent=h}if(!this.tooltip){var f=document.createElement("div");jQuery(f).css({position:"absolute","z-index":1000,display:"none"});f.className="VismoTooltip";jQuery(f).mousedown(function(j){j.preventDefault();if(g&&g.onmousedown){g.onmousedown(j)}});jQuery(f).mousemove(function(j){j.preventDefault()});jQuery(this.wrapper).parent().append(f);this.tooltip=f;jQuery(window).unload(function(){e.tooltip=false})}if(!this.tooltipAdded){var a=this.onmousemove;var e=this;var c;var b=function(m,k){if(!m){m=window.event}if(!e.tooltip){return}jQuery(e.tooltip).html("");if(k&&c!=k){var o=k.getBoundingBox();if(e.tooltipAddContent){e.tooltipAddContent(e.tooltip,k)}var p=VismoTransformations.applyTransformation(o.x2,o.y1,e.getTransformation());var j=jQuery(e.wrapper).width();var l=jQuery(e.wrapper).height();var n=jQuery(e.wrapper).offset();if(p.x>n.left+j){p.x=n.left+j}}if(e.tooltipAddContent&&k){e.tooltipAddContent(e.tooltip,k);c=k;jQuery(e.tooltip).css({display:""})}else{jQuery(e.tooltip).css({display:"none"})}if(a){a(m,k)}};this.onmousemove=b;this.tooltipAdded=true}},getXYWindow:function(a){var c=arguments[0];var b=this.getTransformation();var d=this.getXY(c);return VismoTransformations.applyTransformation(d.x,d.y,b)},getXY:function(a){var b=arguments[0];return VismoTransformations.getXY(b,this.getTransformation())},mouse:function(a){if(!a){return{up:this.onmouseup,down:this.onmousedown,move:this.onmousemove,dblclick:this.ondblclick,keypress:this.onkeypress}}else{var a=arguments[0];if(a.down){this.onmousedown=a.down}if(a.up){this.onmouseup=a.up}if(a.move){this.onmousemove=a.move}if(a.dblclick){this.ondblclick=a.dblclick}if(a.keypress){this.onkeypress=a.keypress}}},_setupMouse:function(a){var c=this;this.onmousedown=function(g,f,h){};this.onmouseup=function(g,f,h){};this.onmousemove=function(g,f,h){};this.ondblclick=function(g,f,h){};this.onkeypress=function(f){};this._applyMouseBehaviours(this.wrapper);for(var b=0;b<this.wrapper.childNodes.length;b++){var d=this.wrapper.childNodes[b]}},_applyMouseBehaviours:function(b){var d=arguments[0];var e=this;var c=function(g){var f=e.getShapeAtClick(g,d);return f};var a=function(h){var l=h.onmousedown;var g=h.onmouseup;var f=h.onmousemove;var k=h.ondblclick;this.initialKeyPress=window.onkeypress;h.onmouseover=function(m){if(!e.keypressactive){e.keypressactive=true;window.onkeypress=function(n){e.onkeypress(n);if(e.initialKeyPress){e.initialKeyPress(n)}};document.onkeypress=function(o){if(!o){o=window.event}if(e.initialKeyPress){e.initialKeyPress(o)}if(!o){o=window.event}var n=c(o);if(e.onkeypress){e.onkeypress(o,n)}}}};h.onmouseout=function(m){if(!m){m=window.event}e.keypressactive=false};jQuery(h).mousedown(function(n){var m=c(n);if(m){if(m.getProperty("onmousedown")){m.getProperty("onmousedown")(n,m);if(e.onmousedown){e.onmousedown(n,m)}}else{if(e.onmousedown){e.onmousedown(n,m)}}}else{if(e.onmousedown){e.onmousedown(n,m)}if(l){l(n,m)}}});jQuery(h).dblclick(function(n){if(!n){n=window.event}var m=c(n);if(m){if(m.getProperty("ondblclick")){m.getProperty("ondblclick")(n,m)}else{if(e.ondblclick){e.ondblclick(n,m)}else{}}}else{if(e.ondblclick){e.ondblclick(n,m)}if(k){k(n,m)}}});jQuery(h).mouseup(function(n){var m=c(n);if(m){if(m.getProperty("onmouseup")){m.getProperty("onmouseup")(n,m);if(e.onmouseup){e.onmouseup(n,m)}}else{if(e.onmouseup){e.onmouseup(n,m)}}}else{if(e.onmouseup){e.onmouseup(n,m)}if(g){g(n,m)}}});var j;jQuery(h).mousemove(function(o){if(!o){o=window.event}var n=c(o);if(!VismoUtils.browser.isIE){if(jQuery(h).hasClass("overVismoShape")){jQuery(h).removeClass("overVismoShape")}}if(!VismoUtils.browser.isIE){if(jQuery(h).hasClass("overVismoPoint")){jQuery(h).removeClass("overVismoPoint")}}if(n&&!n.getProperty("unclickable")){if(e.ondblclick||e.onmousedown||e.onmouseup){var m;if(n){m=n.getShape();if(!VismoUtils.browser.isIE&&m=="point"){jQuery(h).addClass("overVismoPoint")}}if(!VismoUtils.browser.isIE&&!jQuery(h).hasClass("panning")&&!jQuery(h).hasClass("zooming")){jQuery(h).addClass("overVismoShape")}}if(n.getProperty("onmousemove")){n.getProperty("onmousemove")(o,n)}}else{}if(e.onmousemove){e.onmousemove(o,n)}if(f){f(o,n)}})};a(d)},getDimensions:function(a){return{width:this.width(),height:this.height()}},height:function(){var b=this.canvas;if(!b){return -1}var a=parseInt(b.style.height);if(a){return a}else{return -1}},width:function(){var b=this.canvas;if(!b){return -1}var a=parseInt(b.style.width);if(a){return a}else{return -1}},resize:function(b){var d=arguments[0];var a=arguments[1];if(!a){a=jQuery(this.wrapper).height()}if(!d){d=jQuery(this.wrapper).width()}if(this.canvas.getAttribute("width")){this.canvas.width=d;this.canvas.height=a}jQuery(this.hideoverflow).css({height:a,width:d});jQuery(this.wrapper).css({height:a,width:d});jQuery(this.canvas).css({height:a,width:d});if(this.vismoController){var c=this.vismoController.getTransformation();c.origin.x=d/2;c.origin.h=a/2;this.vismoController.setTransformation(c)}},setTransparency:function(a){var b=arguments[0];this.settings.globalAlpha=b},_setupCanvasEnvironment:function(b){if(VismoUtils.browser.isIE){return}var a=this.canvas.getContext("2d");var c=this.getTransformation().scale;if(c&&c.x){a.lineWidth=(0.5/c.x)}a.globalAlpha=this.settings.globalAlpha;a.clearRect(0,0,this.canvas.width,this.canvas.height);a.lineJoin="round"},clear:function(b){var c=arguments[0];if(c){this.clearMemory()}this._maxX=0;this._maxY=0;if(this.canvas&&!this.canvas.getContext){return}jQuery(".VismoLabels",this.wrapper).html("");this.setTransformation(this.getTransformation());var a=this.canvas.getContext("2d");a.clearRect(0,0,this.canvas.width,this.canvas.height)},ie_render:function(b){var v=arguments[0];VismoTimer.start("VismoCanvas.ie_render");var g=this;var l=this.getTransformation();if(this.options.beforeRender){this.options.beforeRender(this)}if(l.scale.x){sc=l.scale.x}else{sc=1}var r=this.options.pointsize/parseFloat(sc);tran=l;var p=tran.origin,m=tran.translate,n=tran.scale;jQuery(this.canvas).css({left:p.x+(m.x*n.x),top:p.y+(n.y*m.y),zoom:n.x});var f=g.memory;var h=false;var c;if(g.canvas.childNodes.length==0){h=true;c=document.createElement("div")}else{c=g.canvas}var k=this._lastTransformation.scale;var q=this._lastTransformation.shapes;var a=f.length;if(k.x===n.x&&k.y===n.y&&a==q){tran=false}var u=g.settings.globalAlpha;var d=0;var e={width:this.width(),height:this.height()};var j=function(){var t=20;for(var s=d;s<d+t;s++){var w=f[s];if(!w){break}var o=w.properties.shape;if(o=="domElement"){tran=l}w.render(g.canvas,tran,v,true,null,e);if(w.vmlfill&&!w.vmlfill.opacity&&u){w.vmlfill.opacity=u}}g._lastTransformation={scale:{x:n.x,y:n.y},shapes:a};if(h){g.canvas.appendChild(c.cloneNode(true))}d+=t;if(d<a){window.setTimeout(j,g._renderSpeed)}};(function(){j()})();VismoTimer.end("VismoCanvas.ie_render")},canvas_render:function(h){var g=arguments[0];this.render=this.canvas_render;var f=this;var k=this.getTransformation();if(this.options.beforeRender){this.options.beforeRender(this)}if(k.scale.x){sc=k.scale.x}else{sc=1}var b=this.options.pointsize/parseFloat(sc);var m;var l=f.getMemory();this._setupCanvasEnvironment();var p=f.canvas.getContext("2d");p.save();tran=false;if(k){var c=k.origin;var j=k.translate;var q=k.scale;var a=k.rotate;if(c&&q&&j){if(typeof(c.x)=="number"){p.translate(c.x,c.y)}if(typeof(q.x)=="number"){p.scale(q.x,q.y)}if(typeof(j.x)=="number"){p.translate(j.x,j.y)}}if(a&&a.x){p.rotate(a.x)}}m=f.canvas;for(var d=0;d<l.length;d++){var e=l[d];var n=e.getShape();if(e.optimise(f.canvas,k,g)){if(n=="domElement"){tran=k}e.render(f.canvas,tran,g,true,f.settings.browser);if(e.vmlfill&&f.settings.globalAlpha){e.vmlfill.opacity=f.settings.globalAlpha}}}if(p){p.restore()}},render:function(b){var a=arguments[0];if(this.settings.browser=="good"){this.canvas_render(a)}else{this.ie_render(a)}},getTransformation:function(c){if(!this.transformation){var b=parseInt(this.canvas.style.width);var a=parseInt(this.canvas.style.height);this.transformation={scale:{x:1,y:1},translate:{x:0,y:0},origin:{x:b/2,y:a/2}}}return this.transformation},setTransformation:function(a){var d=arguments[0];this._transformLabels(d);if(!d.origin){d.origin={};d.origin.x=jQuery(this.wrapper).width()/2;d.origin.y=jQuery(this.wrapper).height()/2}if(d){this.transformation=d}var b=d.translate,c=d.scale;d.cache={id1:[c.x,",",c.y].join(""),id2:[b.x,",",b.y].join("")}},_transformLabels:function(a){var d=a.translate;var c=a.scale;var b={x:this.width()/2,y:this.height()/2};jQuery(this.labelHolder).css({top:parseInt(d.y*c.y),left:parseInt(d.x*c.x)});this._eachLabel(function(m){var e=jQuery(m);var n=e.attr("v_x");var k=e.attr("v_y");if(!n||!k){return}else{n=parseInt(n);k=parseInt(k)}var o=parseFloat(e.attr("v_w"))*c.x;var j=parseFloat(e.attr("v_h"))*c.y;var g=b.x+(n*c.x);var p=b.y+(k*c.y);var f={top:p,left:g};e.css(f)})},_eachLabel:function(b){var c=jQuery("*",this.labelHolder);for(var a=0;a<c.length;a++){b(c[a])}},centerOn:function(a,d,b){var c=this.getTransformation();c.translate.x=-a;c.translate.y=-d;if(this.vismoController){this.vismoController.setTransformation(c)}else{this.setTransformation(c)}this.render()},remove:function(c){var b=arguments[0];var a=this.getMemory();for(var d=0;d<a.length;d++){if(a[d]==b){this.memory.splice(d,1)}}if(b.vml){b.vml.scrub()}var e=b.properties.id;delete this._idtoshapemap[e]},add:function(c){var b=arguments[0];this.needsSort=true;if(!b._isVismoShape){b=new VismoShape(b)}if(b.properties.shape=="point"){b.setDimensions(this.options.pointsize,this.options.pointsize)}if(!this.memory){this.memory=[]}b.vismoCanvas=this;if(!b.getProperty("id")){var a=this.memory.length+"_"+Math.random();b.setProperty("id",a)}b._canvasref=this._referenceid;var d=b.properties.id;this.memory.push(b);this._idtoshapemap[d]=b;b._vismoClickingID=d;return b},clearLabels:function(){jQuery(this.labelHolder).html("")},addLabel:function(f){var b=arguments[0];var k=arguments[1];var g=arguments[2];var e=arguments[3];jQuery(b).addClass("canvasLabel");this.labelHolder.appendChild(b);var c=jQuery(b).height();var l=jQuery(b).width();var j,a;a=k+(this.width()/2)+l/2;j=(this.height()/2)+g+c/2;jQuery(b).attr("v_x",k);jQuery(b).attr("v_y",g);jQuery(b).attr("v_w",l);jQuery(b).attr("v_h",c);jQuery(b).css({position:"absolute",top:j,left:a});var d=this;jQuery(b).dblclick(function(h){d.ondblclick(h,e)});jQuery(b).mouseup(function(h){d.onmouseup(h,e)});jQuery(b).mousedown(function(h){d.onmousedown(h,e)})},transform:function(a){var b=arguments[0];this.setTransformation(b);this.render()},clearMemory:function(a){for(var b=0;b<this.memory.length;b++){if(this.memory[b].vml){this.memory[b].vml.scrub()}}this._idtoshapemap={};this.memory=[];this.clearLabels()},getMemory:function(a){if(this.needsSort){this.memory=this.memory.sort(function(d,c){var h=d.getProperty("z-index");var g=c.getProperty("z-index");if(h<g){return -1}else{if(h==g){var f=d.getBoundingBox();var e=c.getBoundingBox();return(e.width*e.height)>(f.width*f.height)}else{return 1}}});this.needsSort=false}return this.memory},getMemoryID:function(b){var a=arguments[0];if(a&&a._vismoClickingID){return a._vismoClickingID}else{return false}},getShapeWithID:function(a){var c=arguments[0];var b=this.getMemory();if(this._idtoshapemap[c]){return this._idtoshapemap[c]}else{return false}},getShapeAtClick:function(h){var d=arguments[0];var a=arguments[1];if(!d){d=window.event}var b=VismoClickingUtils.resolveTarget(d);if(b&&b.tagName){if(b.tagName.toUpperCase()=="SHAPE"){if(b._vismoClickingID){var g=this.getShapeWithID(b._vismoClickingID);if(g){return g}}}}var f=VismoClickingUtils.resolveTargetWithVismo(d);if(a){f=a}if(!f){return}var c=jQuery(f).offset();var k=VismoClickingUtils.scrollXY();x=d.clientX+k.x-c.left;y=d.clientY+k.y-c.top;if(this.memory.length>0){var g=false;if(f.vismoClicking){var j=VismoTransformations.undoTransformation(x,y,this.transformation);x=j.x;y=j.y;g=this.getShapeAtPosition(x,y)}else{}return g}else{return false}},getShapeAtPosition:function(h){var k=arguments[0];var j=arguments[1];var a=this.memory;var b=[];for(var c=0;c<a.length;c++){var e=a[c];if(!e.getProperty("unclickable")){var l=e.getShape();var d=e.getBoundingBox();if(k>=d.x1&&k<=d.x2&&j>=d.y1&&j<=d.y2){b.push(a[c])}}}if(b.length>0){var f=this._findNeedleInHaystack(k,j,b);return f}else{return false}},_findNeedleInHaystack:function(l){var n=arguments[0];var m=arguments[1];var a=arguments[2];var d=[];for(var f=0;f<a.length;f++){var o=a[f].getShape();var b=false;if(o=="polygon"){b=this._inPoly(n,m,a[f])}else{if(o=="path"){b=false}else{if(o=="image"){b=true}else{if(o=="point"||o=="circle"){b=this._inCircle(n,m,a[f])}}}}if(b){d.push(a[f])}}if(d.length==0){return false}else{if(d.length==1){return d[0]}else{var e={s:[],z:0};for(var f=0;f<d.length;f++){var c=d[f].getProperty("z-index");if(c>e.z){e.s=[d[f]];e.z=c}else{if(c==e.z){e.s.push(d[f])}}}if(e.s.length==1){return e.s[0]}var j=e.s[0].getBoundingBox();var h=Math.min(j.x2-n,n-j.x1,j.y2-m,m-j.y1);var k={id:0,closeness:h};for(var f=1;f<e.s.length;f++){var j=e.s[f].getBoundingBox();var h=Math.min(j.x2-n,n-j.x1,j.y2-m,m-j.y1);if(k.closeness>h){k.id=f;k.closeness=h}}return e.s[k.id]}}},_inCircle:function(j){var n=arguments[0];var k=arguments[1];var l=arguments[2];var f=l.getBoundingBox();var b=l.getTransformation();if(b){var g=VismoTransformations.applyTransformation(n,k,b);n=g.x;k=g.y}var m=((n-f.center.x)*(n-f.center.x))+((k-f.center.y)*(k-f.center.y));var e=l.getDimensions();var o=e.width/2;var d=e.height/2;var p;var c;if(b&&b.scale){o*=b.scale.x;d*=b.scale.y}o*=o;d*=d;if(m<=o){p=true}else{p=false}if(m<=d){c=true}else{c=false}if(p&&c){return true}else{return false}},_onPath:function(c){var a=arguments[0];var d=arguments[1];var b=arguments[2];return false},_inPoly:function(c){var f=arguments[0];var e=arguments[1];var j=arguments[2];var n;n=j.getCoordinates();var g=j.getTransformation();if(g){var q=VismoTransformations.applyTransformation(f,e,g);f=q.x;e=q.y}var k=n.length;if(k/2<3){return false}var r=false;var s=n[k-2];var a=n[k-1];var p,o,d,b,h,l;for(var m=0;m<k;m+=2){h=n[m];l=n[m+1];if(h>s){p=s;o=h;d=a;b=l}else{p=h;o=s;d=l;b=a}if((h<f)==(f<=s)&&(e-d)*(o-p)<(b-d)*(f-p)){r=!r}s=h;a=l}return r},isOverlap:function(b,a){return false}};var VismoTransformations={clone:function(b){var a={};a.translate={x:0,y:0};a.scale={x:1,y:1};if(b.translate&&b.translate.x){a.translate.x=b.translate.x;a.translate.y=b.translate.y}if(b.scale&&b.scale.x){a.scale.x=b.scale.x;a.scale.y=b.scale.y}return a},applyTransformation:function(a,d,c){var b={};b.x=a;b.y=d;if(c.translate){b.x+=c.translate.x;b.y+=c.translate.y}if(c.scale){b.x*=c.scale.x;b.y*=c.scale.y}if(c.origin){b.x+=c.origin.x;b.y+=c.origin.y}return b},mergeTransformations:function(f,e){if(!e){return f}if(!f){return e}var d={};var h;for(h in f){d[h]=f[h]}for(h in e){if(d[h]){var c=d[h];var g=e[h];d[h].x=c.x+g.x;d[h].y=c.y+g.y}else{d[h]=e[h]}}return d},undoTransformation:function(a,h,d){var g={};var b=d;var e=b.translate;var c=b.scale;var f=b.origin;if(c===false||f===false||e===false){return false}if(a===false||h===false){return false}g.x=a-f.x;g.y=h-f.y;if(g.x!==0){g.x/=c.x}if(g.y!==0){g.y/=c.y}g.x-=e.x;g.y-=e.y;return g},getXY:function(b,a){var c=VismoClickingUtils.getMouseFromEvent(b);return this.undoTransformation(c.x,c.y,a)},create:function(a){var e={};var c;for(c in a){e[c]=a[c]}var d=e.scale;var b=e.translate;e.cache={id1:[d.x,",",d.y].join(""),id2:[b.x,",",b.y].join("")};return e}};var VismoOptimisations={minradius:5,packCoordinates:function(c){var b=[];for(var a=0;a<c.length-1;a+=2){b.push([c[a],c[a+1]])}return b},unpackCoordinates:function(c){var b=[];for(var a=0;a<c.length;a+=1){b.push(c[a][0]);b.push(c[a][1])}return b},douglasPeucker:function(n,j,a,e){var f=[];if(!a){a=0}if(!e){e=n.length-1}if(a>=n.length||e>=n.length||a==e-1){return[]}var q={};q.x=(n[e][0]+n[a][0])/2;q.y=(n[e][1]+n[a][1])/2;var o={distance:-1,index:-1};for(var g=a+1;g<e;g++){var m=n[g][0];var k=n[g][1];var r=q.x-m;var p=q.y-k;var l=Math.sqrt((r*r)+(p*p));if(l>o.distance){o.index=g;o.distance=l}}if(o.index==-1||o.distance<j){var h=[];h.push(n[a]);return h}else{f.push(n[a]);var b=o.index;var d=VismoOptimisations.douglasPeucker(n,j,a+1,b);var c=VismoOptimisations.douglasPeucker(n,j,b,e);f=f.concat(d);f=f.concat(c);f.push(n[e]);return f}},inVisibleArea:function(b,j,e,g){var c=0,f=0;var k=jQuery(b).width();var a=jQuery(b).height();var d=VismoClickingUtils.undotransformation(c,f,g);var h=VismoClickingUtils.undotransformation(k,a,g);if(j<h.x&&j>d.x&&e<h.y&&e>d.y){return true}else{console.log("bad",b,j,e,g,d,h);return false}},vismoShapeIsInVisibleArea:function(m,c,k,h){var d=0,j=0;var n=parseInt(c.width)+d;var a=parseInt(c.height)+j;var f=VismoClickingUtils.undotransformation(d,j,k);var l=VismoClickingUtils.undotransformation(n,a,k);if(h){f=h.xy(f);l=h.xy(l)}var b={};b.top=f.y;b.bottom=l.y;b.right=l.x;b.left=f.x;var e=m.getBoundingBox();if(e.x2<b.left){return false}if(e.y2<b.top){return false}if(e.x1>b.right){return false}if(e.y1>b.bottom){return false}return true},vismoShapeIsTooSmall:function(a,f){VismoTimer.start("VismoOptimisations.vismoShapeIsTooSmall");if(!f||!f.scale){VismoTimer.end("VismoOptimisations.vismoShapeIsTooSmall");return false}var e=a.getBoundingBox();var c=f.scale;var d=(e.width)*c.x;var b=(e.height)*c.y;if(b<this.minradius&&d<this.minradius){VismoTimer.end("VismoOptimisations.vismoShapeIsTooSmall");return true}else{VismoTimer.end("VismoOptimisations.vismoShapeIsTooSmall");return false}VismoTimer.end("VismoOptimisations.vismoShapeIsTooSmall")}};var GeoTag=function(b,d,a){var c={};c.type="feature";c.geometry={};c.geometry.type="point";c.geometry.coordinates=[b,d];c.properties=a;return c};var GeoPath=function(c,b){var d={geometry:{type:"LineString"},type:"feature",properties:b};if(c&&c[0].length>1){d.geometry.coordinates=c}else{var e=[];for(var a=0;a<c.length;a+=2){e.push([c[a],c[a+1]])}d.geometry.coordinates=e}return d};var VismoMap=function(a,l){if(a.length){var m=[];for(var c=0;c<a.length;c++){var g=new VismoMap(a[c],l);m.push(g)}return g}if(typeof a=="string"){a=document.getElementById(a)}else{a=a}this.wrapper=a;a.vismoMap=this;var e=this;this.settings={};var j=jQuery(a).width();var d=jQuery(a).height();jQuery(a).css({width:j,height:d});this.feature_reference={};if(!l){l={}}var e=this;var k=function(h){e.transform(h)};if(l.vismoController){l.vismoController.handler=k}this.vismoCanvas=new VismoCanvas(a,l);this.controller=this.vismoCanvas.vismoController;if(this.controller){this.transform(this.controller.transformation)}this._fittocanvas=true;this.geofeatures={};this.features=[];this.clear();var b=l.projection;var f=this;this._hijackMouseFunctions();if(l.tooltip){this.vismoCanvas.addTooltip(function(n,h){if(h){n.innerHTML=h.getProperty("name")}})}this.mouse({down:l.mousedown,up:l.mouseup,move:l.move,dblclick:l.dblclick,keypress:l.keypress});var f=this;if(b){if(b=="globe"||b=="spinnyglobe"){f=new VismoGlobe(this);if(b=="spinnyglobe"){f.toggleSpin()}}if(b=="google"){f.settings.projection=VismoSlippyMap.prototype.getGoogleMercatorProjection()}else{if(b=="slippystaticmap"){f=new VismoSlippyMap(this)}}}if(l.geojson){this.drawFromGeojson(l.geojson,l.fullscreen)}else{if(l.georss){this.drawFromGeojson(VismoConversion.geoRssToGeoJson(l.georss),l.fullscreen)}else{if(l.kml){this.drawFromGeojson(VismoConversion.kmlToGeoJson(l.kml),l.fullscreen)}}}return f};VismoMap.prototype={setTransparency:function(a){var b=arguments[0];this.vismoCanvas.setTransparency(b)},getVismoShapes:function(a){return this.vismoCanvas.getMemory()},resize:function(b){var d=arguments[0];var a=arguments[1];this.wrapper.style.width=d+"px";this.wrapper.style.height=a+"px";var c=this.getTransformation();c.origin.x=d/2;c.origin.y=a/2;this.setTransformation(c);this.vismoCanvas.resize(d,a);this.clear()},getProjection:function(a){return this.settings.projection},setProjection:function(b){var a=arguments[0];this.settings.projection=a},clear:function(a){var b=arguments[0];this.vismoCanvas.clear(b)},drawFromGeojson:function(args){var geojson=arguments[0];var autosize=arguments[1];if(typeof geojson=="string"){geojson=eval("("+geojson+")")}this._lastgeojson=geojson;if(autosize){var t=VismoMapUtils.fitgeojsontocanvas(geojson,this.wrapper);var p=this.getProjection();if(p&&p.name=="GLOBE"){t.translate={x:0,y:0}}this.controller.setTransformation(t)}var type=geojson.type.toLowerCase();if(type=="featurecollection"){var features=geojson.features;this.drawGeoJsonFeatures(features)}else{if(type=="feature"){this.drawGeoJsonFeature(geojson)}else{console.log("only feature collections currently supported")}}this.render()},add:function(a){this.drawGeoJsonFeature(a,a.properties);this.render()},drawFromGeojsonFile:function(a){var b=arguments[0];var c=this;var d=function(e,j,g,f,h){c.drawFromGeojson(g)};VismoFileUtils.loadRemoteFile(b,d)},getTransformation:function(a){if(!this.transformation){return false}else{return this.transformation}},setTransformation:function(a){var b=arguments[0];if(typeof b.translate.x!="number"||typeof b.translate.y!="number"){throw"bad transformation translate given "}if(typeof b.scale.x!="number"||typeof b.scale.y!="number"){throw"bad transformation scale given "}this.controller.setTransformation(b)},moveTo:function(b){var e=arguments[0];var g=arguments[1];var d=arguments[2];var a={translate:{},scale:{}};var c=this.getTransformation();var f={};f.x=parseFloat(e);f.y=parseFloat(g);if(this.settings.projection){f=this.settings.projection.xy(f.x,f.y,c)}a.translate.x=-f.x;a.translate.y=f.y;if(!d){d=c.scale.x}else{d=parseFloat(d)}a.scale.x=d;a.scale.y=d;this.controller.setTransformation(a)},redraw:function(a){this.render()},transform:function(b){var g=arguments[0];var a=parseInt(this.wrapper.style.width);var e=parseInt(this.wrapper.style.height);var c=g.translate;var d=g.scale;this.transformation=g;if(d.x<0.5){d.x=0.5}if(d.y<0.5){d.y=0.5}if(c.x>180){c.x=180}if(c.x<-180){c.x=-180}if(c.y>85.0511){c.y=85.0511}if(c.y<-85.0511){c.y=-85.0511}if(!this.transformation.rotate){this.transformation.rotate={x:0,y:0,z:0}}var f=this;f.vismoCanvas.setTransformation(f.transformation);f.redraw()},mouse:function(a){if(!a){return{up:this.onmouseup,down:this.onmousedown,move:this.onmousemove,dblclick:this.ondblclick,keypress:this.onkeypress}}if(a.move){this.onmousemove=a.move}if(a.up){this.onmouseup=a.up}if(a.down){this.onmouseup=a.down}if(a.keypress){this.onkeypress=a.keypress}if(a.dblclick){this.ondblClick=a.dblclick}},_hijackMouseFunctions:function(c){var h=this;var b=function(l){var r={};var j;if(l.which){j=l.which}else{if(l.keyCode){j=l.keyCode}}var k;if(j){k=String.fromCharCode(j)}var q=VismoClickingUtils.resolveTargetWithVismo(l);if(q&&q.getAttribute("class")=="vismoControl"){return false}var m=h.vismoCanvas.getShapeAtClick(l);if(m){r.shape=m;r.feature=h.geofeatures[h.vismoCanvas.getMemoryID(m)]}var o=VismoClickingUtils.getMouseFromEvent(l);var p=o.x;var n=o.y;r.mouse=o;r.longitude_latitude=VismoMapUtils.getLongLatFromMouse(p,n,h);r.event=l;r.keypressed=k;return r};var f=function(l,j){var k=b(l);if(h.onmousedown){h.onmousedown(l,j,k.mouse,k.longitude_latitude,k.feature,k.key,h)}};var a=function(l,j){var k=b(l);if(h.onmouseup){h.onmouseup(l,j,k.mouse,k.longitude_latitude,k.feature,k.key,h)}};var g=function(l,j){var k=b(l);if(h.onmousemove){h.onmousemove(l,j,k.mouse,k.longitude_latitude,k.feature,k.key,h)}};var e=function(l,j){var k=b(l);if(h.ondblClick){h.ondblClick(l,j,k.mouse,k.longitude_latitude,k.feature,k.key,h)}};var d=function(l,j){var k=b(l);if(h.onkeypress){h.onkeypress(l,j,k.mouse,k.longtitude_latitude,k.feature,k.key,h)}};this.vismoCanvas.mouse({mousedown:f,mouseup:a,mousemove:g,dblclick:e,keypress:d})},render:function(b){var g=new Date();var a=arguments[0];var d=this.transformation;var f=this;this.vismoCanvas.render(this.settings.projection);if(this.settings.afterRender){this.settings.afterRender(d)}var c=document.getElementById(f.wrapper.id+"_statustext");if(c){c.parentNode.removeChild(c)}var e=new Date();var h="mapRender";if(!VismoTimer[h]){VismoTimer[h]=0}VismoTimer[h]+=(e-g)},getFeatures:function(a){if(arguments[0]&&this.features[arguments[0]]){return this.features[arguments[0]]}return this.features},drawGeoJsonFeature:function(a){var f=arguments[0];var e=arguments[1];var c=new VismoMap.Feature(f,e);var d=c.getVismoShapes();for(var b=0;b<d.length;b++){this.vismoCanvas.add(d[b])}this.features.push(c)},drawGeoJsonFeatures:function(a){var c=arguments[0];var d=0;for(var b=0;b<c.length;b++){this.drawGeoJsonFeature(c[b],{featureid:b})}},getVismoCanvas:function(a){return this.vismoCanvas}};VismoMap.Feature=function(a,b){this.init(a,b)};VismoMap.Feature.prototype={init:function(b){var d=arguments[0];if(arguments[1]){extra_properties=arguments[1]}else{extra_properties={}}this.properties=d.properties;this.geometry=d.geometry;this.outers=[];this.vismoShapes=[];var h=this.geometry;var e=h.type.toLowerCase();if(e=="multipolygon"){this._drawGeoJsonMultiPolygonFeature(d.geometry.coordinates,d)}else{if(e=="linestring"){this._drawGeoJsonLineStringFeature(d)}else{if(e=="multilinestring"||e=="multipoint"||e=="geometrycollection"){console.log(e+" not supported yet")}else{if(e=="polygon"){this._drawGeoJsonPolygonFeature(d.geometry.coordinates,d)}else{if(e=="point"){this._drawGeoJsonPointFeature(d.geometry.coordinates,d)}else{}}}}}var a=this.getVismoShapes();var g;for(g in extra_properties){for(var c=0;c<a.length;c++){a[c].setProperty(g,extra_properties[g])}}},addOuterVismoShape:function(b){var a=arguments[0];this.outers.push(a)},getOuterVismoShapes:function(a){return this.outers},addVismoShape:function(b){var a=arguments[0];this.vismoShapes.push(a)},getVismoShapes:function(a){return this.vismoShapes},_drawGeoJsonLineStringFeature:function(a){var c=arguments[0];var g=c.geometry.coordinates;var f=c.properties;if(!f){f={}}f.shape="path";f.coordinates=[];for(var b=0;b<g.length;b++){var e=g[b];f.coordinates.push(e[0]);f.coordinates.push(-e[1])}var d=new VismoShape(f);this.addVismoShape(d);return d},_drawGeoJsonMultiPolygonFeature:function(a){var f=arguments[0];var d=arguments[1];var c;for(var b=0;b<f.length;b++){var e=this._drawGeoJsonPolygonFeature(f[b],d,b)}},_drawGeoJsonPolygonFeature:function(d){var f=arguments[0];var k=arguments[1];var b=arguments[2];var a=k.properties;a.shape="polygon";var g=false;for(var c=0;c<f.length;c++){var e=f[c];e=VismoUtils.invertYCoordinates(e);var h=new VismoShape(a,e);h.properties.geometryid=b;h.properties.geometryid2=c;this.addVismoShape(h)}return g},_drawGeoJsonPointFeature:function(a){var e=arguments[0];var b=arguments[1];var d=b.properties;d.shape="point";e[1]=-e[1];var c=new VismoShape(d,e);this.addVismoShape(c)},setProperty:function(b){var e=arguments[0];var d=arguments[1];var a=this.getVismoShapes();for(var c=0;c<a.length;c++){a[c].setProperty(e,d)}}};var VismoVector=function(a,b,c){VismoTimer.start("VismoVector.init");this._iemultiplier=100;this.vismoShape=a;this.cache={};this.maxResolution_id_x=1;this._oldproperties={};this.initShape(a,b,c);a.vml=this;VismoTimer.end("VismoVector.init")};VismoVector.prototype={scrub:function(){VismoTimer.start("VismoVector.scrub");if(this.el){this.el.parentNode.removeChild(this.el);this.el=false}VismoTimer.end("VismoVector.scrub")},initShape:function(k,e,c){VismoTimer.start("VismoVector.initShape");this.coordinatesHaveChanged();this.el=false;var f;var b=k.properties.shape;this.initialshapetype=b;if(b=="point"||b=="circle"){this._initArc(k,e);f=false}else{if(b=="image"){this._initImage(k,e)}else{if(b=="domElement"){this.el=k.getProperty("element");this.el.style.position="absolute";return}else{this._initPoly(k,e,c);f=true}}}var d=this.el;if(f&&e){var l,g;if(!e){throw" i need a canvas to do my magic!"}if(e.width){l=e.width}else{l=jQuery(e).width();e.width=l}if(e.height){g=e.height}else{g=jQuery(e).height();e.height=g}d.coordsize=this._getCoordSize(l,g)}if(this.vismoShape&&d){var a="vismoShape";if(b=="path"){a="vismoShapePath"}d.setAttribute("class",a);this.style()}var j=this;VismoTimer.end("VismoVector.initShape")},_getCoordSize:function(b,d){var a=this._iemultiplier;var f=parseInt(b);f*=a;var e=parseInt(d);e*=a;var c=[f,",",e].join("");return c},_initImage:function(b,c){var d=this;var f=b.getDimensions();var a=function(){var g=document.createElement("img");d.el=g;g.src=b.getProperty("src");jQuery(g).css({height:f.height,width:f.width,position:"absolute","z-index":4})};var e=new Image();e.src=b.getProperty("src");e.onload=function(g){a()};if(e.complete){a()}},_initArc:function(j,a){var e=document.createElement("vismoShapeVml_:arc");e.startAngle=0;e.endAngle=360;var f=j.getBoundingBox();this.el=e;var d=this;jQuery(window).unload(function(){d.el=null});var c=f.width;var h=f.width/2;var b=f.height;var g=f.height/2;jQuery(e).css({height:b,left:f.center.x-h,top:f.center.y-g,width:b,position:"absolute","z-index":4})},_initPoly:function(j,c,a){VismoTimer.start("VismoVector._initPoly");var g=document.createElement("vismoShapeVml_:shape");var b=j.properties;g.name=b.name;var k=a.width;var d=a.height;var e=["height:",d,"px; width:",k,"px; position:absolute;z-index:4;"].join("");g.style.cssText=e;var f=this;this.el=g;jQuery(window).unload(function(){f.el=null});VismoTimer.end("VismoVector._initPoly")},getVMLElement:function(){return this.el},_createvmlpathstring:function(h,A){var e=this._iemultiplier;VismoTimer.start("VismoVector.createvmlpathstring");var a=this.el;cindex="1,1";var m=this.cache;if(!m[cindex]){this.cache[cindex]={}}var o=this.vismoShape;var z=o.properties;if(!m[cindex]["pathstring"]){var p;var r=[];var w=o.getCoordinates("normal");if(A){w=o._applyProjection(A,h)}var l=w.length;if(l<2){return}var g,f;var j=0;if(o.isCommand(w[0])){j=1}g=w[j];f=w[j+1];g=Math.round(g*e);f=Math.round(f*e);r.push(["M",g,",",f].join(""));var k=false,n=false,q=false;for(var u=j+2;u<l;u+=2){var s=w[u];if(o.isCommand(s)){switch(s){case"M":r.push(" M");k=false;u+=1;break;case"z":r.push(" XE");break;case"q":n=true;u+=1;break;case"c":q=true;u+=1;break}}if(k){r.push(" ")}else{r.push(" L")}var g=Math.round(w[u]*e);var f=Math.round(w[u+1]*e);if(n){var v=parseInt(w[u+2]*e);var d=parseInt(w[u+3]*e);r.push([" c ",g,",",f,",",v,",",d,",",v,",",d,""].join(""));u+=2;n=false}else{if(q){var v=parseInt(w[u+2]*e);var d=parseInt(w[u+3]*e);var t=parseInt(w[u+4]*e);var b=parseInt(w[u+5]*e);r.push([" c ",g,",",f,",",v,",",d,",",t,",",b,""].join(""));u+=4;q=false}else{r.push([g,",",f].join(""))}}}if(z.shape!="path"){r.push(" XE")}this.cache[cindex]["pathstring"]=r.join("")}VismoTimer.end("VismoVector.createvmlpathstring");return m[cindex]["pathstring"]},transformDomElement:function(h,d){VismoTimer.start("VismoVector.transformDomElement");var e=this.vismoShape;var b=this.el;var g,c,a,j;var f=e.getBoundingBox();dx=f.x1;dy=f.y1;jQuery(this.el).css({left:dx,top:dy});VismoTimer.end("VismoVector.transformDomElement")},coordinatesHaveChanged:function(){this.coordinatesChanged=true},_cacheStyle:function(l,m,c){VismoTimer.start("VismoVector._cacheStyle");var a=this.el;if(!this.initialStyle){var d=a.style;var n=parseInt(d.top);if(!n){n=0}var g=parseInt(d.left);if(!g){g=0}var k=parseInt(d.width);var e=parseInt(d.height);this.initialStyle={width:k,height:e}}var b=this.initialStyle;var f=b.width*m.x;var j=b.height*m.y;VismoTimer.end("VismoVector._cacheStyle");return{width:[f,"px"].join(""),height:[j,"px"].join("")}},_cssTransform:function(d,c){VismoTimer.start("VismoVector._cssTransform");var a=this.el;var e=this.vismoShape;var j=this.vismoShapeProperties.shape;if(e._isArcBased(j)||e._isDomElement(j)){this.transformDomElement(d,c);VismoTimer.end("VismoVector._cssTransform");return}if(!d){return}var g,f;if(d.cache){g=d.cache.id1;f=d.cache.id2}else{g="1,1";f="0,0"}if(!this.cache[g]){this.cache[g]={}}var k=d.scale;if(!this.cache[g][f]){var b=d.origin,h=d.translate;this.cache[g][f]=this._cacheStyle(h,k,b)}VismoTimer.end("VismoVector._cssTransform")},clear:function(){VismoTimer.start("VismoVector.clear");var a=this.el;try{if(a){jQuery(a).css({display:"none"})}}catch(b){}VismoTimer.end("VismoVector.clear")},render:function(b,h,e){VismoTimer.start("VismoVector.render");var d=this;var f=this.el;this.vismoShapeProperties=this.vismoShape.properties;if(!f){return}if(!this.haveAppended){f._vismoClickingID=this.vismoShapeProperties.id}if(this.coordinatesChanged){this._cssTransform(h,e);f.path=this._createvmlpathstring(h,e);this.coordinatesChanged=false}var l=this.vismoShapeProperties.shape;if(this.initialshapetype!=l){this.scrub();this.initShape(this.vismoShape,b);this.haveAppended=false}if(l!="domElement"){f.style.display=""}if(!this.haveAppended){if(h){this._cssTransform(h,e)}jQuery(b).append(f);if(l=="domElement"){var j=this.vismoShape;var g=j.getCoordinates();var a=jQuery(el).width()/2;var k=jQuery(el).height()/2;jQuery(el).css({position:"absolute",left:g[0],top:g[1]-k})}this.haveAppended=true}this.style();VismoTimer.end("VismoVector.render")},_styleStroke:function(b,a){VismoTimer.start("VismoVector._styleStroke");if(a.lineWidth){b.strokeweight=[a.lineWidth,"em"].join("")}else{b.strokeweight="1em"}var f=a.stroke;if(f==this._lastStroke){return}if(!b.stroked){b.stroked="t"}if(f.indexOf("#")==0||f.indexOf("rgb(")==0){b.strokecolor=f}else{if(!this.vmlstroke){var d=document.createElement("vismoShapeVml_:stroke");b.appendChild(d);this.vmlstroke=d}var d=this.vmlstroke;if(f){var e;if(f.indexOf("rgba")!=-1&&f.match(/rgba\([0-9]*,[0-9]*,[0-9]*,(.*)\)/)){var c=f.match(/(rgb)a(\([0-9]*,[0-9]*,[0-9]*),(.*)\)/);if(c[3]){e=c[1]+c[2]+")";d.opacity=c[3]}}else{e=f}d.color=e}else{d.color="rgb(0,0,0)"}}this._lastStroke=f;VismoTimer.end("VismoVector._styleStroke")},_styleFill:function(b,a){VismoTimer.start("VismoVector._styleFill");var g=a.shape;if(!a.fill||g=="path"){b.filled="f";VismoTimer.end("VismoVector.style");return}var f=a.fill;b.filled="t";if(f.indexOf("#")==0||f.indexOf("rgb(")==0){b.fillcolor=a.fill}else{if(!this.vmlfill&&b){var d=document.createElement("vismoShapeVml_:fill");b.appendChild(d);this.vmlfill=d;var e=this;jQuery(window).unload(function(){e.vmlfill=null})}var d=this.vmlfill;if(f.indexOf("rgba")!=-1&&f.match(/rgba\([0-9]*,[0-9]*,[0-9]*,(.*)\)/)){var c=f.match(/(rgb)a(\([0-9]*,[0-9]*,[0-9]*),(.*)\)/);if(c[3]){f=c[1]+c[2]+")";d.opacity=c[3]}}d.color=f}VismoTimer.end("VismoVector._styleFill")},style:function(){VismoTimer.start("VismoVector.style");var b=this.el;var a=this.vismoShape.properties;if(a.hidden){jQuery(b).css({display:"none"})}if(this.nochange){VismoTimer.end("VismoVector.style");return}this.nochange=true;var d=a.shape;var c=b.style;if(c.display=="none"){c.display=""}if(a["z-index"]){c.zIndex=a["z-index"]}this._styleStroke(b,a);this._styleFill(b,a);this._oldproperties=VismoUtils.clone(a);this.nochange=true;VismoTimer.end("VismoVector.style")}};var VismoTimer={startsAt:{},timed:{},clear:function(){var a;for(a in this.timed){this.timed[a]=0}},on:function(){VismoTimer.start=function(a){if(!this.timed[a]){this.timed[a]=0}this.startsAt[a]=new Date()};VismoTimer.end=function(b){var a=new Date();this.timed[b]+=(a-this.startsAt[b])}},start:function(){},end:function(){},summarise:function(a){var b="";for(i in this.timed){b+=i+": "+this.timed[i].toString()+"\n"}if(a){jQuery(a).html(b)}else{return b}},blankf:function(){}};