kaMap.js
Summary
No overview generated for 'kaMap.js'
Method Summary
|
static void
|
_queueManager_execute( pos)
|
static Object
|
safeParseInt( val )
special helper function to parse an integer value safely in case
it is represented in IEEE format (scientific notation).
|
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 ++;
var KAMAP_LAYERS_CHANGED = gnLastEventId ++;
var KAMAP_LAYER_STATUS_CHANGED = gnLastEventId ++;
var KAMAP_CONTEXT_MENU = gnLastEventId ++;
var KAMAP_METAEXTENTS_CHANGED = gnLastEventId++;
var KAMAP_MAP_CLICKED = gnLastEventId++;
function kaMap( szID ) {
this.isCSS = false;
this.isW3C = false;
this.isIE4 = false;
this.isNN4 = false;
this.isIE6CSS = false;
if (document.images) {
this.isCSS = (document.body && document.body.style) ? true : false;
this.isW3C = (this.isCSS && document.getElementById) ? true : false;
this.isIE4 = (this.isCSS && document.all) ? true : false;
this.isNN4 = (document.layers) ? true : false;
this.isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
}
this.domObj = this.getRawObject( szID );
this.domObj.style.overflow = 'hidden';
this.hideLayersOnMove = false;
this.loadUnchecked=false;
this.initializationState = 0;
this.bMouseDown = false;
this.lastx = 0;
this.lasty = 0;
this.theInsideLayer = null;
this.viewportWidth = this.getObjectWidth(this.domObj);
this.viewportHeight = this.getObjectHeight(this.domObj);
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.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.aInfoTools = [];
for (var i=0; i<gnLastEventId; i++) {
this.registerEventID( i );
}
this.createLayers();
};
kaMap.prototype.seekLayer = function(doc, name) {
var theObj;
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers[i].name == name) {
theObj = doc.layers[i];
break;
}
if (doc.layers[i].document.layers.length > 0) {
theObj = this.seekLayer(document.layers[i].document, name);
}
}
return theObj;
};
kaMap.prototype.getRawObject = function(obj) {
var theObj;
if (typeof obj == "string") {
if (this.isW3C) {
theObj = document.getElementById(obj);
} else if (this.isIE4) {
theObj = document.all(obj);
} else if (this.isNN4) {
theObj = seekLayer(document, obj);
}
} else {
theObj = obj;
}
return theObj;
};
kaMap.prototype.getObject = function(obj) {
var theObj = this.getRawObject(obj);
if (theObj && this.isCSS) {
theObj = theObj.style;
}
return theObj;
};
kaMap.prototype.getObjectWidth = function(obj) {
var elem = this.getRawObject(obj);
var result = 0;
if (elem.offsetWidth) {
result = elem.offsetWidth;
} else if (elem.clip && elem.clip.width) {
result = elem.clip.width;
} else if (elem.style && elem.style.pixelWidth) {
result = elem.style.pixelWidth;
}
return parseInt(result);
};
kaMap.prototype.getObjectHeight = function(obj) {
var elem = this.getRawObject(obj);
var result = 0;
if (elem.offsetHeight) {
result = elem.offsetHeight;
} else if (elem.clip && elem.clip.height) {
result = elem.clip.height;
} else if (elem.style && elem.style.pixelHeight) {
result = elem.style.pixelHeight;
}
return parseInt(result);
};
kaMap.prototype.zoomTo = function( cgX, cgY ) {
var oMap = this.getCurrentMap();
var inchesPerUnit = new Array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);
var newScale;
var bScaleChanged = false;
if (arguments.length == 3) {
newScale = arguments[2];
bScaleChanged = (newScale != this.getCurrentScale())
} else {
newScale = this.getCurrentScale();
}
var bZoomTo = true;
if (!bScaleChanged) {
var extents = this.getGeoExtents();
if (cgX >= extents[0] && cgX <= extents[2] &&
cgY >= extents[1] && cgY <= extents[3]) {
var cx = (extents[0]+extents[2])/2;
var cy = (extents[1]+extents[3])/2;
var dx = (cx - cgX)/this.cellSize;
var dy = (cgY - cy)/this.cellSize;
this.slideBy(dx,dy);
bZoomTo = false;
}
}
if (bZoomTo) {
this.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
var nFactor = oMap.zoomToScale( newScale );
this.setMapLayers();
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=0; k<layers.length; k++) {
var d = layers[k].domObj;
for(var j=0; j<this.nHigh; j++) {
for( var i=0; i<this.nWide; i++) {
var img = d.childNodes[(j*this.nWide)+i];
img.src = this.aPixel.src;
img.style.top = (this.nCurrentTop + j*this.tileHeight - this.yOrigin) + "px";
img.style.left = (this.nCurrentLeft + i*this.tileWidth - this.xOrigin) + "px";
layers[k].setTile(img);
}
}
}
this.checkWrap( );
this.updateObjects();
}
if (bScaleChanged) {
this.triggerEvent( KAMAP_SCALE_CHANGED, this.getCurrentScale() );
}
this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );
};
kaMap.prototype.zoomToExtents = function(minx, miny, maxx, maxy) {
var inchesPerUnit = new Array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);
var oMap = this.getCurrentMap();
var cgX = (maxx+minx)/2;
var cgY = (maxy+miny)/2;
var tmpCellSizeX = (maxx - minx)/this.viewportWidth;
var tmpCellSizeY = (maxy - miny)/this.viewportHeight;
var tmpCellSize = Math.max( tmpCellSizeX, tmpCellSizeY );
var tmpScale = tmpCellSize * oMap.resolution * inchesPerUnit[oMap.units];
var newScale = oMap.aScales[0];
for (var i=1; i<oMap.aScales.length; i++) {
if (tmpScale >= oMap.aScales[i]) {
break;
}
newScale = oMap.aScales[i];
}
this.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
var nFactor = oMap.zoomToScale( newScale );
this.setMapLayers();
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=0; k<layers.length; k++) {
var d = layers[k].domObj;
for(var j=0; j<this.nHigh; j++) {
for( var i=0; i<this.nWide; i++) {
var img = d.childNodes[(j*this.nWide)+i];
img.src = this.aPixel.src;
img.style.top = (this.nCurrentTop + j*this.tileHeight - this.yOrigin) + "px";
img.style.left = (this.nCurrentLeft + i*this.tileWidth - this.xOrigin) + "px";
layers[k].setTile(img);
}
}
}
this.checkWrap( );
this.updateObjects();
this.triggerEvent( KAMAP_SCALE_CHANGED, this.getCurrentScale() );
this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );
};
kaMap.prototype.createDrawingCanvas = function( idx ) {
var d = document.createElement( 'div' );
d.style.position = 'absolute';
d.style.left = '0px';
d.style.top = '0px';
d.style.width= '3000px';
d.style.height = '3000px';
d.style.zIndex = idx;
this.theInsideLayer.appendChild( d );
this.aCanvases.push( d );
d.kaMap = this;
return d;
};
kaMap.prototype.removeDrawingCanvas = function( canvas ) {
for (var i=0; i<this.aCanvases.length;i++) {
if (this.aCanvases[i] == canvas) {
this.aCanvases.splice( i, 1 );
}
}
this.theInsideLayer.removeChild(canvas);
canvas.kaMap = null;
return true;
};
kaMap.prototype.addObjectGeo = function( canvas, lon, lat, obj ) {
obj.lon = lon;
obj.lat = lat;
var aPix = this.geoToPix( lon, lat );
return this.addObjectPix( canvas, aPix[0], aPix[1], obj );
};
kaMap.prototype.addObjectPix = function( canvas, x, y, obj ) {
var xOffset = (obj.xOffset) ? obj.xOffset : 0;
var yOffset = (obj.yOffset) ? obj.yOffset : 0;
var top = (y - this.yOrigin + yOffset);
var left = (x - this.xOrigin + xOffset);
obj.style.position = 'absolute';
obj.style.top = top + "px";
obj.style.left = left + "px";
obj.canvas = canvas;
canvas.appendChild( obj );
this.aObjects.push( obj );
return true;
};
kaMap.prototype.shiftObject = function( x, y, obj ) {
var top = safeParseInt(obj.style.top);
var left = safeParseInt(obj.style.left);
obj.style.top = (top + y) + "px";
obj.style.left = (left + x) + "px";
return true;
};
kaMap.prototype.removeObject = function( obj ) {
if (obj == null) {
for (var i=0; i<this.aObjects.length; i++) {
obj = this.aObjects[i];
if (obj.canvas) {
obj.canvas.removeChild(obj);
}
}
this.aObjects = [];
return true;
} else {
for (var i=0; i<this.aObjects.length; i++) {
if (this.aObjects[i] == obj) {
obj = this.aObjects[i];
if (obj.canvas) {
obj.canvas.removeChild( obj );
obj.canvas = null;
}
this.aObjects.splice(i,1);
return true;
}
}
return false;
}
};
kaMap.prototype.removeAllObjects = function(canvas) {
for (var i=0; i<this.aObjects.length; i++) {
obj = this.aObjects[i];
if (obj.canvas && obj.canvas == canvas) {
obj.canvas.removeChild( obj );
obj.canvas = null;
this.aObjects.splice(i--,1);
}
}
return true;
};
kaMap.prototype.centerObject = function(obj) {
var vpX = -safeParseInt(this.theInsideLayer.style.left) + this.viewportWidth/2;
var vpY = -safeParseInt(this.theInsideLayer.style.top) + this.viewportHeight/2;
var xOffset = (obj.xOffset)?obj.xOffset:0;
var yOffset = (obj.yOffset)?obj.yOffset:0;
var dx = safeParseInt(obj.style.left) - xOffset- vpX;
var dy = safeParseInt(obj.style.top) - yOffset - vpY;
this.slideBy(-dx, -dy);
return true;
};
kaMap.prototype.geoToPix = function( gX, gY ) {
var pX = gX / this.cellSize;
var pY = -1 * gY / this.cellSize;
return [Math.floor(pX), Math.floor(pY)];
};
kaMap.prototype.pixToGeo = function( pX, pY ) {
var bAdjust = (arguments.length == 3 && arguments[2]) ? true : false;
if (bAdjust) {
pX = pX + this.xOrigin;
pY = pY + this.yOrigin;
}
var gX = -1 * pX * this.cellSize;
var gY = pY * this.cellSize;
return [gX, gY];
};
kaMap.prototype.initialize = function() {
if (this.initializationState == 2) {
this.triggerEvent( KAMAP_ERROR, 'ERROR: ka-Map! is already initialized!' );
return false;
} else if (this.intializationState == 1) {
this.triggerEvent( KAMAP_WARNING, 'WARNING: ka-Map! is currently initializing ... wait for the KAMAP_INITIALIZED event to be triggered.' );
return false;
}
this.initializationState = 1;
var szURL = this.server+this.init;
var sep = (this.init.indexOf("?") == -1) ? "?" : "&";
if (arguments.length > 0 && arguments[0] != '') {
szURL = szURL + sep + "map="+ arguments[0];
sep = "&";
}
if (arguments.length > 1 && arguments[1] != '') {
szURL = szURL + sep + "extents="+ arguments[1];
sep = "&";
}
if (arguments.length > 2 && arguments[2] != '') {
szURL = szURL + sep + "centerPoint="+ arguments[2];
sep = "&";
}
call(szURL, this, this.initializeCallback);
return true;
};
kaMap.prototype.initializeCallback = function( 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;
}
eval(szInit);
this.triggerEvent( KAMAP_INITIALIZED );
this.initializationState = 2;
};
kaMap.prototype.setBackgroundColor = function( color ) {
this.domObj.style.backgroundColor = color;
return true;
};
kaMap.prototype.createLayers = function() {
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.onkeypress = kaMap_onkeypress;
this.theInsideLayer.ondblclick = kaMap_ondblclick;
this.theInsideLayer.oncontextmenu = kaMap_oncontextmenu;
this.theInsideLayer.onmousewheel = kaMap_onmousewheel;
if (window.addEventListener &&
navigator.product && navigator.product == "Gecko") {
this.domObj.addEventListener( "DOMMouseScroll", kaMap_onmousewheel, false );
}
this.theInsideLayer.ondragstart = new Function([], 'var e=e?e:event;e.cancelBubble=true;e.returnValue=false;return false;');
};
kaMap.prototype.initializeLayers = function(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=0; k<layers.length; k++) {
var d = layers[k].domObj;
for(var j=0; j<this.nHigh; j++) {
for( var i=0; i<this.nWide; i++) {
var img = d.childNodes[(j*this.nWide)+i];
img.src = this.aPixel.src;
img.style.top = (this.nCurrentTop + j*this.tileHeight - this.yOrigin) + "px";
img.style.left = (this.nCurrentLeft + i*this.tileWidth - this.xOrigin) + "px";
layers[k].setTile(img);
}
}
}
this.checkWrap();
this.updateObjects();
};
kaMap.prototype.paintLayer = function(l) {
var d = l.domObj;
for(var j=0; j<this.nHigh; j++) {
for( var i=0; i<this.nWide; i++) {
var img = d.childNodes[(j*this.nWide)+i];
img.style.top = (this.nCurrentTop + j*this.tileHeight - this.yOrigin) + "px";
img.style.left = (this.nCurrentLeft + i*this.tileWidth - this.xOrigin) + "px";
l.setTile(img);
}
}
this.checkWrap();
};
kaMap.prototype.updateObjects = function() {
for (var i=0; i<this.aObjects.length;i++) {
var obj = this.aObjects[i];
var xOffset = (obj.xOffset) ? obj.xOffset : 0;
var yOffset = (obj.yOffset) ? obj.yOffset : 0;
var aPix = this.geoToPix( obj.lon, obj.lat );
var top = (aPix[1] - this.yOrigin + yOffset);
var left = (aPix[0] - this.xOrigin + xOffset);
obj.style.top = top + "px";
obj.style.left = left + "px";
}
};
kaMap.prototype.resize = function( ) {
if (this.initializationState != 2) {
return false;
}
var newViewportWidth = this.getObjectWidth(this.domObj);
var newViewportHeight = this.getObjectHeight(this.domObj);
if (this.viewportWidth == null) {
this.theInsideLayer.style.top = (-1*this.nCurrentTop + this.yOrigin) + "px";
this.theInsideLayer.style.left = (-1*this.nCurrentLeft + this.xOrigin) + "px";
this.theInsideLayer.style.top = (safeParseInt(this.theInsideLayer.style.top) + (newViewportHeight - viewportHeight)/2)+"px";
this.theInsideLayer.style.left = (safeParseInt(this.theInsideLayer.style.top) + (newViewportWidth - viewportWidth)/2)+"px";
this.viewportWidth = newViewportWidth;
this.viewportHeight = newViewportHeight;
}
var newWide = Math.ceil((newViewportWidth / this.tileWidth) + 2*this.nBuffer);
var newHigh = Math.ceil((newViewportHeight / this.tileHeight) + 2*this.nBuffer);
this.viewportWidth = newViewportWidth;
this.viewportHeight = newViewportHeight;
if (this.nHigh == 0 && this.nWide == 0) {
this.nWide = newWide;
}
while (this.nHigh < newHigh) {
this.appendRow();
}
while (this.nHigh > newHigh && newHigh > 3) {
this.removeRow();
}
while (this.nWide < newWide) {
this.appendColumn();
}
while (this.nWide > newWide && newWide > 3) {
this.removeColumn();
}
var map = this.getCurrentMap();
var layers =map.getLayers();
for(i=0;i<layers.length;i++) {
layers[i].setTileLayer();
}
this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );
this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );
};
kaMap.prototype.createImage = function( 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.galleryimg = "no";
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;
img.ie_hack = false;
if (this.isIE4) {
if (obj.imageformat &&
(obj.imageformat.toLowerCase() == "alpha")) {
img.ie_hack = true;
}
}
return img;
};
kaMap.prototype.resetTile = function( id, bForce ) {
var img = this.DHTMLapi.getRawObject(id);
if (img.layer) {
img.layer.setTile(this, bForce);
}
};
kaMap.prototype.reloadImage = function(id) {
};
kaMap.prototype.resetImage = function(id) {
};
kaMap_imgOnError = function(e) {
if (this.layer) {
this.layer.setTile(this, true);
}
};
kaMap_imgOnLoad = function(e) {
if ((this.ie_hack) &&
(this.src != this.kaMap.aPixel.src)) {
var src = this.src;
this.src = this.kaMap.aPixel.src;
this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"')";
}
this.style.visibility = 'visible';
};
kaMap.prototype.appendRow = function(layer) {
if (this.nWide == 0) {
return;
}
var layers = null;
if(arguments.length==1) {
layers = Array(layer);
} else {
layers = this.aMaps[this.currentMap].getLayers();
}
for( var i=0; i<layers.length; i++) {
var obj = layers[i].domObj;
for (var j=0; j<this.nWide; j++) {
var top = this.nCurrentTop + (this.nHigh * this.tileHeight);
var left = this.nCurrentLeft + (j * this.tileWidth);
var img = this.createImage( top, left, layers[i] );
if (this.isIE4) {
img.style.filter = "Alpha(opacity="+layers[i].opacity+")";
}
obj.appendChild( img );
}
}
this.nHigh = this.nHigh + 1;
};
kaMap.prototype.appendColumn = function(layer) {
if (this.nHigh == 0) {
return;
}
var layers = null;
if(arguments.length==1) {
layers = Array(layer);
} else {
layers = this.aMaps[this.currentMap].getLayers();
}
for( var i=0; i<layers.length; i++) {
var obj = layers[i].domObj;
for(var j=this.nHigh-1; j>=0; j--) {
var top = this.nCurrentTop + (j * this.tileHeight);
var left = this.nCurrentLeft + (this.nWide * this.tileWidth);
var img = this.createImage( top, left, layers[i] );
if (this.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;
};
kaMap.prototype.removeColumn = function(layer) {
if (this.nWide < 3) {
return;
}
var layers = null;
if(arguments.length==1) {
layers = Array(layer);
} else {
layers = this.aMaps[this.currentMap].getLayers();
}
for( var i=0; i<layers.length; i++) {
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;
};
kaMap.prototype.removeRow = function(layer) {
if (this.nHigh < 3) {
return;
}
var layers = null;
if(arguments.length==1) {
layers = Array(layer);
} else {
layers = this.aMaps[this.currentMap].getLayers();
}
for( var i=0; i<layers.length; i++) {
var d = layers[i].domObj;
for(var j=this.nWide - 1; j >= 0; j--) {
var img = d.childNodes[((this.nHigh-1)*this.nWide)+j];
d.removeChild( img );
img.onload = null;
img.onerror = null;
}
}
this.nHigh = this.nHigh - 1;
};
kaMap.prototype.hideLayers = function() {
if (!this.hideLayersOnMove) {
return;
}
if (this.layersHidden) {
return;
}
var layers = this.aMaps[this.currentMap].getLayers();
for( var i=0; i<layers.length; i++) {
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;
};
kaMap.prototype.showLayers = function() {
if (!this.hideLayersOnMove) {
return;
}
if (!this.layersHidden) {
return;
}
var layers = this.aMaps[this.currentMap].getLayers();
for( var i=0; i<layers.length; i++) {
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;
};
kaMap.prototype.moveBy = function( x, y ) {
var til = this.theInsideLayer;
til.style.top = (safeParseInt(til.style.top)+y) + 'px';
til.style.left = (safeParseInt(til.style.left)+x )+ 'px';
this.checkWrap();
};
kaMap.prototype.slideBy = function(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(i<steps) {
if (i>0) {
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,this.slide,[0]);
};
kaMap.prototype.slide = function(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,this.slide,[ pos]);
};
kaMap_onkeypress = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onkeypress( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onkeypress(e);
}
}
};
kaMap_onmousemove = function( e ) {
e = (e)?e:((event)?event:null);
if (e.button==2) {
this.kaMap.triggerEvent( KAMAP_CONTEXT_MENU );
}
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmousemove( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onmousemove(e);
}
}
};
kaMap_onmousedown = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmousedown( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onmousedown(e);
}
}
};
kaMap_onmouseup = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmouseup( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onmouseup(e);
}
}
};
kaMap_onmouseover = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmouseover( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onmouseover(e);
}
}
};
kaMap_onmouseout = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmouseout( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].onmouseout(e);
}
}
};
kaMap_oncontextmenu = function( e ) {
e = e?e:event;
if (e.preventDefault) {
e.preventDefault();
}
return false;
};
kaMap_ondblclick = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.ondblclick( e );
}
if (this.kaMap.aInfoTools.length > 0) {
for (var i=0; i<this.kaMap.aInfoTools.length; i++) {
this.kaMap.aInfoTools[i].ondblclick(e);
}
}
};
kaMap_onmousewheel = function( e ) {
if (this.kaMap.currentTool) {
this.kaMap.currentTool.onmousewheel( e );
}
};
kaMap.prototype.cancelEvent = function(e) {
e = (e)?e:((event)?event:null);
e.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
}
return false;
};
kaMap.prototype.registerTool = function( toolObj ) {
this.aTools.push( toolObj );
};
kaMap.prototype.activateTool = function( toolObj ) {
if (toolObj.isInfoTool()) {
this.aInfoTools.push(toolObj);
} else {
if (this.currentTool) {
this.currentTool.deactivate();
}
this.currentTool = toolObj;
if (this.theInsideLayer) {
this.setCursor(this.currentTool.cursor);
}
}
};
kaMap.prototype.deactivateTool = function( toolObj ) {
if (toolObj.isInfoTool()) {
for (var i=0; i<this.aInfoTools.length; i++) {
if (this.aInfoTools[i] == toolObj) {
this.aInfoTools.splice(i,1);
break;
}
}
} else {
if (this.currentTool == toolObj) {
this.currentTool = null;
}
if (this.theInsideLayer) {
this.theInsideLayer.style.cursor = 'auto';
}
}
};
kaMap.prototype.setCursor = function(cursor) {
if (cursor && cursor.length && typeof cursor == 'object') {
for (var i = 0; i < cursor.length; i++) {
this.theInsideLayer.style.cursor = cursor[i];
if (this.theInsideLayer.style.cursor == cursor[i]) {
break;
}
}
} else if (typeof cursor == 'string') {
this.theInsideLayer.style.cursor = cursor;
} else {
this.theInsideLayer.style.cursor = 'auto';
}
};
kaMap.prototype.checkWrap = function() {
var bWrapped = false;
this.checkMaxExtents();
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) {
this.wrapR2L();
bWrapped = true;
}
while (this.xOffset < -(this.nBuffer*this.tileWidth)) {
this.wrapL2R();
bWrapped = true;
}
while (this.yOffset > -(this.nBuffer*this.tileHeight)) {
this.wrapB2T();
bWrapped = true;
}
while (this.yOffset < -(2*this.nBuffer*this.tileHeight)) {
this.wrapT2B();
bWrapped = true;
}
var layer = this.aMaps[this.currentMap].getLayers()[0];
if (layer) {
var img = layer.domObj.childNodes[0].style;
this.nCurrentTop = safeParseInt(img.top) + this.yOrigin;
this.nCurrentLeft = safeParseInt(img.left) + this.xOrigin;
}
if (bWrapped) {
this.triggerEvent( KAMAP_METAEXTENTS_CHANGED, this.getMetaExtents() );
}
};
kaMap.prototype.checkMaxExtents = function() {
var maxExtents = this.getCurrentMap().maxExtents;
if (maxExtents.length == 4) {
if ((maxExtents[0] >= maxExtents[2]) || (maxExtents[1] >= maxExtents[3])) {
return false;
}
var geoExtents = this.getGeoExtents();
var hPixelAdjustment = 0;
var vPixelAdjustment = 0;
if (geoExtents[0] < maxExtents[0]) {
hPixelAdjustment = Math.round((maxExtents[0] - geoExtents[0]) / this.cellSize);
}
if (geoExtents[2] > maxExtents[2]) {
if(hPixelAdjustment != 0)
{
hPixelAdjustment += Math.round((maxExtents[2] - geoExtents[2]) / this.cellSize);
hPixelAdjustment /= 2;
} else {
hPixelAdjustment += Math.round((maxExtents[2] - geoExtents[2]) / this.cellSize);
}
}
if(hPixelAdjustment != 0) {
this.theInsideLayer.style.left = (safeParseInt(this.theInsideLayer.style.left) - hPixelAdjustment) + 'px';
}
if(geoExtents[1] < maxExtents[1]) {
vPixelAdjustment = Math.round((maxExtents[1] - geoExtents[1]) / this.cellSize);
}
if(geoExtents[3] > maxExtents[3]) {
if(vPixelAdjustment != 0) {
vPixelAdjustment += Math.round((maxExtents[3] - geoExtents[3]) / this.cellSize);
vPixelAdjustment /= 2;
} else {
vPixelAdjustment = Math.round((maxExtents[3] - geoExtents[3]) / this.cellSize);
}
}
if(vPixelAdjustment != 0) {
this.theInsideLayer.style.top = (safeParseInt(this.theInsideLayer.style.top) + vPixelAdjustment) + 'px';
}
}
};
kaMap.prototype.wrapR2L = function() {
this.xOffset = this.xOffset - (this.nBuffer * this.tileWidth);
var layers = this.aMaps[this.currentMap].getLayers();
for( var k=0; k<layers.length; k++) {
var d = layers[k].domObj;
var refLeft = safeParseInt(d.childNodes[0].style.left);
for (var j=0; j<this.nHigh; j++) {
var imgLast = d.childNodes[((j+1)*this.nWide)-1];
var imgNext = d.childNodes[j*this.nWide];
imgLast.style.left = (refLeft - this.tileWidth) + 'px';
imgLast.src = this.aPixel.src;
d.removeChild(imgLast);
d.insertBefore(imgLast, imgNext);
if (layers[k].visible) {
layers[k].setTile(imgLast);
}
}
}
};
kaMap.prototype.wrapL2R = function() {
this.xOffset = this.xOffset + (this.nBuffer*this.tileWidth);
var layers = this.aMaps[this.currentMap].getLayers();
for( var k=0; k<layers.length; k++) {
var d = layers[k].domObj;
var refLeft = safeParseInt(d.childNodes[this.nWide-1].style.left);
for (var j=0; j<this.nHigh; j++) {
var imgFirst = d.childNodes[j*this.nWide];
var imgNext;
if (j < this.nHigh-1) {
imgNext = d.childNodes[((j+1)*this.nWide)];
} else {
imgNext = null;
}
imgFirst.style.left = (refLeft + this.tileWidth) + 'px';
imgFirst.src = this.aPixel.src;
d.removeChild(imgFirst);
if (imgNext) {
d.insertBefore(imgFirst, imgNext);
} else {
d.appendChild(imgFirst);
}
if (layers[k].visible) {
layers[k].setTile(imgFirst);
}
}
}
};
kaMap.prototype.wrapT2B = function() {
this.yOffset = this.yOffset + (this.nBuffer*this.tileHeight);
var layers = this.aMaps[this.currentMap].getLayers();
for( var k=0; k<layers.length; k++) {
var d = layers[k].domObj;
var refTop = safeParseInt(d.childNodes[(this.nHigh*this.nWide)-1].style.top);
for (var i=0; i<this.nWide; i++) {
var imgBottom = d.childNodes[0];
imgBottom.style.top = (refTop + this.tileHeight) + 'px';
imgBottom.src = this.aPixel.src;
d.removeChild(imgBottom);
d.appendChild(imgBottom);
if (layers[k].visible) {
layers[k].setTile(imgBottom);
}
}
}
};
kaMap.prototype.wrapB2T = function() {
this.yOffset = this.yOffset - (this.nBuffer*this.tileHeight);
var layers = this.aMaps[this.currentMap].getLayers();
for( var k=0; k<layers.length; k++) {
var d = layers[k].domObj;
var refTop = safeParseInt(d.childNodes[0].style.top);
for (var i=0; i<this.nWide; i++) {
var imgTop = d.childNodes[(this.nHigh*this.nWide)-1];
imgTop.style.top = (refTop - this.tileHeight) + 'px';
imgTop.src = this.aPixel.src;
d.removeChild(imgTop);
d.insertBefore(imgTop, d.childNodes[0]);
if (layers[k].visible) {
layers[k].setTile(imgTop);
}
}
}
};
kaMap.prototype.addMap = function( oMap ) {
oMap.kaMap = this;
this.aMaps[oMap.name] = oMap;
};
kaMap.prototype.getMaps = function() {
return this.aMaps;
};
kaMap.prototype.getCurrentMap = function() {
return this.aMaps[this.currentMap];
};
kaMap.prototype.selectMap = function( name ) {
if (!this.aMaps[name]) {
return false;
} else {
this.currentMap = name;
var oMap = this.getCurrentMap();
this.setBackgroundColor(oMap.backgroundColor);
this.setMapLayers();
if (arguments[1] && arguments[1].length == 3) {
this.zoomTo(arguments[1][0], arguments[1][1], arguments[1][2]);
oMap.aZoomTo.length = 0;
} else if (oMap.aZoomTo.length != 0) {
this.zoomTo(oMap.aZoomTo[0], oMap.aZoomTo[1], oMap.aZoomTo[2]);
oMap.aZoomTo.length = 0;
} else if (arguments[1] && arguments[1].length == 4) {
this.zoomToExtents( arguments[1][0], arguments[1][1],
arguments[1][2], arguments[1][3] );
} else {
this.zoomToExtents( oMap.currentExtents[0], oMap.currentExtents[1],
oMap.currentExtents[2], oMap.currentExtents[3] );
}
this.triggerEvent( KAMAP_MAP_INITIALIZED, this.currentMap );
return true;
}
};
kaMap.prototype.setMapLayers = function( ) {
var oMap = this.getCurrentMap();
for(var i = this.theInsideLayer.childNodes.length - 1; i>=0; i-- ) {
if (this.theInsideLayer.childNodes[i].className == 'mapLayer') {
this.theInsideLayer.childNodes[i].appended=false;
this.theInsideLayer.removeChild(this.theInsideLayer.childNodes[i]); }
}
layers=oMap.getLayers();
for( var i=0; i<layers.length; i++) {
if(!layers[i].domObj) {
var d = this.createMapLayer( layers[i].name );
this.theInsideLayer.appendChild( d );
d.appended=true;
layers[i].domObj = d;
layers[i].setOpacity( layers[i].opacity );
layers[i].setZIndex( layers[i].zIndex );
layers[i].setVisibility( layers[i].visible );
this.nWide = 0;
this.nHigh = 0;
this.drawGroup(layers[i]);
} else if (!layers[i].domObj.appended) {
this.theInsideLayer.appendChild( layers[i].domObj );
layers[i].domObj.appended=true;
layers[i].setZIndex( layers[i].zIndex );
}
}
return true;
};
kaMap.prototype.drawGroup = function(group) {
var newViewportWidth = this.getObjectWidth(this.domObj);
var newViewportHeight = this.getObjectHeight(this.domObj);
if (this.viewportWidth == null) {
this.theInsideLayer.style.top = (-1*this.nCurrentTop + this.yOrigin) + "px";
this.theInsideLayer.style.left = (-1*this.nCurrentLeft + this.xOrigin) + "px";
this.viewportWidth = newViewportWidth;
this.viewportHeight = newViewportHeight;
}
var newWide = Math.ceil((newViewportWidth / this.tileWidth) + 2*this.nBuffer);
var newHigh = Math.ceil((newViewportHeight / this.tileHeight) + 2*this.nBuffer);
this.viewportWidth = newViewportWidth;
this.viewportHeight = newViewportHeight;
if (this.nHigh == 0 && this.nWide == 0) {
this.nWide = newWide;
}
while (this.nHigh < newHigh) {
this.appendRow(group);
}
while (this.nHigh > newHigh) {
this.removeRow(group);
}
while (this.nWide < newWide) {
this.appendColumn(group);
}
while (this.nWide > newWide) {
this.removeColumn(group);
}
return true;
};
kaMap.prototype.createMapLayer = function( 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';
d.appended= false;
return d;
};
kaMap.prototype.addMapLayer = function( l ) {
var map = this.getCurrentMap();
map.addLayer(l);
this.setMapLayers();
this.paintLayer(l);
this.triggerEvent( KAMAP_LAYERS_CHANGED, this.currentMap );
};
kaMap.prototype.removeMapLayer = function( id ) {
var map = this.getCurrentMap();
var layer = map.getLayer(id);
if (!layer) {
return false;
}
if (map.removeLayer ( map.getLayer(id) )) {
this.setMapLayers();
this.triggerEvent( KAMAP_LAYERS_CHANGED, this.currentMap );
}
};
kaMap.prototype.getCenter = function() {
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 );
};
kaMap.prototype.getGeoExtents = function() {
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];
};
kaMap.prototype.getMetaExtents = function() {
var result = this.getGeoExtents();
var oMap = this.getCurrentMap();
layers=oMap.getLayers();
for( var i=0; i<layers.length; i++) {
if(layers[i].domObj) {
var d = layers[i].domObj;
var pl = safeParseInt(d.childNodes[0].style.left);
var pt = safeParseInt(d.childNodes[0].style.top);
var glt = this.pixToGeo(pl,pt,true);
var left = -1*glt[0];
var top = -1*glt[1];
var right = left + this.nWide*this.tileWidth*this.cellSize;
var bottom = top - this.nHigh*this.tileHeight*this.cellSize;
result = [left, bottom, right, top];
break;
}
}
return result;
};
kaMap.prototype.zoomIn = function() {
this.zoomByFactor(this.aMaps[this.currentMap].zoomIn());
};
kaMap.prototype.zoomOut = function() {
this.zoomByFactor(this.aMaps[this.currentMap].zoomOut());
};
kaMap.prototype.zoomToScale = function( scale ) {
this.zoomByFactor(this.aMaps[this.currentMap].zoomToScale(scale));
};
kaMap.prototype.zoomByFactor = function( nZoomFactor ) {
if (nZoomFactor == 1) {
this.triggerEvent( KAMAP_NOTICE, "NOTICE: changing to current scale aborted");
return;
}
this.cellSize = this.cellSize/nZoomFactor;
this.setMapLayers();
this.initializeLayers(nZoomFactor);
this.triggerEvent( KAMAP_SCALE_CHANGED, this.getCurrentScale() );
this.triggerEvent( KAMAP_EXTENTS_CHANGED, this.getGeoExtents() );
};
kaMap.prototype.getCurrentScale = function() {
return this.aMaps[this.currentMap].aScales[this.aMaps[this.currentMap].currentScale];
};
kaMap.prototype.setLayerQueryable = function( name, bQueryable ) {
this.aMaps[this.currentMap].setLayerQueryable( name, bQueryable );
};
kaMap.prototype.setLayerVisibility = function( name, bVisible ) {
if(!this.loadUnchecked && bVisible) {
layer=this.aMaps[this.currentMap].getLayer(name);
layer.visible=true;
this.setMapLayers();
this.aMaps[this.currentMap].setLayerVisibility( name, bVisible );
this.paintLayer(layer);
} else {
this.aMaps[this.currentMap].setLayerVisibility( name, bVisible );
}
};
kaMap.prototype.setLayerOpacity = function( name, opacity ) {
this.aMaps[this.currentMap].setLayerOpacity( name, opacity );
};
kaMap.prototype.registerEventID = function( eventID ) {
return this.eventManager.registerEventID(eventID);
};
kaMap.prototype.registerForEvent = function( eventID, obj, func ) {
return this.eventManager.registerForEvent(eventID, obj, func);
};
kaMap.prototype.deregisterForEvent = function( eventID, obj, func ) {
return this.eventManager.deregisterForEvent(eventID, obj, func);
};
kaMap.prototype.triggerEvent = function( eventID ) {
return this.eventManager.triggerEvent.apply( this.eventManager, arguments );
};
function safeParseInt( val ) {
return Math.round(parseFloat(val));
};
function _map(o) {
this.aLayers = [];
this.aZoomTo = [];
this.kaMap = null;
this.name = (typeof(o.name) != 'undefined') ? o.name : 'noname';
this.title = (typeof(o.title) != 'undefined') ? o.title : 'no title';
this.aScales = (typeof(o.scales) != 'undefined') ? o.scales : [1];
this.currentScale = (typeof(o.currentScale) != 'undefined') ? parseFloat(o.currentScale) : 0;
this.units = (typeof(o.units) != 'undefined') ? o.units : 5;
this.resolution = (typeof(o.resolution) != 'undefined') ? o.resolution:72;
this.defaultExtents = (typeof(o.defaultExtents) != 'undefined') ? o.defaultExtents:[];
this.currentExtents = (typeof(o.currentExtents) != 'undefined') ? o.currentExtents:[];
this.maxExtents = (typeof(o.maxExtents) != 'undefined') ? o.maxExtents : [];
this.backgroundColor = (typeof(o.backgroundColor) != 'undefined') ? o.backgroundColor : '#ffffff';
this.version = (typeof(o.version) != 'undefined') ? o.version : "";
};
_map.prototype.addLayer = function( layer ) {
layer._map = this;
layer.zIndex = this.aLayers.length;
this.aLayers.push( layer );
};
_map.prototype.removeLayer = function( l ) {
var alayer=Array();
for(i=0,a=0;i<this.aLayers.length;i++) {
if(this.aLayers[i]!=l) {
alayer[a]=this.aLayers[i];
a++;
}
}
this.aLayers=alayer;
return true;
};
_map.prototype.getQueryableLayers = function() {
var r = [];
var l = this.getLayers();
for( var i=0; i<l.length; i++) {
if (l[i].isQueryable()) {
r.push(l[i]);
}
}
return r;
};
_map.prototype.getLayers = function() {
var r = [];
for( var i=0; i<this.aLayers.length; i++) {
if (this.aLayers[i].isVisible() &&
(this.aLayers[i].visible || this.kaMap.loadUnchecked) ) {
r.push(this.aLayers[i]);
}
}
return r;
};
_map.prototype.getAllQueryableLayers = function() {
var r = [];
for( var i=0; i<this.aLayers.length; i++) {
if (this.aLayers[i].isQueryable()) {
r.push(this.aLayers[i]);
}
}
return r;
};
_map.prototype.getAllLayers = function() {
return this.aLayers;
};
_map.prototype.getLayer = function( name ) {
for (var i=0; i<this.aLayers.length; i++) {
if (this.aLayers[i].name == name) {
return this.aLayers[i];
}
}
};
_map.prototype.getScales = function() {
return this.aScales;
};
_map.prototype.zoomIn = function() {
var nZoomFactor = 1;
if (this.currentScale < this.aScales.length - 1) {
nZoomFactor = this.aScales[this.currentScale]/this.aScales[this.currentScale+1];
this.currentScale = this.currentScale + 1;
}
return nZoomFactor;
};
_map.prototype.zoomOut = function() {
var nZoomFactor = 1;
if (this.currentScale > 0) {
nZoomFactor = this.aScales[this.currentScale]/this.aScales[this.currentScale-1];
this.currentScale = this.currentScale - 1;
}
return nZoomFactor;
};
_map.prototype.zoomToScale = function( scale ) {
var nZoomFactor = 1;
for (var i=0; i<this.aScales.length; i++) {
if (this.aScales[i] == scale) {
nZoomFactor = this.aScales[this.currentScale]/scale;
this.currentScale = parseInt(i);
}
}
return nZoomFactor;
};
_map.prototype.setLayerQueryable = function( name, bQueryable ) {
var layer = this.getLayer( name );
if(typeof(layer) != 'undefined') {
layer.setQueryable( bQueryable );
}
};
_map.prototype.setLayerVisibility = function( name, bVisible ) {
var layer = this.getLayer( name );
if(typeof(layer) != 'undefined') {
layer.setVisibility( bVisible );
}
};
_map.prototype.setLayerOpacity = function( name, opacity ) {
var layer = this.getLayer( name );
if(typeof(layer) != 'undefined') {
layer.setOpacity( opacity );
}
};
_map.prototype.setDefaultExtents = function( minx, miny, maxx, maxy ){
this.defaultExtents = [minx, miny, maxx, maxy];
if (this.currentExtents.length == 0)
this.setCurrentExtents( minx, miny, maxx, maxy );
};
_map.prototype.setCurrentExtents = function( minx, miny, maxx, maxy ) {
this.currentExtents = [minx, miny, maxx, maxy];
};
_map.prototype.setMaxExtents = function( minx, miny, maxx, maxy ) {
this.maxExtents = [minx, miny, maxx, maxy];
};
_map.prototype.setBackgroundColor = function( szBgColor ) {
this.backgroundColor = szBgColor;
};
function _layer( o ) {
this.domObj = null;
this._map = null;
this.name = (typeof(o.name) != 'undefined') ? o.name : 'unnamed';
this.visible = (typeof(o.visible) != 'undefined') ? o.visible : true;
this.opacity = (typeof(o.opacity) != 'undefined') ? o.opacity : 100;
this.imageformat = (typeof(o.imageformat) != 'undefined') ? o.imageformat : null;
this.queryable = (typeof(o.queryable) != 'undefined') ? o.queryable : false;
this.queryState = (typeof(o.queryable) != 'undefined') ? o.queryable : false;
this.tileSource = (typeof(o.tileSource) != 'undefined') ? o.tileSource : 'auto';
this.scales = (typeof(o.scales) != 'undefined') ? o.scales : new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
this.toLoad=0;
var ts = new Date();
this.timeStamp = Math.round(ts.getTime()/1000) + ts.getTimezoneOffset() * 60;
this.redrawInterval = (typeof(o.redrawInterval) != 'undefined') ? o.redrawInterval : -1;
this.refreshInterval = (typeof(o.refreshInterval) != 'undefined') ? o.refreshInterval : -1;
if (this.refreshInterval > 0) {
goQueueManager.enqueue( this.refreshInterval*1000, this, this.redraw );
}
};
_layer.prototype.isQueryable = function() {
return this.queryState;
};
_layer.prototype.setQueryable = function( bQueryable ) {
if (this.queryable) {
this.queryState = bQueryable;
}
};
_layer.prototype.isVisible= function() {
return (this.scales[this._map.currentScale]==1)? true:false;
};
_layer.prototype.setOpacity = function( amount ) {
this.opacity = amount;
if (this.domObj) {
this.domObj.style.opacity = amount/100;
this.domObj.style.mozOpacity = amount/100;
for(var i=0;i<this.domObj.childNodes.length;i++) {
this.domObj.childNodes[i].style.filter = "Alpha(opacity="+amount+")";
}
}
};
_layer.prototype.setTile = function(img) {
var l = safeParseInt(img.style.left) + this._map.kaMap.xOrigin;
var t = safeParseInt(img.style.top) + this._map.kaMap.yOrigin;
var szImageformat = '';
var src;
var image_format = '';
if (this.imageformat && this.imageformat != '') {
image_format = this.imageformat;
szImageformat = '&i='+image_format;
}
if(this.tileSource == 'cache') {
var metaLeft = Math.floor(l/(this._map.kaMap.tileWidth * this._map.kaMap.metaWidth)) * this._map.kaMap.tileWidth * this._map.kaMap.metaWidth;
var metaTop = Math.floor(t/(this._map.kaMap.tileHeight * this._map.kaMap.metaHeight)) * this._map.kaMap.tileHeight * this._map.kaMap.metaHeight;
var metaTileId = 't' + metaTop + '/l' + metaLeft;
var groupsDir = (this.name != '') ? this.name.replace(/\W/g, '_') : 'def';
var cacheDir = this._map.kaMap.webCache + this._map.name + '/' + this._map.aScales[this._map.currentScale] + '/' + groupsDir + '/def/' + metaTileId;
var tileId = "t" + t + "l" + l;
var imageExtension = this.imageformat.toLowerCase().replace(/[\de]/g, '');
src = cacheDir + "/" + tileId + "." + imageExtension;
} else {
var szVersion = '';
if (this._map.version != '') {
szVersion = '&version='+this._map.version;
}
var szForce = '';
var szLayers = '';
if (arguments[1]) {
szForce = '&force=true';
}
var szTimestamp = '';
if (this.tileSource == 'redraw' || this.tileSource == "refresh") {
szTimestamp = '&ts='+this.timeStamp;
if (this.redrawInterval) {
szTimestamp = szTimestamp + '&interval='+this.redrawInterval;
}
}
var szGroup = '&g='+img.layer.domObj.id;
var szScale = '&s='+this._map.aScales[this._map.currentScale];
var q = '?';
if (this._map.kaMap.tileURL.indexOf('?') != -1) {
if (this._map.kaMap.tileURL.slice(-1) != '&') {
q = '&';
} else {
q = '';
}
}
if (this.tileSource == 'nocache') {
src = this._map.kaMap.server +
this._map.kaMap.tileURL.replace('tile.php', 'tile_nocache.php') +
q + 'map=' + this._map.name +
'&t=' + t +
'&l=' + l +
szScale + szForce + szGroup + szImageformat;
if(typeof(this.replacementVariables) != 'undefined') {
for(var key in this.replacementVariables) {
src += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(this.replacementVariables[key]);
}
}
} else {
src = this._map.kaMap.server +
this._map.kaMap.tileURL +
q + 'map=' + this._map.name +
'&t=' + t +
'&l=' + l +
szScale + szForce + szGroup + szImageformat + szTimestamp + szVersion;
}
}
if (img.src != src) {
img.style.visibility = 'hidden';
img.src = src;
}
};
_layer.prototype.setVisibility = function( 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<this.domObj.childNodes.length; i++) {
this.setTile(this.domObj.childNodes[i]);
}
this._map.kaMap.triggerEvent( KAMAP_LAYER_STATUS_CHANGED, this );
}
};
_layer.prototype.setZIndex = function( zIndex ) {
this.zIndex = zIndex;
if (this.domObj) {
this.domObj.style.zIndex = zIndex;
}
};
_layer.prototype.setTileLayer = function() {
this.loaded=0;
for(i = 0; i < this.domObj.childNodes.length; i++) {
img = this.domObj.childNodes[i];
if(arguments[0]) {
this.setTile(img, arguments[0]);
}
else {
this.setTile(img);
}
}
};
_layer.prototype.redraw = function() {
if (arguments[0]) {
this.refreshInterval = arguments[0];
}
if (this.visible) {
var ts = new Date();
this.timeStamp = Math.round(ts.getTime()/1000) + ts.getTimezoneOffset() * 60;
this.setTileLayer();
}
if (this.refreshInterval > 0) {
goQueueManager.enqueue( this.refreshInterval*1000, this, this.redraw );
}
};
function _eventManager( )
{
this.events = [];
this.lastEventID = 0;
}
_eventManager.prototype.registerEventID = function( eventID ) {
var ev = new String(eventID);
if (!this.events[eventID]) {
this.events[eventID] = [];
}
};
_eventManager.prototype.registerForEvent = function(eventID, obj, func) {
var ev = new String(eventID);
this.events[eventID].push( [obj, func] );
};
_eventManager.prototype.deregisterForEvent = function( eventID, obj, func ) {
var ev = new String(eventID);
var bResult = false;
if (!this.events[eventID]) {
return false;
}
for (var i=0;i<this.events[eventID].length;i++) {
if (this.events[eventID][i][0] == obj &&
this.events[eventID][i][1] == func) {
this.events[eventID].splice(i,1);
bResult = true;
}
}
return bResult;
};
_eventManager.prototype.triggerEvent = function( eventID ) {
var ev = new String(eventID);
if (!this.events[eventID]) {
return false;
}
var args = new Array();
for(i=1; i<arguments.length; i++) {
args[args.length] = arguments[i];
}
for (var i=0; i<this.events[eventID].length; i++) {
this.events[eventID][i][1].apply( this.events[eventID][i][0],
arguments );
}
return true;
};
var goQueueManager = new _queueManager();
function _queueManager() {
this.queue = new Array();
}
_queueManager.prototype.enqueue = function( timeout, obj, func, args ) {
var pos = this.queue.length;
for (var i=0; i< this.queue.length; i++) {
if (this.queue[i] == null) {
pos = i;
break;
}
}
var id = window.setTimeout( "_queueManager_execute("+pos+")", timeout );
this.queue[pos] = new Array( id, obj, func, args );
return pos;
};
_queueManager.prototype.dequeue = function( pos ) {
if (this.queue[pos] != null) {
window.clearTimeout( this.queue[pos][0] );
this.queue[pos] = null;
}
};
function _queueManager_execute( pos) {
if (goQueueManager.queue[pos] != null) {
var obj = goQueueManager.queue[pos][1];
var func = goQueueManager.queue[pos][2];
if (goQueueManager.queue[pos][3] != null) {
func.apply( obj, goQueueManager.queue[pos][3] );
} else {
func.apply( obj );
}
goQueueManager.queue[pos] = null;
}
};
Documentation generated by
JSDoc on Mon Feb 5 08:25:15 2007