﻿var GLMap=Class.create();GLMap.DEFAULT_MAP_MARKER="/Resource/Map/icons/ix_op_all/24x24/plain/flag_red.gif";GLMap.prototype={cX:null,ak:null,hM:null,mJ:null,initialize:function(aQ,lat,lon,am,gm){this.cX=$("map");this.ak=new AJAXMAP('map','http://ts1.webatlas.no/',false,"1881Live");if($defined(gm)&&gm){this.ak.disallowMouseNavigation();}this.ak.init(new Coordinate(lon,lat,"EPSG:4326"),aQ,am);this.ak.setMouseZoom(true);this.ak.disableAnnotationInfo();this.ak.disableLogging();$('mapzoomBox').style.border="dashed 2px white";this.km();},getMouseDownCoords:function(){return this.ak.getMouseDownCoords();},yW:null,wM:function(aG){this.uN(aG);},cp:null,gb:null,km:function(){try{Event.observe(this.cX,"map:moved",this.nQ.bindAsEventListener(this));Event.observe(this.cX,"map:zoomedIn",this.jJ.bindAsEventListener(this,"in"));Event.observe(this.cX,"map:zoomedOut",this.jJ.bindAsEventListener(this,"out"));Event.observe(this.cX,"map:mouseMoved",this.uz.bindAsEventListener(this));Event.observe(this.cX,"map:dragBegin",this.wx.bindAsEventListener(this));Event.observe(this.cX,"map:dragEnd",this.wy.bindAsEventListener(this));this.cp=this.addEventType("onchangeview");this.gb=this.addEventType("onbeginpan");this.hx=this.addEventType("onendpan");}catch(e){}},uN:function(aG){var myMenuItems=[{name:'Markér sted',className:'setPoints',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('showCoordinates',cP);}).bind(this)},{name:'Sett målepunkt',className:'addMeasurePoints',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('addMeasurePoints',cP);}).bind(this)},{name:'Fjern målepunkt',className:'deleteMeasurePoints',callback:(function(){aG('deleteMeasurePoints');}).bind(this)},{name:'Lag veibeskrivelse herfra',className:'addFromPointMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('addFromPointMenuItem',cP);}).bind(this)},{name:'Lag veibeskrivelse hit',className:'addToPointMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('addToPointMenuItem',cP);}).bind(this)},{name:'Legg til sted i veibeskrivelse',className:'addViaPointMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('addViaPointMenuItem',cP);}).bind(this)},{name:'Zoom inn',className:'zoomInMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('zoomInMenuItem',cP);}).bind(this)},{name:'Zoom ut',className:'zoomOutMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('zoomOutMenuItem',cP);}).bind(this)},{name:'Sentrér kart',className:'centerMapMenuItem',callback:(function(){var cP=this.ak.UTMToLatLon(this.ak.getMouseDownMapCoords());aG('centerMapMenuItem',cP);}).bind(this)}];new Proto.Menu({selector:'#map',className:'menu desktop',menuItems:myMenuItems})},wx:function(e){this.gb.fire();},wy:function(e){this.hx.fire();},uz:function(e){this.hM=e.memo.mouseCoords;this.mJ=e.memo.mouseMapCoords;},jJ:function(e,gX){if(this.hM==null){this.hM=this.ak.getCurrentMouseCoords();this.mJ=this.ak.getPixelLatLon(this.hM);}this.cp.fire({viewport:this.qB(e.memo.boundingBox),level:this.ak.getZoomLevel(),mouseCoords:this.hM,mouseMapCoords:this.UTMToLatLon(this.mJ),actionType:"zoom"});},nQ:function(e){var bO=this.qB(this.ak.getBoundingBox());this.cp.fire({viewport:bO,level:this.ak.getZoomLevel(),mouseMapCoords:new Coordinate(),mouseCoords:e.memo.mouseMapCoords,actionType:"move"});},qB:function(bO){return{maxLat:bO.top,north:bO.top,minLon:bO.left,west:bO.left,minLat:bO.bottom,south:bO.bottom,maxLon:bO.right,east:bO.right};},getMapContainer:function(){return this.ak.getMapContainer();},getDrawLayer:function(){return this.ak.getDrawLayer();},getStaticDrawLayer:function(){return this.ak.getStaticDrawLayer();},getMouseLayer:function(){return this.ak.getMouseLayer();},decimalDegreesToUTM:function(bE){return this.ak.decimalDegreesToUTM(bE);},UTMToLatLon:function(bE){return this.ak.UTMToLatLon(bE);},getType:function(){return "GLMap";},getDrawLayer:function(){return this.ak.getDrawLayer();},getZoomLevel:function(){return this.ak.getZoomLevel();},setZoomLevel:function(level){this.centerAndZoom({level:level});},centerAndZoom:function(at){var ay;var aC=$defined(at.lat)?at.lat:null;var aD=$defined(at.lon)?at.lon:null;if(aC==null||aD==null){ay=this.ak.getCenterCoordinate().transform("EPSG:4326");}else{ay=new Coordinate(aD,aC,"EPSG:4326");}var ax=$defined(at.level)?at.level:null;if(ax==null){ax=this.ak.getZoomLevel();}this.ak.centerAndZoom(ay,ax);},center:function(position){this.centerAndZoom(position);},getCenter:function(){return this.ak.getCenterCoordinate();},getCenterUTM:function(){var bE=this.ak.getCenterCoordinate();return bE.transform("EPSG:32633");},zJ:function(){return{width:Element.getWidth(this.cX),height:Element.getHeight(this.cX)}},getPixelLatLon:function(){if(arguments.length==2){var pixel=new Coordinate(arguments[0],arguments[1]);return this.ak.getPixelLatLon(pixel);}else{return this.ak.getPixelLatLon(arguments[0]);}},getLatLonPixel:function(aC,aD){var aO=Element.getWidth(this.cX);var aJ=Element.getHeight(this.cX);var kQ=this.getPixelLatLon(aO,aJ);var kS=this.getPixelLatLon(0,0);var y=(1-((aC-kQ.y)/(kS.y-kQ.y)))*aJ;var x=(aD-kS.x)/(kQ.x-kS.x)*aO;return new Coordinate(x,y);},getMapStyle:function(){return this.ak.getMapStyle();},mK:[0,1,2],setMapStyle:function(style){if(this.mK.include(style)){this.ak.setMapStyle(style);return true;}return false;},isBirdseyeAvailable:function(){if(this.getZoomLevel()>=15){var center=this.ak.getCenterCoordinate();aC=center.y;aD=center.x;return this.uS(aC,aD);}else{return false;}},pan:function(xdir,ydir){this.ak.move({x:xdir,y:ydir},true);},wo:false,resize:function(aO,aJ){var bannerHeight=0;if(aO==undefined){this.ak.resize(undefined,undefined,false);}else{this.ak.resize(aJ,aO,false);}this.wo=true;},getViewport:function(){var w=this.ak.getWidth();var h=this.ak.getHeight();var min=this.ak.getPixelLatLon(new Coordinate(0,h));var max=this.ak.getPixelLatLon(new Coordinate(w,0));return({minLat:min.y,minLon:min.x,maxLat:max.y,maxLon:max.x,height:h,width:w});},getBestView:function(bO){return this.ak.zoomOnBoundingBox(bO,true,true);},addMarker:function(icon,northing,easting,title,description,lowerbound,upperbound,iconXOffset,iconYOffset){this.ak.addMarker(icon,northing,easting,title?title:"",description?description:"",lowerbound?lowerbound:0,upperbound?upperbound:15,iconXOffset?iconXOffset:0,iconYOffset?iconYOffset:0);},drawLine:function(ey){var dH=this.ak.getDrawCanvas();if(dH==null){dH=new WAPICanvas();dH.element.style.zIndex=1;this.ak.addDrawCanvas(dH);}else{dH.clear();}for(var i=0;i<ey.length;i++){ey[i]=ey[i].transform('EPSG:32633');}if(ey.length==2){var mL=new PolyLine(ey,{'rgba':'rgba(255, 0, 0, 1)','lineWidth':3});dH.addPolyLine(mL);}else if(ey.length>2){var mL=new PolyLine(ey,{'rgba':'rgba(255, 0, 0, 1)','lineWidth':3});dH.addPolyLine(mL,true);var wS=new PolyLine([ey.last(),ey.first()],{'rgba':'rgba(255, 0, 0, 0.3)','lineWidth':3});dH.addPolyLine(wS,true);dH.redraw();}},clearDrawings:function(){var dH=this.ak.getDrawCanvas();if(dH!=null){dH.clear();}},hideLine:function(id){},showLine:function(id){}};Object.extend(GLMap,AbstractMap);Object.extend(GLMap.prototype,new AbstractEventTrigger());