
CanvasActiveLayer.instances={};CanvasActiveLayer.styles={};CanvasActiveLayer.deferred_styles={};CanvasActiveLayer.derange=function(s){var parts=s.split(',');var ranges={};for(var i=0;i<parts.length;i++){var p=parts[i];var lh=p.split('-');if(lh.length==1){ranges[p]=1;}else{var low=parseInt(lh[0]);var high=parseInt(lh[1]);for(var j=low;j<=high;j++){ranges[j.toString()]=1;}}}
return ranges;};CanvasActiveLayer._defineStyle=function(layername,cls,scalestep,prop,value){if(!CanvasActiveLayer.deferred_styles[layername]){CanvasActiveLayer.deferred_styles[layername]=[];}
CanvasActiveLayer.deferred_styles[layername].push(function(){CanvasActiveLayer.defineStyle(layername,cls,scalestep,prop,value);});};CanvasActiveLayer.defineStyle=function(layername,cls,scalestep,prop,value){if(!CanvasActiveLayer.styles[layername]){CanvasActiveLayer.styles[layername]={};}
var ln=CanvasActiveLayer.styles[layername];var clsranges=CanvasActiveLayer.derange(cls);for(var cs in clsranges){if(clsranges.hasOwnProperty(cs)){if(!ln[cs]){ln[cs]={};}
var c=ln[cs];var scranges=CanvasActiveLayer.derange(scalestep);for(var ss in scranges){if(scranges.hasOwnProperty(ss)){if(!c[ss]){c[ss]={};}
var s=c[ss];s[prop]=value;}}}}};CanvasActiveLayer._defineStyle('*','*','*','linewidth','6');CanvasActiveLayer._defineStyle('*','*','*','strokestyle','rgba(193,214,49,0.7)');function CanvasActiveLayer(id,layername,filter,offset,suppress,featurename,simplify)
{this.superclass=CanvasCanvas;this.superclass(id);this.layername=escape(layername);this.filter=null;this.featureName=null;this.lastCgi=null;this.suppress=null;this.simplify=false;this.localsimplify=false;this.blobStyle=null;this.blobSize=null;this.blobImg=null;this.blobImgW=null;this.blobImgH=null;this.refreshPending=false;this.lastCls=null;this.lastScaleStep=null;this.lastBoundN=null;this.lastBoundE=null;this.lastBoundS=null;this.lastBoundW=null;this.dataBoundN=-90;this.dataBoundE=-180;this.dataBoundS=90;this.dataBoundW=180;this.showMe=true;this.donefirstrun=false;if(filter){this.filter=escape(filter);}
if(offset){this.offset=parseInt(offset);}
if(suppress){this.suppress=escape(suppress);}
if(featurename){this.featureName=escape(featurename);}
if(simplify==='local'&&featurename){this.localsimplify=true;}
else if(simplify){this.simplify=true;}
this.jsonScript=null;this.dynaFeatures={};this.localsimplifycache={};CanvasActiveLayer.instances[id]=this;}
CanvasActiveLayer.prototype=new CanvasCanvas;CanvasActiveLayer.prototype.destroy=function()
{CanvasActiveLayer.instances[this.id]=null;};CanvasActiveLayer.prototype.init=function(mydivId,mymap)
{this._superInit=CanvasCanvas.prototype.init;this._superInit(mydivId,mymap);if(!this.checkSuppress()){this.suppress=null;}
if(this.featureName){if(!this.donefirstrun||this.simplify){this.getData();}}
else{this.refreshData();}
this.donefirstrun=true;};CanvasActiveLayer.prototype.reInit=function(divId)
{var restore=false;if(this.localsimplify&&this.showMe){this.showMe=false;restore=true;}
this._superReInit=CanvasCanvas.prototype.reInit;this._superReInit(divId);if(this.localsimplify&&restore){this.showMe=true;this._drawFeatures();}};CanvasActiveLayer.prototype.getDataBound=function()
{if(!this.dataBoundN||!this.dataBoundS||!this.dataBoundE||!this.dataBoundW){return{};}
return{top:this.dataBoundN,bottom:this.dataBoundS,left:this.dataBoundW,right:this.dataBoundE};};CanvasActiveLayer.prototype.getTooltipData=function(vpx,vpy)
{};CanvasActiveLayer.prototype.showCallback=function(show)
{this.showMe=show;if(!this.featureName&&show){this.refreshData();}
this._superShowCallback=CanvasCanvas.prototype.showCallback;this._superShowCallback(show);};CanvasActiveLayer.prototype.trayMoveCallback=function(dx,dy)
{if(this.localsimplify){this._drawFeatures();}
else{this._superTrayMoveCallback=CanvasCanvas.prototype.trayMoveCallback;this._superTrayMoveCallback(dx,dy);}
if(!this.featureName){this.incrementalRefresh(dx,dy);}};function canvasActiveLayerCallback(id,obj,incremental)
{if(CanvasActiveLayer.instances[id]){var s=CanvasActiveLayer.instances[id];s.jsonCallback(obj,incremental);}}
CanvasActiveLayer.prototype.jsonCallback=function(obj,incremental)
{this.refreshPending=false;var i,feature;if((!obj.feature||obj.feature.length===0)&&(!obj.shape)){return;}
if(!incremental){this.dynaFeatures={};this.dataBoundN=-90;this.dataBoundE=-180;this.dataBoundS=90;this.dataBoundW=180;}
if(obj.feature){for(i=0;i<obj.feature.length;i++){feature=obj.feature[i];this.dynaFeatures[feature.name]=feature;}}
if(obj.shape){feature=obj;delete(feature.requestid);this.dynaFeatures[feature.name]=feature;}
this._drawFeatures();};CanvasActiveLayer.prototype._drawFeatures=function(){this.clearCanvas();this.lastCls=null;for(var i in this.dynaFeatures){if(this.dynaFeatures.hasOwnProperty(i)){this._drawFeature(this.dynaFeatures[i]);}}};CanvasActiveLayer.prototype._drawFeature=function(feature)
{this._setStyle(feature);var sh=feature.shape.trim();var parts=sh.split(/[:;]/);for(var part=0;part<parts.length;part++){var pts=(parts[part].trim()).split(/[ +]/);if(pts.length===1){var ll=pts[0].split(',');this._drawBlob(ll[0],ll[1]);}else{this._drawPart(pts,part);}}};CanvasActiveLayer.prototype._dataBound=function(lon,lat)
{lon=parseFloat(lon);lat=parseFloat(lat);if(lon<this.dataBoundW){this.dataBoundW=lon;}
if(lon>this.dataBoundE){this.dataBoundE=lon;}
if(lat<this.dataBoundS){this.dataBoundS=lat;}
if(lat>this.dataBoundN){this.dataBoundN=lat;}};CanvasActiveLayer._undeferStyles=function(layername)
{if(layername in CanvasActiveLayer.deferred_styles){var qs=CanvasActiveLayer.deferred_styles[layername];for(var i=0;i<qs.length;i++){(qs[i])();}
delete CanvasActiveLayer.deferred_styles[layername];}};CanvasActiveLayer.prototype._checkStyleProperty=function(layername,cls,scalestep,property)
{var a,b,c,d;if((a=CanvasActiveLayer.styles[layername])&&(b=a[cls])&&(c=b[scalestep])&&(d=c[property])){return d;}};CanvasActiveLayer.prototype._getStyleProperty=function(feature,property,css)
{var value=null;CanvasActiveLayer._undeferStyles(this.layername);value=this._checkStyleProperty(this.layername,feature["_class"],css,property);if(value){return value;}
value=this._checkStyleProperty(this.layername,feature["_class"],"*",property);if(value){return value;}
value=this._checkStyleProperty(this.layername,"*",css,property);if(value){return value;}
value=this._checkStyleProperty(this.layername,"*","*",property);if(value){return value;}
CanvasActiveLayer._undeferStyles("*");value=this._checkStyleProperty("*",feature["_class"],css,property);if(value){return value;}
value=this._checkStyleProperty("*",feature["_class"],"*",property);if(value){return value;}
value=this._checkStyleProperty("*","*",css,property);if(value){return value;}
value=this._checkStyleProperty("*","*","*",property);return value;};CanvasActiveLayer.prototype._sameStyleAsLast=function(feature){if(!('_class'in feature)){return false};return(feature["_class"]==this.lastCls&&this.lastScaleStep==(this.MyMap.ScaleStep).toString());};CanvasActiveLayer.prototype._setStyle=function(feature)
{if(this._sameStyleAsLast(feature)){return;}
this.lastCls=feature["_class"];var css,ss;css=this.lastScaleStep=(this.MyMap.ScaleStep).toString();this._defaultStyle();ss=this._getStyleProperty(feature,"strokestyle",css);if(ss){this.strokeStyle(ss);}
ss=this._getStyleProperty(feature,"fillstyle",css);if(ss){this.fillStyle(ss);}
ss=this._getStyleProperty(feature,"linewidth",css);if(ss){this.lineWidth(parseInt(ss));}
ss=this._getStyleProperty(feature,"type",css);if(ss){this.blobType=ss;}
ss=this._getStyleProperty(feature,"src",css);if(ss){this.blobImg=ss;}
ss=this._getStyleProperty(feature,"height",css);if(ss){this.blobImgH=parseInt(ss);}
ss=this._getStyleProperty(feature,"width",css);if(ss){this.blobImgW=parseInt(ss);}
ss=this._getStyleProperty(feature,"size",css);if(ss){this.blobSize=parseInt(ss);}};CanvasActiveLayer.prototype._defaultStyle=function()
{this.strokeStyle("#cc0000");this.fillStyle("#009900");this.lineWidth(4);this.blobType="dot";this.blobSize=5;this.blobImg=null;this.blobImgW=10;this.blobImgH=10;return;};CanvasActiveLayer.prototype._drawBlob=function(lon,lat)
{if(this.blobType=="img"){if(!this.blobImg){return;}
this.beginPath();this.drawImageLL(this.blobImg,lon,lat,this.blobImgW,this.blobImgH);}else if(this.blobType=="box"){this.beginPath();this.rectLLCenter(lon,lat,this.blobSize,this.blobSize);this.fill();}else{this.beginPath();this.arcLL(lon,lat,this.blobSize,0,2*Math.PI);this.fill();}
this._dataBound(lon,lat);};CanvasActiveLayer.prototype._drawPart=function(pts,partnum)
{this.beginPath();if(pts.length<2){return;}
if(this.localsimplify){var mapscale=(this.MyMap.getState()).Scale;if(this.localsimplifycache[partnum+','+mapscale]){pts=this.localsimplifycache[partnum+','+mapscale];}else{var dp_alg=new DP_simplify(pts,(this.MyMap.getState()).Scale);if(dp_alg.eps){pts=dp_alg.go();this.localsimplifycache[partnum+','+mapscale]=pts;}}}
var ll,first;ll=first=pts[0].split(',');this.moveToLL(ll[0],ll[1]);this._dataBound(ll[0],ll[1]);for(var i=1;i<pts.length;i++){ll=pts[i].split(',');this.lineToLL(ll[0],ll[1]);this._dataBound(ll[0],ll[1]);}
if(ll[0]==first[0]&&ll[1]==first[1]){this.closePath();this.fill();}
this.stroke();};CanvasActiveLayer.prototype.checkSuppress=function()
{var retval=true;var valid={_class:1,scale:1,description:1,timestamp:1};var input=unescape(this.suppress).split(',');for(var i=0;i<input.length;i++)
{input[i].trim();if(input[i]=="class")
{input[i]="_class";}
if(!(input[i]in valid))
{retval=false;}}
return retval;};CanvasActiveLayer.prototype.getData=function()
{if(!this.showMe){return;}
var s=this.MyMap.getState();var cb="canvasActiveLayerCallback('"+this.id+"', %s, false);";var cgi="http://service.maptuit.com/axiom/?config=MAP.affinity&tolowercase=true&output_format=text/javascript&service=layer::getfeature&layername="+this.layername+"&scale="+s.Scale+"&callback="+escape(cb)+"&name="+this.featureName;if(this.offset){cgi+="&shift="+this.offset;}
if(this.suppress){cgi+="&suppress="+this.suppress;}
if(this.simplify){cgi+="&shapesimplification=enable";}
if((cgi==this.lastCgi)&&this.refreshPending){return;}
this.lastCgi=cgi;if(this.jsonScript){this.jsonScript.removeScriptTag();this.jsonScript=null;}
this.refreshPending=true;this.jsonScript=new JSONscriptRequest(cgi);this.jsonScript.buildScriptTag();this.jsonScript.addScriptTag();};CanvasActiveLayer.prototype.refreshData=function()
{if(!this.showMe){return;}
var s=this.MyMap.getState();var cb="canvasActiveLayerCallback('"+this.id+"', %s, false);";var cgi="http://service.maptuit.com/axiom/?config=MAP.affinity&tolowercase=true&output_format=text/javascript&service=layer::searchregion&layername="+this.layername;cgi+="&top="+s.Top+"&left="+s.Left+"&right="+s.Right+"&bottom="+s.Bottom+"&scale="+s.Scale+"&callback="+escape(cb);if(this.offset){cgi+="&shift="+this.offset;}
if(this.suppress){cgi+="&suppress="+this.suppress;}
if(this.simplify){cgi+="&shapesimplification=enable";}
this.lastBoundN=s.Top;this.lastBoundW=s.Left;this.lastBoundE=s.Right;this.lastBoundS=s.Bottom;if(this.filter){cgi+="&filter="+this.filter;}
if((cgi==this.lastCgi)&&this.refreshPending){return;}
this.lastCgi=cgi;if(this.jsonScript){this.jsonScript.removeScriptTag();this.jsonScript=null;}
this.refreshPending=true;this.jsonScript=new JSONscriptRequest(cgi);this.jsonScript.buildScriptTag();this.jsonScript.addScriptTag();};CanvasActiveLayer.prototype.incrementalRefresh=function(dx,dy)
{if(!this.showMe){return;}
if(dx===0&&dy===0){return;}
var s=this.MyMap.getState();var top,left,right,bottom,swp,cb,cgi,extra_params1,extra_params2,k;if(this.jsonScript){this.jsonScript.removeScriptTag();this.jsonScript=null;}
cb="canvasActiveLayerCallback('"+this.id+"', %s, true);";cgi="http://service.maptuit.com/axiom/?config=MAP.affinity&tolowercase=true&output_format=text/javascript&service=layer::searchregions&layername="+this.layername;cgi+="&scale="+s.Scale+"&callback="+escape(cb);if(this.offset){cgi+="&shift="+this.offset;}
if(this.suppress){cgi+="&suppress="+this.suppress;}
if(this.simplify){cgi+="&shapesimplification=enable";}
extra_params1="";extra_params2="";k=0;if(dx<0){left=s.Left;right=this.lastBoundW;}else{left=this.lastBoundE;right=s.Right;}
if(dx!==0){if(parseFloat(left)>parseFloat(right)){swp=left;left=right;right=swp;}
extra_params1="&region0_top="+s.Top+"&region0_bottom="+s.Bottom+"&region0_left="+left+"&region0_right="+right;k++;}
if(dy>0){top=this.lastBoundS;bottom=s.Bottom;if(dx<0){left=this.lastBoundW;right=s.Right;}else{left=s.Left;right=this.lastBoundE;}}else{top=s.Top;bottom=this.lastBoundN;if(dx<0){left=this.lastBoundW;right=s.Right;}else{left=s.Left;right=this.lastBoundE;}}
if(dy!==0){if(parseFloat(left)>parseFloat(right)){swp=left;left=right;right=swp;}
extra_params2="&region"+k+"_top="+top+"&region"+k+"_bottom="+bottom+"&region"+k+"_left="+left+"&region"+k+"_right="+right;}
this.lastBoundN=s.Top;this.lastBoundW=s.Left;this.lastBoundE=s.Right;this.lastBoundS=s.Bottom;if(this.filter){cgi+="&filter="+this.filter;}
cgi+=extra_params1+extra_params2;this.lastCgi=null;this.jsonScript=new JSONscriptRequest(cgi);this.jsonScript.buildScriptTag();this.jsonScript.addScriptTag();};function DP_simplify(_points,_radius){var i,xy;this.n=_points.length;if(this.n<=2){return;}
this.D=111195;this.eps=_radius/this.D;this.eps*=this.eps;this.K=Math.PI/180;this.X=[];this.Y=[];for(i=0;i<this.n;i++){xy=_points[i].split(',');this.X[i]=xy[0];this.Y[i]=xy[1];}
return true;}
DP_simplify.prototype.p2vs=function(px,py,x1,y1,x2,y2){var x4,y4,la,t,d12s,d34s,dp31;la=Math.cos(y1*this.K);d12s=la*la*(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);dp31=la*la*(px-x1)*(x2-x1)+(py-y1)*(y2-y1);if(d12s!==0){t=dp31/d12s;if(t<0){t=0;}
if(t>1){t=1;}
x4=(1-t)*x1+t*x2;y4=(1-t)*y1+t*y2;}else{x4=x1;y4=y1;}
d34s=la*la*(px-x4)*(px-x4)+(py-y4)*(py-y4);return d34s;};DP_simplify.prototype.dp=function(f,t){var d,max,maxpt,i,j,k,m;if(t-f<=1){return t-f+1;}
maxpt=f+1;max=this.p2vs(this.X[f+1],this.Y[f+1],this.X[f],this.Y[f],this.X[t],this.Y[t]);for(i=f+2;i<t;i++){d=this.p2vs(this.X[i],this.Y[i],this.X[f],this.Y[f],this.X[t],this.Y[t]);if(d>max){maxpt=i;max=d;}}
if(max<this.eps){this.X[f+1]=this.X[t];this.Y[f+1]=this.Y[t];return 2;}else if(t-f==2){return 3;}else{j=this.dp(f,maxpt);k=this.dp(maxpt,t);m=j+k-1;for(i=0;i<k;i++){this.X[f+j-1+i]=this.X[maxpt+i];this.Y[f+j-1+i]=this.Y[maxpt+i];}
return m;}};DP_simplify.prototype.go=function()
{var k=this.dp(0,this.n-1);var out=[];for(i=0;i<k;i++){out[i]=this.X[i]+','+this.Y[i];}
return out;};