var gnLastEventId=0;var KAMAP_ERROR=gnLastEventId ++;var KAMAP_WARNING=gnLastEventId ++;var KAMAP_NOTICE=gnLastEventId++;var KAMAP_INITIALIZED=gnLastEventId ++;var KAMAP_MAP_INITIALIZED=gnLastEventId ++;var KAMAP_EXTENTS_CHANGED=gnLastEventId ++;var KAMAP_SCALE_CHANGED=gnLastEventId ++; function kaMap( szID ){ this.domObj=getRawObject( szID ); this.domObj.style.overflow='hidden'; this.initializationState=0; this.bMouseDown=false; this.lastx=0; this.lasty=0; this.theInsideLayer=null; this.viewportWidth=safeParseInt(this.domObj.style.width); this.viewportHeight=safeParseInt(this.domObj.style.height); this.xOffset=0; this.yOffset=0; this.xOrigin=0; this.yOrigin=0; this.currentMap=''; this.nWide=0; this.nHigh=0; this.nCurrentTop=0; this.nCurrentLeft=0; this.aPixel=new Image(1,1); this.aPixel.src='images/a_pixel.gif'; this.imgErrors=new Array(); this.aMaps=new Array(); this.tileWidth=null; this.tileHeight=null; this.nBuffer=1; this.baseURL=''; this.tileURL='tile.php?'; this.cellSize=null; this.gImageID=0; this.eventManager=new _eventManager(); this.as=slideid=null; this.accelerationFactor=1; this.pixelsPerStep=30; this.timePerStep=25; this.server=''; this.init="init.php"; this.tileURL=null; this.aObjects=[]; this.aCanvases=[]; this.layersHidden=false; this.aTools=[]; this.initialize=kaMap_initialize; this.setBackgroundColor=kaMap_setBackgroundColor; this.resize=kaMap_resize; this.addMap=kaMap_addMap; this.getMaps=kaMap_getMaps; this.selectMap=kaMap_selectMap; this.getCurrentMap=kaMap_getCurrentMap; this.setLayerVisibility=kaMap_setLayerVisibility; this.setLayerOpacity=kaMap_setLayerOpacity; this.getCenter=kaMap_getCenter; this.getGeoExtents=kaMap_getGeoExtents; this.pixToGeo=kaMap_pixToGeo; this.geoToPix=kaMap_geoToPix; this.setMapSize=kaMap_setMapSize; this.zoomIn=kaMap_zoomIn; this.zoomOut=kaMap_zoomOut; this.zoomToScale=kaMap_zoomToScale; this.zoomByFactor=kaMap_zoomByFactor; this.zoomToExtents=kaMap_zoomToExtents; this.zoomTo=kaMap_zoomTo; this.slideBy=kaMap_slideBy; this.moveBy=kaMap_moveBy; this.getCurrentScale=kaMap_getCurrentScale; this.registerTool=kaMap_registerTool; this.activateTool=kaMap_activateTool; this.deactivateTool=kaMap_deactivateTool; this.registerEventID=kaMap_registerEventID; this.registerForEvent=kaMap_registerForEvent; this.deregisterForEvent=kaMap_deregisterForEvent; this.triggerEvent=kaMap_triggerEvent; this.createDrawingCanvas=kaMap_createDrawingCanvas; this.removeDrawingCanvas=kaMap_removeDrawingCanvas; this.hideLayers=kaMap_hideLayers; this.showLayers=kaMap_showLayers; this.addObjectGeo=kaMap_addObjectGeo; this.addObjectPix=kaMap_addObjectPix; this.removeObject=kaMap_removeObject; this.centerObject=kaMap_centerObject; this.shiftObject=kaMap_shiftObject; this.updateObjects=kaMap_updateObjects; for (var i=0; i=oMap.aScales[i]) { break; } newScale=oMap.aScales[i]; } this.cellSize=newScale/(oMap.resolution * inchesPerUnit[oMap.units]); var nFactor=oMap.zoomToScale( newScale ); var cpX=cgX / this.cellSize; var cpY=cgY / this.cellSize; var vpLeft=Math.round(cpX - this.viewportWidth/2); var vpTop=Math.round(cpY + this.viewportHeight/2); var cTileX=Math.floor(cpX/this.tileWidth)*this.tileWidth; var cTileY=Math.floor(cpY/this.tileHeight)*this.tileHeight; var nTilesLeft=Math.ceil(this.viewportWidth/(2*this.tileWidth))*this.tileWidth; var nTilesUp=Math.ceil(this.viewportHeight/(2*this.tileHeight))*this.tileHeight; this.nCurrentLeft=cTileX - nTilesLeft; this.nCurrentTop=-1*(cTileY + nTilesUp); this.xOrigin=this.nCurrentLeft; this.yOrigin=this.nCurrentTop; this.theInsideLayer.style.left=-1*(vpLeft - this.xOrigin) + "px"; this.theInsideLayer.style.top=(vpTop + this.yOrigin) + "px"; var layers=oMap.getLayers(); for( var k in layers) { var d=layers[k].domObj; for(var j=0; j 0) szURL=szURL + "?map="+ arguments[0]; call(szURL, this, kaMap_initializeCallback); return true;} function kaMap_initializeCallback( szInit ){ if (szInit.substr(0, 1) !="/") { this.triggerEvent( KAMAP_ERROR, 'ERROR: ka-Map! initialization '+ 'failed on the server. Message returned was:\n' + szInit); return false; } this.initializationState=2; eval(szInit); this.triggerEvent( KAMAP_INITIALIZED );} function kaMap_setBackgroundColor( color ){ this.domObj.style.backgroundColor=color; return true;} function kaMap_createLayers(){ this.theInsideLayer=document.createElement('div'); this.theInsideLayer.id='theInsideLayer'; this.theInsideLayer.style.position='absolute'; this.theInsideLayer.style.left='0px'; this.theInsideLayer.style.top='0px'; this.theInsideLayer.style.zIndex='1'; this.theInsideLayer.kaMap=this; if (this.currentTool) this.theInsideLayer.style.cursor=this.currentTool.cursor; this.domObj.appendChild(this.theInsideLayer); this.domObj.kaMap=this; this.theInsideLayer.onmousedown=kaMap_onmousedown; this.theInsideLayer.onmouseup=kaMap_onmouseup; this.theInsideLayer.onmousemove=kaMap_onmousemove; this.theInsideLayer.onmouseover=kaMap_onmouseover; this.domObj.onmouseout=kaMap_onmouseout; this.theInsideLayer.onkeyup=kaMap_onkeyup; this.theInsideLayer.onkeypress=kaMap_onkeypress; this.theInsideLayer.ondblclick=kaMap_ondblclick; this.theInsideLayer.oncontextmenu=kaMap_oncontextmenu; this.theInsideLayer.ondragstart=new Function([], 'var e=e?e:event;e.cancelBubble=true;e.returnValue=false;return false;');} function kaMap_initializeLayers(nFactor){ var deltaMouseX=this.nCurrentLeft + safeParseInt(this.theInsideLayer.style.left) - this.xOrigin; var deltaMouseY=this.nCurrentTop + safeParseInt(this.theInsideLayer.style.top) - this.yOrigin; var vpTop=this.nCurrentTop - deltaMouseY; var vpLeft=this.nCurrentLeft - deltaMouseX; var vpCenterX=vpLeft + this.viewportWidth/2; var vpCenterY=vpTop + this.viewportHeight/2; var currentTileX=Math.floor(vpCenterX/this.tileWidth)*this.tileWidth; var currentTileY=Math.floor(vpCenterY/this.tileHeight)*this.tileHeight; var tileDeltaX=currentTileX - this.nCurrentLeft; var tileDeltaY=currentTileY - this.nCurrentTop; var newVpCenterX=vpCenterX * nFactor; var newVpCenterY=vpCenterY * nFactor; var newTileX=Math.floor(newVpCenterX/this.tileWidth) * this.tileWidth; var newTileY=Math.floor(newVpCenterY/this.tileHeight) * this.tileHeight; var newCurrentLeft=newTileX - tileDeltaX; var newCurrentTop=newTileY - tileDeltaY; this.nCurrentLeft=newCurrentLeft; this.nCurrentTop=newCurrentTop; var newTilLeft=-newVpCenterX + this.viewportWidth/2; var newTilTop=-newVpCenterY + this.viewportHeight/2; var xOldOrigin=this.xOrigin; var yOldOrigin=this.yOrigin; this.xOrigin=this.nCurrentLeft; this.yOrigin=this.nCurrentTop; this.theInsideLayer.style.left=(newTilLeft + this.xOrigin) + "px"; this.theInsideLayer.style.top=(newTilTop + this.yOrigin) + "px"; var layers=this.aMaps[this.currentMap].getLayers(); for( var k in layers) { var d=layers[k].domObj; for(var j=0; j newHigh) kaMap_removeRow.apply(this, []); while (this.nWide < newWide) kaMap_appendColumn.apply(this, []); while (this.nWide > newWide) kaMap_removeColumn.apply(this, []); } function kaMap_createImage( top, left, obj ){ var img=document.createElement('img'); img.src=this.aPixel.src; img.width=this.tileWidth; img.height=this.tileHeight; img.setAttribute('style', 'position:absolute; top:'+top+'px; left:'+left+'px;' ); img.style.position='absolute'; img.style.top=(top - this.yOrigin)+'px'; img.style.left=(left - this.xOrigin)+'px'; img.style.width=this.tileWidth + "px"; img.style.height=this.tileHeight + "px"; img.style.visibility='hidden'; img.onerror=kaMap_imgOnError; img.onload=kaMap_imgOnLoad; img.errorCount=0; img.id="i" + this.gImageID; img.layer=obj; img.kaMap=this; this.gImageID=this.gImageID + 1; if (obj.visible) obj.setTile(img); return img;} function kaMap_resetTile( id, bForce ){ var img=getRawObject(id); if (img.layer) img.layer.setTile(this, bForce);} function kaMap_reloadImage(id){} function kaMap_resetImage(id){} function kaMap_imgOnError(e){ if (this.layer) this.layer.setTile(this, true);} function kaMap_imgOnLoad(e){ this.style.visibility='visible';} function kaMap_appendRow(){ if (this.nWide==0) return; var layers=this.aMaps[this.currentMap].getLayers(); for( var i in layers) { var obj=layers[i].domObj; for (var j=0; j=0; j--) { var top=this.nCurrentTop + (j * this.tileHeight); var left=this.nCurrentLeft + (this.nWide * this.tileWidth); var img=kaMap_createImage.apply( this, [top, left, layers[i]]); if (isIE4) img.style.filter="Alpha(opacity="+layers[i].opacity+")"; if (j < this.nHigh-1) obj.insertBefore(img, obj.childNodes[((j+1)*this.nWide)]); else obj.appendChild(img); } } this.nWide=this.nWide + 1;} function kaMap_removeColumn(){ if (this.nWide < 4) return; var layers=this.aMaps[this.currentMap].getLayers(); for( var i in layers) { var d=layers[i].domObj; for(var j=this.nHigh - 1; j >=0; j--) { var img=d.childNodes[((j+1)*this.nWide)-1]; d.removeChild( img ); img.onload=null; img.onerror=null; } } this.nWide=this.nWide - 1;} function kaMap_removeRow(){ if (this.nHigh < 4) return; var layers=this.aMaps[this.currentMap].getLayers(); for( var i in layers) { var d=layers[i].domObj; for(var i=this.nWide - 1; i >=0; i--) { var img=d.childNodes[((this.nHigh-1)*this.nWide)+i]; d.removeChild( img ); img.onload=null; img.onerror=null; } } this.nHigh=this.nHigh - 1;} function kaMap_hideLayers(){ if (this.layersHidden) return; var layers=this.aMaps[this.currentMap].getLayers(); for( var i in layers) { layers[i]._visible=layers[i].visible; if (layers[i].name !='__base__') { layers[i].setVisibility( false ); } } for( var i=0; i < this.aCanvases.length; i++) { this.aCanvases[i].style.visibility='hidden'; this.aCanvases[i].style.display='none'; } this.layersHidden=true;} function kaMap_showLayers(){ if (!this.layersHidden) return; var layers=this.aMaps[this.currentMap].getLayers(); for( var i in layers) { layers[i].setVisibility( layers[i]._visible ); } for( var i=0; i < this.aCanvases.length; i++) { this.aCanvases[i].style.visibility='visible'; this.aCanvases[i].style.display='block'; } this.layersHidden=false;} function kaMap_moveBy( x, y ){ var til=this.theInsideLayer; til.style.top=(safeParseInt(til.style.top)+y) + 'px'; til.style.left=(safeParseInt(til.style.left)+x )+ 'px'; kaMap_checkWrap.apply(this, []);} function kaMap_slideBy(x,y){ if (this.slideid!=null) goQueueManager.dequeue( this.slideid ); this.as=[]; var absX=Math.abs(x); var absY=Math.abs(y); var signX=x/absX; var signY=y/absY; var distance=absX>absY?absX:absY; var steps=Math.floor(distance/this.pixelsPerStep); var dx=dy=0; if (steps > 0) { dx=(x)/(steps*this.pixelsPerStep); dy=(y)/(steps*this.pixelsPerStep); } var remainderX=x - dx*steps*this.pixelsPerStep; var remainderY=y - dy*steps*this.pixelsPerStep; var px=py=0; var curspeed=this.accelerationFactor; var i=0; while(i0) { px+=this.as[i-1][0]; py+=this.as[i-1][1]; } var cx=px+Math.round(dx*this.pixelsPerStep); var cy=py+Math.round(dy*this.pixelsPerStep); this.as[i]=new Array(cx-px,cy-py); i++; } if (remainderX !=0 || remainderY !=0) { this.as[i]=[remainderX, remainderY]; } this.hideLayers(); this.slideid=goQueueManager.enqueue(this.timePerStep,this,kaMap_slide,[0]);} function kaMap_slide(pos){ if (pos>=this.as.length){this.as=slideid=null;this.showLayers();this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );return;} this.moveBy( this.as[pos][0], this.as[pos][1] ); pos ++; this.slideid=goQueueManager.enqueue(this.timePerStep,this,kaMap_slide,[ pos]);} function kaMap_onkeypress( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onkeypress( e );}function kaMap_onkeyup( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onkeyup( e );}function kaMap_onmousemove( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onmousemove( e );} function kaMap_onmousedown( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onmousedown( e );} function kaMap_onmouseup( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onmouseup( e );} function kaMap_onmouseover( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onmouseover( e );} function kaMap_onmouseout( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.onmouseout( e );} function kaMap_oncontextmenu( e ){ return false;} function kaMap_ondblclick( e ){ if (this.kaMap.currentTool) this.kaMap.currentTool.ondblclick( e );} function kaMap_cancelEvent(e){ e=(e)?e:((event)?event:null); e.returnValue=false; if (e.preventDefault) e.preventDefault(); return false;} function kaMap_registerTool( toolObj ){ this.aTools.push( toolObj );} function kaMap_activateTool( toolObj ){ if (this.currentTool) { this.currentTool.deactivate(); } this.currentTool=toolObj; if (this.theInsideLayer) this.theInsideLayer.style.cursor=this.currentTool.cursor;} function kaMap_deactivateTool( toolObj ){ if (this.currentTool==toolObj) this.currentTool=null; if (this.theInsideLayer) this.theInsideLayer.style.cursor='auto';} function kaMap_checkWrap(){ this.xOffset=safeParseInt(this.theInsideLayer.style.left) + this.nCurrentLeft - this.xOrigin; this.yOffset=safeParseInt(this.theInsideLayer.style.top) + this.nCurrentTop - this.yOrigin; while (this.xOffset > 0) { kaMap_wrapR2L.apply(this, []); } while (this.xOffset < -(this.nBuffer*this.tileWidth)) { kaMap_wrapL2R.apply(this, []); } while (this.yOffset > -(this.nBuffer*this.tileHeight)) { kaMap_wrapB2T.apply(this, []); } while (this.yOffset < -(2*this.nBuffer*this.tileHeight)) { kaMap_wrapT2B.apply(this, []); } var layer=this.aMaps[this.currentMap].aLayers[0].domObj; var img=layer.childNodes[0].style; this.nCurrentTop=safeParseInt(img.top) + this.yOrigin; this.nCurrentLeft=safeParseInt(img.left) + this.xOrigin;} function kaMap_wrapR2L(){ this.xOffset=this.xOffset - (this.nBuffer * this.tileWidth); var layers=this.aMaps[this.currentMap].getLayers(); for( var k in layers) { var d=layers[k].domObj; var refLeft=safeParseInt(d.childNodes[0].style.left); for (var j=0; j=0; i-- ) { if (this.theInsideLayer.childNodes[i].className=='mapLayer') { this.theInsideLayer.removeChild(this.theInsideLayer.childNodes[i]); } } var layers=this.aMaps[this.currentMap].getLayers(); var j=2; for (var i in layers) { var d=kaMap_createMapLayer( layers[i].name ); if (layers[i].name=='__base__') { d.style.zIndex=1; d.style.visibility='visible'; } else { d.style.zIndex=j++; d.style.visibility=layers[i].visible?'visible':'hidden'; d.style.display=layers[i].visible?'block':'none'; } this.theInsideLayer.appendChild( d ); layers[i].domObj=d; layers[i].setOpacity( layers[i].opacity ); } this.nWide=0; this.nHigh=0; this.resize(); this.zoomToExtents( oMap.currentExtents[0], oMap.currentExtents[1], oMap.currentExtents[2], oMap.currentExtents[3] ); this.triggerEvent( KAMAP_MAP_INITIALIZED, this.currentMap ); return true; }} function kaMap_createMapLayer( id ){ var d=document.createElement( 'div' ); d.id=id; d.className='mapLayer'; d.style.position='absolute'; d.style.visibility='visible'; d.style.left='0px'; d.style.top='0px'; d.style.width='3000px'; d.style.height='3000px'; return d;} function kaMap_getCenter(){ var deltaMouseX=this.nCurrentLeft - this.xOrigin + safeParseInt(this.theInsideLayer.style.left); var deltaMouseY=this.nCurrentTop - this.yOrigin + safeParseInt(this.theInsideLayer.style.top); var vpTop=this.nCurrentTop - deltaMouseY; var vpLeft=this.nCurrentLeft - deltaMouseX; var vpCenterX=vpLeft + this.viewportWidth/2; var vpCenterY=vpTop + this.viewportHeight/2; return new Array( vpCenterX, vpCenterY );} function kaMap_getGeoExtents(){ var minx=-1*(safeParseInt(this.theInsideLayer.style.left) - this.xOrigin) * this.cellSize; var maxx=minx + this.viewportWidth * this.cellSize; var maxy=(safeParseInt(this.theInsideLayer.style.top) - this.yOrigin) * this.cellSize; var miny=maxy - this.viewportHeight * this.cellSize; return [minx,miny,maxx,maxy]; } function kaMap_zoomIn(){ this.zoomByFactor(this.aMaps[this.currentMap].zoomIn());} function kaMap_zoomOut(){ this.zoomByFactor(this.aMaps[this.currentMap].zoomOut());} function kaMap_zoomToScale( scale ){ this.zoomByFactor(this.aMaps[this.currentMap].zoomToScale(scale));} function kaMap_zoomByFactor( nZoomFactor ){ if (nZoomFactor==1) { this.triggerEvent( KAMAP_NOTICE, "NOTICE: changing to current scale aborted"); return; } this.cellSize=this.cellSize/nZoomFactor; kaMap_initializeLayers.apply(this, [nZoomFactor]); this.triggerEvent( KAMAP_SCALE_CHANGED, this.getCurrentScale() ); this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );} function kaMap_getCurrentScale(){ return this.aMaps[this.currentMap].aScales[this.aMaps[this.currentMap].currentScale];} function kaMap_setLayerVisibility( name, bVisible ){ this.aMaps[this.currentMap].setLayerVisibility( name, bVisible );} function kaMap_setLayerOpacity( name, opacity ){ this.aMaps[this.currentMap].setLayerOpacity( name, opacity );} function kaMap_registerEventID( eventID ){ return this.eventManager.registerEventID(eventID);} function kaMap_registerForEvent( eventID, obj, func ){ return this.eventManager.registerForEvent(eventID, obj, func);} function kaMap_deregisterForEvent( eventID, obj, func ){ return this.eventManager.deregisterForEvent(eventID, obj, func);} function kaMap_triggerEvent( eventID ){ return this.eventManager.triggerEvent.apply( this.eventManager, arguments );} function kaMap_setMapSize(x_px, y_px){ if(!x_px){x_px=600;} if(!y_px){y_px=600;} var t=this.domObj.style; t.width=x_px + "px"; t.height=y_px + "px"; this.resize();} function safeParseInt( val ){ return Math.round(parseFloat(val));} function _map(szName,szTitle,nCurrentScale, units, aszScales ){ this.name=szName; this.title=szTitle; this.aScales=aszScales; this.currentScale=parseFloat(nCurrentScale); this.units=units; this.resolution=72; this.aLayers=[]; this.defaultExtents=[]; this.currentExtents=[]; this.maxExtents=[]; this.backgroundColor='#ffffff'; this.version="0"; this.kaMap=null; this.zoomIn=_map_zoomIn; this.zoomOut=_map_zoomOut; this.zoomToScale=_map_zoomToScale; this.addLayer=_map_addLayer; this.getLayers=_map_getLayers; this.getLayer=_map_getLayer; this.getScales=_map_getScales; this.setLayerVisibility=_map_setLayerVisibility; this.setLayerOpacity=_map_setLayerOpacity; this.setDefaultExtents=_map_setDefaultExtents; this.setCurrentExtents=_map_setCurrentExtents; this.setMaxExtents=_map_setMaxExtents; this.setBackgroundColor=_map_setBackgroundColor;} function _map_addLayer( layer ){ layer._map=this; this.aLayers.push( layer );} function _map_getLayers(){ return this.aLayers;} function _map_getLayer( name ){ for (var i=0; i 0) { nZoomFactor=this.aScales[this.currentScale]/this.aScales[this.currentScale-1]; this.currentScale=this.currentScale - 1; } return nZoomFactor;} function _map_zoomToScale( scale ){ var nZoomFactor=1; for (var i in this.aScales) { if (this.aScales[i]==scale) { nZoomFactor=this.aScales[this.currentScale]/scale; this.currentScale=parseInt(i); } } return nZoomFactor;} function _map_setLayerVisibility( name, bVisible ){ var layer=this.getLayer( name ); layer.setVisibility( bVisible );} function _map_setLayerOpacity( name, opacity ){ var layer=this.getLayer( name ); layer.setOpacity( opacity );} function _map_setDefaultExtents( minx, miny, maxx, maxy ){ this.defaultExtents=[minx, miny, maxx, maxy]; if (this.currentExtents.length==0) this.setCurrentExtents( minx, miny, maxx, maxy );} function _map_setCurrentExtents( minx, miny, maxx, maxy ){ this.currentExtents=[minx, miny, maxx, maxy];} function _map_setMaxExtents( minx, miny, maxx, maxy ){ this.maxExtents=[minx, miny, maxx, maxy];} function _map_setBackgroundColor( szBgColor ){ this.backgroundColor=szBgColor;} function _layer( szName, bVisible, opacity ){ this.name=szName; this.visible=bVisible; this.opacity=opacity; this.domObj=null; this._map=null; this.setVisibility=_layer_setVisibility; this.setOpacity=_layer_setOpacity; this.setTile=_layer_setTile;} function _layer_setVisibility( bVisible ){ this.visible=bVisible; if (this.domObj) { this.domObj.style.visibility=bVisible?'visible':'hidden'; this.domObj.style.display=bVisible?'block':'none'; } for( var i=0; i