function DSRange(low,high){this.low=low;this.high=high;}
DSRange.prototype.contains=function(n){return n>=this.low&&n<=this.high;};DSRange.prototype.limitNumber=function(number){number=Math.max(parseFloat(number),this.low);return Math.min(number,this.high);};function DSCircle(low,high){this.low=low;this.high=high;}
DSCircle.prototype.limitNumber=function(number){number=parseFloat(number);while(number>this.high){number-=this.high-this.low;}
while(number<this.low){number+=this.high-this.low;}
return number;};function DSCircleSegment(circle,low,high){this.circle=circle;this.low=low;this.high=high;}
DSCircleSegment.prototype.contains=function(point){var p=this.circle.limitNumber(point);if(this.low>this.high){return(p>=this.low&&p<=this.circle.high)||(p>=this.circle.low&&p<=this.high);}else{return p>=this.low&&p<=this.high;}};var DSLatitude=new DSRange(-90,90);var DSLongitude=new DSCircle(-180,180);function DSBoundingBox(lower,upper){this.lower=lower;this.upper=upper;this.width=new DSCircleSegment(DSLongitude,lower.lng,upper.lng);this.height=new DSRange(lower.lat,upper.lat);}
DSBoundingBox.prototype.contains=function(point){return this.width.contains(point.lng)&&this.height.contains(point.lat);};function DSMapTileUrlFactory(base,tileSet,extension,map,suffix){this.base=base||'';this.tileSet=tileSet||'';this.extension=extension||'';this.map=map;this.locale=map.locale||'';this.suffix=suffix||'';this.post=this.extension+'?';this.setPre();}
DSMapTileUrlFactory.prototype.setPre=function(){this.pre=this.base+(this.locale.length?this.locale+'/':'');};DSMapTileUrlFactory.prototype.getPost=function(){return this.post+'w='+this.map.width+'&h='+this.map.height+this.suffix;};DSMapTileUrlFactory.prototype.getUrl=function(x,y,z){return this.pre+z+'/'+x+'/'+y+this.getPost();};DSMapTileUrlFactory.prototype.setLocale=function(locale){this.locale=locale;this.setPre();};function DSCopyright(text,boxes,minzoom,maxzoom,tileset){this.text=text;this.boxes=(typeof boxes.length=='undefined'?[boxes]:boxes);this.minzoom=minzoom;this.maxzoom=maxzoom;this.tileset=tileset;}
DSCopyright.prototype.contains=function(point,zoom,tileset){var t=(!tileset||!this.tileset||(tileset==this.tileset));var z=(!this.minzoom||zoom>=this.minzoom)&&(!this.maxzoom||zoom<=this.maxzoom);var p=false;for(var i=0;i<this.boxes.length;++i){if(this.boxes[i].contains(point)){p=true;break;}}
return p&&z&&t;};function DSCopyrightSet(){this.copyrights=[];}
DSCopyrightSet.prototype.getCopyright=function(point,zoom,tileset){var t=[];if(point&&zoom){for(var i=0;i<this.copyrights.length;++i){if(this.copyrights[i].contains(point,zoom,tileset)){t.push(this.copyrights[i].text);}}}
return t.join(' - ');};DSCopyrightSet.prototype.addCopyright=function(c){this.copyrights.push(c);};function DSMapDecoratorCollection(){this.init();}
LMI.Lang.extend(DSMapDecoratorCollection,DSCollection);DSMapDecoratorCollection.prototype.getByType=function(type){var it=new DSIterator(this),ret=[],d;while((d=it.next())){if(d.type==type){ret.push(d);}}
return ret;};DSMapDecoratorCollection.prototype.getByName=function(name){var it=new DSIterator(this),d;while((d=it.next())){if(d.name==name){return d;}}
return ret;};function DSMapDecorator(map,el,pos,type,name){this.init(map,el,pos,type,name);}
DSMapDecorator.prototype.init=function(map,el,pos,type,name){this.map=map;this.element=el;this.position=pos;this.type=type;this.name=name;this.updatePosition();};DSMapDecorator.prototype.getElement=function(){return this.element;};DSMapDecorator.prototype.getFirstElement=function(){for(i=0,iLen=this.element.childNodes.length;i<iLen;++i){var o=this.element.childNodes[i];if(!LMI.StyleSheet.isClass(o,'skip')){return o;}}};DSMapDecorator.prototype.updatePosition=function(){this.element.style.position='absolute';if(typeof this.position.left!='undefined'){this.element.style.left=parseInt(this.position.left,10)+'px';}
if(typeof this.position.right!='undefined'){this.element.style.right=parseInt(this.position.right,10)+'px';}
if(typeof this.position.top!='undefined'){this.element.style.top=parseInt(this.position.top,10)+'px';}
if(typeof this.position.bottom!='undefined'){this.element.style.bottom=parseInt(this.position.bottom,10)+'px';}
for(var i in{width:'',height:''}){if(typeof this.position[i]!='undefined'){this.element.style[i]=parseInt(this.position[i],10)+'px';}}
if(typeof this.position.zIndex!='undefined'){this.element.style.zIndex=parseInt(this.position.zIndex,10);}};DSMapDecorator.prototype.setPosition=function(pos){for(var i in pos){this.position[i]=pos[i];}
this.updatePosition();};DSMapDecorator.prototype.getPosition=function(){return this.position;};(function(){function InvalidLatException(){this.name='InvalidLatException';}
LMI.Lang.extend(InvalidLatException,TypeError);function InvalidLngException(){this.name='InvalidLngException';}
LMI.Lang.extend(InvalidLngException,TypeError);function degrees(rad){return rad*(180.0/Math.PI);}
var M=LMI.Lang.getObject('LMI.Mapping',true);M.Point=function(lat,lng){this.init(lat,lng);};M.Point.prototype={init:function(lat,lng){this.setLat(lat);this.setLng(lng);},latAsRad:function(){return radians(this.lat);},lngAsRad:function(){return radians(this.lng);},equals:function(p){return p&&this.lat===p.lat&&this.lng===p.lng;},limitLat:function(lat){return DSLatitude.limitNumber(lat);},limitLng:function(lng){return DSLongitude.limitNumber(lng);},toString:function(){return'LMI.Mapping.Point('+this.lat+','+this.lng+')';},setLat:function(lat){var latn=parseFloat(lat);if(latn!=lat||isNaN(latn)){throw new InvalidLatException();}
this.lat=Math.round(this.limitLat(latn)*100000)/100000;},setLng:function(lng){var lngn=parseFloat(lng);if(lngn!=lng||isNaN(lngn)){throw new InvalidLngException();}
this.lng=Math.round(this.limitLng(lngn)*100000)/100000;},setLatFromRad:function(latRad){this.setLat(degrees(latRad));},setLngFromRad:function(lngRad){this.setLng(degrees(lngRad));}};M.Point.fromRadians=function(lat,lng){return new M.Point(degrees(lat),degrees(lng));};})();function DSMapObject(point,element,xOffset,yOffset,zOffset){this.init(point,element,xOffset,yOffset,zOffset);}
DSMapObject.prototype={init:function(point,element,xOffset,yOffset,zOffset){this.setPoint(point);this.element=element;this.xOffset=(xOffset?xOffset:0);this.yOffset=(yOffset?yOffset:0);this.zOffset=(zOffset?zOffset:0);this.properties={};this.initEvents('click','mouseout','mouseover');},setPoint:function(point){this.point=point;},setProperty:function(name,val){return this.properties[name]=val;},setProperties:function(){for(var i=0;i<arguments.length;i++){this.properties[arguments[i]]=arguments[++i];}
return this;},getProperty:function(name){return(name&&name in this.properties?this.properties[name]:"");},getXOffset:function(){return this.xOffset;},getYoffset:function(){return this.yOffset;},getZOffset:function(){return this.zOffset;},getWidth:function(){return this.element.offsetWidth;},getHeight:function(){return this.element.offsetHeight;},isIncludedInBestFit:function(){return!this.getProperty('excludeFromBestFit');},update:function(){},remove:function(){}};LMI.Lang.importFunctions(DSMapObject,LMI.Event);DSMapObject.prototype._addEventListener=DSMapObject.prototype.addEventListener;DSMapObject.prototype.addEventListener=function(type,func){switch(type){case'click':LMI.StyleSheet.setCursor(this.element,'pointer');case'mouseout':case'mouseover':if(this.getListeners(type).length==0){var o=this;LMI.BrowserEvent.addListener(this.element,type,function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this);o.triggerEvent(type,e,o);});}
break;}
this._addEventListener(type,func);};DSMapObject.prototype.bindEvent=function(type,obj,func,arg){var f=function(e,o){func.call(obj,e,o,arg);};return this.addEventListener(type,f);};function DSMapObject_Iterator(coll,offset){this.coll=coll;this.pos=(offset?offset:0);}
function DSMapObject_HasNext(){if(this.coll&&(this.pos+1)<=this.coll.order.length){return true;}
this.pos=0;return false;}
function DSMapObject_Next(){return(this.coll.objects[this.coll.order[this.pos++]]);}
function DSMapObject_GetId(){return this.coll.order[this.pos-1];}
function DSMapObject_SetIteratorOffset(offset){this.pos=offset;}
function DSMapObject_GetIteratorOffset(){return this.pos;}
function DSMapObject_Add(obj){this.objects[this.currIdx]=obj;this.order.push(this.currIdx);return this.currIdx++;}
function DSMapObject_Remove(key){if(this.objects[key]){delete this.objects[key]
for(var i=0;i<this.order.length;++i){if(this.order[i]==key){this.order.splice(i,1);}}
return true;}
return false;}
function DSMapObject_RemoveAll(){this.objects={};this.order=[];this.currPos=this.currIdx=0;}
function DSMapObject_GetByIndex(i){return this.objects[this.order[i]];}
function DSMapObject_GetById(id){return this.objects[id]?this.objects[id]:null;}
function DSMapObject_Size(){return this.order.length;}
function DSMapObject_GetByProperty(name,val){for(var i=0;i<this.order.length;++i){if(this.objects[this.order[i]].getProperty(name)==val){return this.objects[this.order[i]];}}
return null;}
function DSMapObject_GetIdsByProperty(name,val){var ids=[];for(var i=0;i<this.order.length;++i){if(this.objects[this.order[i]].getProperty(name)==val){ids.push(this.order[i]);}}
return ids;}
function DSMapObject_Collection(){this.objects={};this.order=[];this.currPos=this.currIdx=0;}
DSMapObject_Collection.prototype.add=DSMapObject_Add;DSMapObject_Collection.prototype.remove=DSMapObject_Remove;DSMapObject_Collection.prototype.getById=DSMapObject_GetById;DSMapObject_Collection.prototype.getByIndex=DSMapObject_GetByIndex;DSMapObject_Collection.prototype.size=DSMapObject_Size;DSMapObject_Collection.prototype.getByProperty=DSMapObject_GetByProperty;DSMapObject_Collection.prototype.getIdsByProperty=DSMapObject_GetIdsByProperty;DSMapObject_Collection.prototype.removeAll=DSMapObject_RemoveAll;DSMapObject_Iterator.prototype.next=DSMapObject_Next;DSMapObject_Iterator.prototype.getId=DSMapObject_GetId;DSMapObject_Iterator.prototype.hasNext=DSMapObject_HasNext;DSMapObject_Iterator.prototype.setOffset=DSMapObject_SetIteratorOffset;DSMapObject_Iterator.prototype.getOffset=DSMapObject_GetIteratorOffset;function DSIcon(point,iconSrc,xOffset,yOffset,zOffset){this.init(point,iconSrc,xOffset,yOffset,zOffset);}
LMI.Lang.extend(DSIcon,DSMapObject);DSIcon.prototype.init=function(point,iconSrc,xOffset,yOffset,zOffset){var icon=LMI.Element.createImage(iconSrc);LMI.BrowserEvent.addListener(icon,'error',DSIcon.ImageError);DSIcon.superclass.init.call(this,point,icon,xOffset,yOffset,zOffset);};DSIcon.prototype.getIcon=function(){return this.icon;};DSIcon.ImageError=function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this),i=e.getCurrentTarget(),defaultIcon=LMI.Urls.getImg('map_icon_blank.png');if(!LMI.Element.getImageSrc(i).match(defaultIcon)){LMI.Element.setImageSrc(i,defaultIcon);}}
function DSOutline(point,width,height){this.init(point,width,height);}
LMI.Lang.extend(DSOutline,DSMapObject);DSOutline.prototype.init=function(point,width,height){var o=LMI.Element.create('div',null);var e=LMI.Element.create('div',o);LMI.StyleSheet.addClass(o,'outline');LMI.StyleSheet.addClass(e,'fill');LMI.StyleSheet.setOpacity(o,60);LMI.StyleSheet.setOpacity(e,25);DSOutline.superclass.init.call(this,point,o);this.setWidth(width);this.setHeight(height);};DSOutline.prototype.setWidth=function(w){this.element.style.width=w+'px';};DSOutline.prototype.setHeight=function(h){this.element.style.height=h+'px';};function DSPolyLine(shapePoints,url,routeArea,visibleArea){this.init(shapePoints,url,routeArea,visibleArea);}
LMI.Lang.extend(DSPolyLine,DSMapObject);DSPolyLine.prototype.init=function(shapePoints,url,routeArea,visibleArea){this.eventsInited=false;this.shapePoints=shapePoints;this.routeArea=routeArea;this.routeRect=null;this.setVisibleArea(visibleArea);this.timeout=null;var el;if(url){el=document.createElement('img');LMI.BrowserEvent.addListener(el,'load',DSPolyLine.ImageLoad);DSPolyLine.superclass.init.call(this,this.point,el,0,0,-1);this.setLineUrl(url);this.url=url;}else{alert('TODO: create poly line element');el=LMI.Element.create('div',null);DSPolyLine.superclass.init.call(this,this.point,el,0,0,-1);}};DSPolyLine.prototype.updateCallback=function(data){if(data.routeUrl){this.setLineUrl(data.routeUrl);this.setVisibleArea(data.visibleRouteArea);this.map.positionObject(this);}};DSPolyLine.prototype.doUpdateLine=function(m){if(this.timeout){window.clearTimeout(this.timeout);}
var that=this;this.timeout=window.setTimeout(function(){that.timeout=null;that.element.style.display='none';var ur=m.getMapLayerURPoint();var ll=m.getMapLayerLLPoint();var bound=[ll.lng,ll.lat,ur.lng,ur.lat];this.center=m.getCenterPoint();LMI.AjaxController.getRouteImageUrl(function(data){that.updateCallback(data)},that.shapePoints,that.routeArea,bound,m.zoomLevel);},250);};DSPolyLine.prototype.updateLine=function(e,m){if(!this.center&&e.previousCenter){this.center=e.previousCenter;}
if(e.eventType=='zoom'&&e.previousZoomLevel!=m.zoomLevel){this.routeRect=null;this.doUpdateLine(m);}else if(e.eventType=='recenter'){var center=this.center;var newCenter=m.getCenterPoint();var tl=m.gridSystem.getUpperLeftPoint(newCenter.lng,newCenter.lat,this.map.width,this.map.height);var br=m.gridSystem.getLowerRightPoint(newCenter.lng,newCenter.lat,this.map.width,this.map.height);var mapRect=new Rectangle(tl.y,tl.x,br.y,br.x);if(!this.routeRect){this.routeRect=this.calculateRect(this.routeArea,m);}
if(!this.visibleRect){this.visibleRect=this.calculateRect(this.visibleArea,m);}
var routeIntersect=mapRect.intersection(this.routeRect);var visibleIntersect=mapRect.intersection(this.visibleRect);var finalIntersect=routeIntersect.intersection(visibleIntersect);if(!routeIntersect.equals(finalIntersect)){this.doUpdateLine(m);}}};DSPolyLine.prototype.calculateRect=function(area,_map){var tl=_map.gridSystem.toXY(area[0],area[3]);var br=_map.gridSystem.toXY(area[2],area[1]);return new Rectangle(tl.y,tl.x,br.y,br.x);}
DSPolyLine.prototype.update=function(_map){if(!this.eventsInited){this.eventsInited=true;this.map=_map;var o=this;this.updateFunc=function(e,m){o.updateLine(e,m)};_map.addEventListener('zoom',this.updateFunc);_map.addEventListener('recenter',this.updateFunc);}};DSPolyLine.prototype.remove=function(){if(this.eventsInited){this.eventsInited=false;this.map.removeEventListener('zoom',this.updateFunc);this.map.removeEventListener('recenter',this.updateFunc);}};DSPolyLine.prototype.setVisibleArea=function(a){this.visibleArea=a;this.point=new LMI.Mapping.Point(a[3],a[0]);this.visibleRect=null;};DSPolyLine.prototype.setLineUrl=function(url){this.url=url;if(LMI.Browser.browser==='Explorer'&&LMI.Browser.version<7){var el=this.element;var u=url.split('?',2);LMI.Element.setAlphaImageLoader(el,u[0]+'?'+u[1].replace(/%/g,'%25'));}else{this.element.src=url;}};DSPolyLine.ImageLoad=function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this);var i=e.getCurrentTarget();i.style.display='block';i.style.height='auto';i.style.width='auto';};function Rectangle(top,left,bottom,right){this.top=top;this.left=left;this.bottom=bottom;this.right=right;}
Rectangle.prototype.intersection=function(r,dest){var x1=Math.max(this.left,r.left);var y1=Math.max(this.top,r.top);var x2=Math.min(this.right,r.right);var y2=Math.min(this.bottom,r.bottom);if(!dest){dest=new Rectangle();}
dest.top=y1;dest.left=x1;dest.bottom=y2;dest.right=x2;return dest;}
Rectangle.prototype.equals=function(r){return this.left==r.left&&this.top==r.top&&this.right==r.right&&this.bottom==r.bottom;}
var EQUITORIAL_EARTH_RADIUS_MEAN_METERS=6.378245e6;var HALF_PI=Math.PI/2.0;(function(){var L=LMI.Lang.getObject('LMI.Mapping'),radiusMiles=EQUITORIAL_EARTH_RADIUS_MEAN_METERS*0.000621371192;L.getDistance=function(p1,p2){if(p1.equals(p2)){return 0;}
var lat1=p1.latAsRad(),lat2=p2.latAsRad(),lng1=p1.lngAsRad(),lng2=p2.lngAsRad(),c=Math.cos,s=Math.sin;return Math.acos(c(lat1)*c(lng1)*c(lat2)*c(lng2)+
c(lat1)*s(lng1)*c(lat2)*s(lng2)+
s(lat1)*s(lat2))*radiusMiles;};})();function Coord(x,y){this.x=x;this.y=y;}
Coord.prototype.toString=function(){return'Coord('+this.x+','+this.y+')';};function radians(deg){return deg*(Math.PI/180.0);}
LMI.Mapping.Grid=function(p,x_size,y_size,x_units,y_units,invert_y,origin_lon,origin_lat){this._P=p;this._x_grid_size=x_size;this._y_grid_size=y_size;this._x_upg=x_units;this._y_upg=y_units;this._invert_y=invert_y;this._origin_lon=radians(origin_lon);this._origin_lat=radians(origin_lat);this.reset();};LMI.Mapping.Grid.prototype=(function(){return{reset:function(){var pt=this._P.forward(this._origin_lon,this._origin_lat);this._x_translation=-pt.x;this._y_translation=-pt.y;this._x_scale=(this._x_upg/this._x_grid_size);this._y_scale=(this._y_upg/this._y_grid_size)*(this._invert_y?-1.0:1.0);},getXScale:function(){return this._x_scale;},getYScale:function(){return this._y_scale;},gridX:function(x){return Math.floor(x/this._x_upg);},gridY:function(y){return Math.floor(y/this._y_upg);},grid:function(x,y){if(arguments.length===1){var pt=x;return new Coord(this.gridX(pt.x),this.gridY(pt.y));}else{return new Coord(this.gridX(x),this.gridY(y));}},offsetX:function(x){return x%this._x_upg;},offsetY:function(y){return y%this._y_upg;},offset:function(x,y){if(arguments.length===1){var pt=x;return new Coord(this.offsetX(pt.x),this.offsetY(pt.y));}else{return new Coord(this.offsetX(x),this.offsetY(y));}},toX:function(grid){var offset=(arguments.length==2?arguments[1]:0);return(grid*this._x_upg)+offset;},toY:function(grid){var offset=(arguments.length==2?arguments[1]:0);return(grid*this._y_upg)+offset;},toXY:function(gridX,offsetX,gridY,offsetY){if(arguments.length==2){var lon=gridX;var lat=offsetX;var xy=this._P.forward(radians(lon),radians(lat));return new Coord((xy.x+this._x_translation)*this._x_scale,(xy.y+this._y_translation)*this._y_scale);}else{return new Coord(this.toX(gridX,offsetX),this.toY(gridY,offsetY));}},toLL:function(x,y){if(arguments.length==1){y=arguments[0].y;x=arguments[0].x;}
return this._P.inverse((x/this._x_scale)-this._x_translation,(y/this._y_scale)-this._y_translation);},getUpperLeftPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x-(width/2.0),xy.y-(height/2.0));}else{return new Coord(xy.x-(width/2.0),xy.y+(height/2.0));}},getLowerRightPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x+(width/2.0),xy.y+(height/2.0));}else{return new Coord(xy.x+(width/2.0),xy.y-(height/2.0));}},getLowerLeftPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x-(width/2.0),xy.y+(height/2.0));}else{return new Coord(xy.x-(width/2.0),xy.y-(height/2.0));}},getUpperRightPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x+(width/2.0),xy.y-(height/2.0));}else{return new Coord(xy.x+(width/2.0),xy.y+(height/2.0));}}};})();LMI.Mapping.Grid.newInstance=function(size_x,size_y,tile_width,tile_height,standard_parallel){return new LMI.Mapping.Grid(new EquiRectangularMapProjection(radians(0.0),radians(standard_parallel)),size_x,size_y,tile_width,tile_height,true,-180.0,90.0);};function EquiRectangularMapProjection(lon,lat){this._center_lon=lon;this._center_lat=lat;this._cos_center_lat=Math.cos(lat);this._R=EQUITORIAL_EARTH_RADIUS_MEAN_METERS;}
function adjust_lon(lon){if(lon<-Math.PI){return lon-(Math.floor(lon/Math.PI)*Math.PI);}else if(lon>Math.PI){return-(Math.PI-lon+(Math.floor(lon/Math.PI)*Math.PI));}
return lon;}
EquiRectangularMapProjection.prototype.forward=function(lon,lat){return new Coord(this._R*adjust_lon(lon-this._center_lon)*this._cos_center_lat,this._R*lat);};EquiRectangularMapProjection.prototype.inverse=function(x,y){return LMI.Mapping.Point.fromRadians(Math.min(y/this._R,HALF_PI),adjust_lon(this._center_lon+x/(this._R*this._cos_center_lat)));};(function(){var M=LMI.Lang.getObject('LMI.Mapping',true),scales=[1.7021276,3.4042553,6.80851064,13.61702128,27.23404256,54.46808512,108.93617024,217.87234048,435.74468096,871.48936192,1742.97872384,3485.95744768,6971.9148953,13943.82979072],grid=[],scalesInited=false;M.Map=function(container,options){this.init(container,options);};M.Map.prototype={setZoomLevel:function(z,p){this.prepareEventObject();if(z<1){z=1;}else if(z>scales.length){z=scales.length;}
if(this.zoomSlider&&this.zoomSlider.shown){this.zoomSlider.setPosition(((z-1)/(scales.length-1)));}
if(p&&!p.equals(this.getCenterPoint())){this.setCenterPoint(p);}
this.zoomLevel=z;this.setScale();this.loadTiles();this.triggerEvent('zoom',this.getEventObject(),this);},bestFit:function(factor,collection){if(typeof factor==='number'){this.factor=factor;}else if(typeof this.factor==='number'){factor=this.factor;}else{this.factor=factor=0.9;}
collection=collection||this.objects;var i,p,pt,maxpt=null,minpt=null,it=new DSMapObject_Iterator(collection);P=this.gridSystem._P;while(it.hasNext()){p=it.next();if(!p.isIncludedInBestFit()){continue;}
if(maxpt===null){maxpt=P.forward(p.point.lngAsRad(),p.point.latAsRad());}
if(minpt===null){minpt=new Coord(maxpt.x,maxpt.y);}
pt=P.forward(p.point.lngAsRad(),p.point.latAsRad());if(pt.x<minpt.x){minpt.x=pt.x;}
if(pt.x>maxpt.x){maxpt.x=pt.x;}
if(pt.y<minpt.y){minpt.y=pt.y;}
if(pt.y>maxpt.y){maxpt.y=pt.y;}}
if(maxpt===null){if(this.getOption('defaultLat')&&this.getOption('defaultLng')&&this.getOption('emptyZoom')){this.centerAndZoom(new M.Point(this.getOption('defaultLat'),this.getOption('defaultLng')),this.getOption('emptyZoom'));}}else if(minpt.x===maxpt.x&&minpt.y===maxpt.y){var ll=P.inverse(minpt.x,minpt.y);this.centerAndZoom(ll,this.getOption('singleZoom'));}else{var midll=P.inverse((minpt.x+maxpt.x)/2.0,(minpt.y+maxpt.y)/2.0);var width=this.width*factor;var height=this.height*factor;var dist_x=maxpt.x-minpt.x;var dist_y=maxpt.y-minpt.y;dist_x*=width/height;for(i=0;i<scales.length;++i){if(dist_x<=(width/grid[i].getXScale())&&dist_y<=Math.abs(height/grid[i].getYScale())){break;}}
var zoom=Math.min(i,scales.length-1);this.centerAndZoom(midll,zoom+1);}},centerOnPoint:function(p){if(!p.equals(this.getCenterPoint())){this.prepareEventObject();this.setCenterPoint(new M.Point(p.lat,p.lng));this.loadTiles();var o=this.getEventObject();this.triggerEvent('recenter',o,this);}},centerAndZoom:function(p,z){this.prepareEventObject();this.setZoomLevel(z,p);var o=this.getEventObject();this.triggerEvent('recenter',o,this);},init:function(cont,options){var container=(typeof cont==='string')?container=LMI.Element.getOne(cont):cont;if(!container){throw('Map: unable to find container: "'+cont+'"');}
this.container=container;LMI.StyleSheet.addClass(container,'dsMap');this.initOptions(options);this.decorators=new DSMapDecoratorCollection();this.centerPoint=null;this.zoomLevel=scales.length;this.locale=this.getOption('defaultLocale');if(!scalesInited){for(var i=0;i<scales.length;++i){grid[i]=LMI.Mapping.Grid.newInstance(scales[i]*this.getOption('tileWidth'),scales[i]*this.getOption('tileHeight'),this.getOption('tileWidth'),this.getOption('tileHeight'),this.getOption('standardParallel'));}
scalesInited=true;}
var year=new Date().getYear();if(year<1000){year+=1900;}
this.copyrightTxt='\xa9'+year+' Local Matters, Inc.';this.copyrightSet=DSMapCopyrightSet;this.setScale();this.setGridLeft(null);this.setGridTop(null);this.columns=this.rows=0;this.initContainer();this.tileUrlFactory=new DSMapTileUrlFactory(this.getOption('tileBase'),'',this.getOption('tileExtension'),this,this.getOption('tileSuffix'));this.objects=new DSMapObject_Collection();this.initEvents('zoom','recenter','resize');},initOptions:function(options){this.options=LMI.Mapping.Map.Defaults;if(typeof options!='undefined'){for(var i in options){this.options[i]=options[i];}}},setLocale:function(locale){this.locale=locale;this.tileUrlFactory.setLocale(locale);},setOption:function(key,value){this.options[key]=value;},getOption:function(key){return this.options[key]||'';},addDecorator:function(d){this.decorators.push(d);this.decoratorLayer.appendChild(d.getElement());},removeDecorator:function(d){var l=this.decorators.getLength();for(var i=0;i<l;++i){if(this.decorators.getByIndex(i)===d){this.decorators.remove(i);this.decoratorLayer.removeChild(d.getElement());return;}}},positionTile:function(i){var t=this.tiles[i];t.setLeft(((i%this.columns)*t.getWidth()+this.mlOffsetLeft)+'px');t.setTop((Math.floor(i/this.columns)*t.getHeight()+this.mlOffsetTop)+'px');},prepareEventObject:function(){this.beforeEvent={previousZoomLevel:this.zoomLevel,previousCenter:this.getCenterPoint()};},getEventObject:function(){var o=this.beforeEvent;this.beforeEvent={};o.zoomLevel=this.zoomLevel;o.center=this.getCenterPoint();return o;},setCopyright:function(copyrightStr){this.copyright.getElement().firstChild.nodeValue=this.copyrightTxt=copyrightStr;},setGridLeft:function(n){return(this.gridLeft=n);},getGridLeft:function(){return this.gridLeft;},setGridTop:function(n){return(this.gridTop=n);},getGridTop:function(){return this.gridTop;},getScale:function(l){if(typeof l=='number'){return scales[l-1];}
return this.scale;},setScale:function(){this.scale=scales[this.zoomLevel-1];this.gridSystem=grid[this.zoomLevel-1];},positionMap:function(){var xy=this.getMapLayerXYByPoint(this.getCenterPoint());this.mapLayer.style.left=Math.round((this.width/2)-xy.x)+'px';this.mapLayer.style.top=Math.round((this.height/2)-xy.y)+'px';},updateTiles:function(){for(var i=0;i<this.tiles.length;++i){this.tiles[i].setSize(this.getOption('tileWidth'),this.getOption('tileHeight'));this.positionTile(i);}
this.updateDataCopyright();},updateMap:function(){this.updateTiles();},calculateGridPosition:function(){var p=this.getCenterPoint();var tl=this.gridSystem.getUpperLeftPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);var tlTile=this.gridSystem.grid(tl);this.setGridLeft(tlTile.x);this.setGridTop(tlTile.y);},loadTiles:function(){this.mlOffsetTop=this.mlOffsetLeft=0;var o=0;this.calculateGridPosition();for(var i=this.getGridTop();i<this.getGridTop()+this.rows;++i){for(var j=this.getGridLeft();j<this.getGridLeft()+this.columns;++j){this.tiles[o++].setUrl(this.tileUrlFactory.getUrl(j,i,this.zoomLevel));}}
this.updateMap();this.positionMap();this.updateObjects();},updateObjects:function(){for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){this.positionObject(it.next());}},getMapLayerULXY:function(){var s=this.mapLayer.style;return new Coord(parseInt(s.left,10),parseInt(s.top,10));},getMapLayerXYByPoint:function(p){if(this.getGridLeft()!==null&&this.getGridTop()!==null){var x=this.gridSystem.toX(this.getGridLeft());var y=this.gridSystem.toY(this.getGridTop());var xy=this.gridSystem.toXY(p.lng,p.lat);return new Coord(Math.round(xy.x-x),Math.round(xy.y-y));}
return null;},getXYByPoint:function(p){var xy=this.getMapLayerXYByPoint(p);if(xy){xy.x+=this.getMapLeft();xy.y+=this.getMapTop();}
return xy;},getPointByMapLayerXY:function(x,y){if(this.getGridLeft()!==null&&this.getGridTop()!==null){return this.gridSystem.toLL(this.gridSystem.toXY(this.getGridLeft(),x-this.mlOffsetLeft,this.getGridTop(),y-this.mlOffsetTop));}
return null;},getPointByXY:function(x,y){return this.getPointByMapLayerXY(x-this.getMapLeft(true),y-this.getMapTop(true));},setCenterPoint:function(p){this.centerPoint=p;},getCenterPoint:function(){return this.centerPoint;},getMapLayerCenterXY:function(){return new Coord((this.width/2)-this.getMapLeft(),(this.height/2)-this.getMapTop());},getULPoint:function(){return this.getPointByXY(0,0);},getBRPoint:function(){return this.getPointByXY(this.width,this.height);},calculateCenterPoint:function(){return this.getPointByXY(Math.floor(this.width/2),Math.floor(this.height/2));},recalculateCenterPoint:function(){this.setCenterPoint(this.calculateCenterPoint());},getMapLayerCenterPoint:function(){var p=this.getCenterPoint();var center=this.gridSystem.toXY(p.lng,p.lat);var xy=this.getMapLayerCenterXY();xy.x-=this.mapLayerWidth/2;xy.y-=this.mapLayerHeight/2;return this.getPointByXY(this.width/2-xy.x,this.height/2-xy.y);},getMapLayerLLPoint:function(){var p=this.getMapLayerCenterPoint();var xy=this.gridSystem.getLowerLeftPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);return this.gridSystem.toLL(xy.x,xy.y);},getMapLayerURPoint:function(){var p=this.getMapLayerCenterPoint();var xy=this.gridSystem.getUpperRightPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);return this.gridSystem.toLL(xy.x,xy.y);},positionObject:function(obj,point){if(typeof point!='undefined'){obj.setPoint(point);}
var xy=this.getMapLayerXYByPoint(obj.point);if(xy){obj.element.style.left=(xy.x-obj.xOffset+this.mlOffsetLeft)+'px';obj.element.style.top=(xy.y-obj.yOffset+this.mlOffsetTop)+'px';}
obj.update(this);},addObject:function(obj){var id=this.objects.add(obj);this.mapLayer.appendChild(obj.element);obj.element.style.position='absolute';obj.z=5+obj.zOffset;obj.element.style.zIndex=obj.z;this.positionObject(obj);return id;},removeObject:function(o){var id=-1;if(typeof o==='object'){for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){var i=it.next();if(i===o){id=it.getId();break;}}}else{id=o;}
var obj=this.objects.getById(id);if(obj){obj.remove(this);this.mapLayer.removeChild(obj.element);this.objects.remove(id);}},removeAll:function(){var o;for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){o=it.next();o.remove(this);o.element.parentNode.removeChild(o.element);}
this.objects.removeAll();},updateDataCopyright:function(){if(!this.dataCopyright){var c=LMI.Element.create('div',null,{textValue:' ',className:'dataCopyright'});var pos={zIndex:100,bottom:0};if(this.width>=250){pos.right=0;}else{pos.left=0;}
this.dataCopyright=new DSMapDecorator(this,c,pos,'copyright','data copyright');this.addDecorator(this.dataCopyright);}
this.dataCopyright.getElement().firstChild.nodeValue=this.copyrightSet.getCopyright(this.getCenterPoint(),this.zoomLevel);},addCopyright:function(){var t=LMI.Element.create('div',null,{textValue:this.copyrightTxt});LMI.StyleSheet.addClass(t,'copyright');this.copyright=new DSMapDecorator(this,t,{bottom:this.width>=250?0:10},'copyright','main copyright');this.addDecorator(this.copyright);this.updateDataCopyright();},sizeLayers:function(){this.width=parseInt(this.container.clientWidth,10);this.height=parseInt(this.container.clientHeight,10);this.desiredRows=Math.ceil(this.height/this.getOption('tileHeight'))+2;this.desiredColumns=Math.ceil(this.width/this.getOption('tileWidth'))+2;this.mapLayerWidth=this.desiredColumns*this.getOption('tileWidth');this.mapLayerHeight=this.desiredRows*this.getOption('tileHeight');this.mapLayer.style.height=this.mapLayerHeight+'px';this.mapLayer.style.width=this.mapLayerWidth+'px';this.viewport.style.height=this.height+'px';this.viewport.style.width=this.width+'px';this.decoratorLayer.style.height=this.height+'px';this.decoratorLayer.style.width=this.width+'px';},initContainer:function(){this.decoratorLayer=LMI.Element.create('div',this.container,{'class':'decLayer'});this.viewport=LMI.Element.create('div',this.decoratorLayer,{'class':'viewport'});this.mapLayer=LMI.Element.create('div',this.viewport,{'class':'mapLayer'});this.tileLayer=LMI.Element.create('div',this.mapLayer,{'class':'tileLayer'});if(!this.getOption('controlBuffer')){this.setOption('controlBuffer',0);}
this.sizeLayers();this.tiles=[];for(var i=0;i<this.desiredRows;++i){for(var j=0;j<this.desiredColumns;++j){this.tiles.push(new M.Tile(this,this.tileLayer));}}
this.rows=this.desiredRows;this.columns=this.desiredColumns;this.mlOffsetTop=this.mlOffsetLeft=0;this.addCopyright();},getMapLeft:function(unadjusted){var l=parseInt(LMI.StyleSheet.getStyle(this.mapLayer,'left'),10);if(!unadjusted){l+=this.mlOffsetLeft;}
return l;},getMapTop:function(unadjusted){var t=parseInt(LMI.StyleSheet.getStyle(this.mapLayer,'top'),10);if(!unadjusted){t+=this.mlOffsetTop;}
return t;}};LMI.Lang.importFunctions(M.Map,LMI.Event);M.Map.setScales=function(s){scales=s;};M.Map.getScales=function(){return scales;};})();LMI.Mapping.Map.Defaults={'singleZoom':3,'emptyZoom':14,'defaultLat':39.73926,'defaultLng':-104.98478,'defaultLocale':'','imageBase':'img/','pixelUrl':'img/pixel_trans.gif','brokenUrl':'img/map_unavailable.gif','tileBase':'http://localhost/tiles/','tileExtension':'.png','tileSuffix':'','tileWidth':256,'tileHeight':256,'tileAttempts':1,'standardParallel':40};(function(){var errors={};LMI.Mapping.Tile=function(map,parent){this.map=map;this.img=LMI.Element.create('img',parent,{src:map.getOption('pixelUrl'),style:'position: absolute;',galleryImg:'no'});LMI.StyleSheet.setOpacity(this.img,0);LMI.BrowserEvent.bind(this.img,'load',this,this.load);LMI.BrowserEvent.bind(this.img,'error',this,this.error);};LMI.Mapping.Tile.prototype={error:function(){var i=this.img,attempts=this.map.getOption('tileAttempts'),broken=this.map.getOption('brokenUrl'),pixel=this.map.getOption('pixelUrl');if(!errors[i.src]){errors[i.src]=1;}
if(errors[i.src]++<attempts){var s=i.src;i.src=pixel;i.src=s;}else if(!i.src.match(broken)){i.src=broken;}},load:function(evt){var a;if('Animation'in LMI){a=new LMI.Animation.Fade(this.img,0,100);a.setDuration(.75);a.start();}else{LMI.StyleSheet.setOpacity(this.img,100);}},removeFromDom:function(){LMI.Element.destroy(this.img);},setSize:function(width,height){this.width=this.img.width=width;this.height=this.img.height=height;},getWidth:function(){return this.width;},getHeight:function(){return this.height;},setLeft:function(left){this.img.style.left=left;},setTop:function(top){this.img.style.top=top;},setUrl:function(url){if(typeof this.img.complete!='undefined'&&!this.img.complete){var o=this;window.setTimeout(function(){o.setUrl(url);},1000);return;}
if(url){if(this.img.src!=url){LMI.StyleSheet.setOpacity(this.img,1);this.img.src=url;}}else{this.img.src=this.map.getOption('brokenUrl');}}};})();var DSMapCopyrightSet=new DSCopyrightSet();(function(){var year=new Date().getYear(),P=LMI.Mapping.Point;if(year<1000){year+=1900;}
var nt=new DSCopyright('\xa9'+year+' NAVTEQ',[new DSBoundingBox(new P(10.0,-135.0),new P(70.0,-60.0)),new DSBoundingBox(new P(48.0,-180.0),new P(75.0,-124.0)),new DSBoundingBox(new P(16.860777,-161.283172),new P(24.219651,-153.424705)),new DSBoundingBox(new P(12.5,-78.6),new P(33.0,-50.0))]);var ta=new DSCopyright('\xa9'+year+' TeleAtlas',[new DSBoundingBox(new P(48.478825,1.322422),new P(52.521175,7.677558)),new DSBoundingBox(new P(31.0,-10),new P(44.0,5.0)),new DSBoundingBox(new P(48.0,-0.6),new P(56.0,11.5)),new DSBoundingBox(new P(46.0,-20.0),new P(61.0,4.7))]);var tl='\xa9'+year+' Terralink Intl Ltd';DSMapCopyrightSet.addCopyright(nt);DSMapCopyrightSet.addCopyright(ta);DSMapCopyrightSet.addCopyright(new DSCopyright(tl,new DSBoundingBox(new P(-70.0,133.0),new P(-11.0,180.0))));})();LMI.MapUtils=(function(){return{getIcon:function(idx,iconSet,badge){var i=parseInt(idx,10);var s=iconSet;var lets=LMI.Strings.getString('js.letters');var l=(i>=0&&i<lets.length?lets.charAt(i):(badge?'star':'blank'));switch(iconSet){case'red':s='red';break;case'blue':default:s='blue';}
return LMI.Urls.getImg('map_nodes/'+s+'/map_icon_'+l+'.png');}};})();