/********************************************************************** * kaZoomOnClick.js * * Date: 17th May 2006 * * purpose: A convenient zoom tool that allows the user to zoom in * or out of the map location where it was clicked. * * author: Wei Yang, Ng - Wayne * * Acknowledgments: Paul Spencer for his guidance. * Note: Alot of the code was borrowed from kaTool.js ********************************************************************** * Usage: * 1) Add the following to your page: * * * 2) create 2 instances of kaZoomOnClick: * (hint: look for initialization code - eg. myOnLoad() in startUp.js) * myKaZoomInOnClick = new kaZoomOnClick( myKaMap, KAMAP_ZOOMIN ); * myKaZoomOutOnClick = new kaZoomOnClick( myKaMap, KAMAP_ZOOMOUT ); * * 3) Include the following img icons in your webpage: * Switch to Zoom In Mode * Switch to Zoom Out Mode * * Note: the switchMode function in startUp.js just went through major changes * ensure you are using the latest startUp.js version * **********************************************************************/ var KAMAP_ZOOMIN = 0; var KAMAP_ZOOMOUT = 1; /** * kaZoomOnClick constructor */ function kaZoomOnClick( oKaMap, type ) { kaTool.apply( this, [oKaMap] ); this.name = 'kaZoomOnClick'; this.cursor = ["url('images/cross.png'),move"]; this.type = type; for (var p in kaTool.prototype) { if (!kaZoomOnClick.prototype[p]) kaZoomOnClick.prototype[p]= kaTool.prototype[p]; } } /** * Move to the point where the cursor was double clicked and zoom in. * This is basically a slight modification of the "kaNavigator.prototype.ondblclick" * function in kaTool.js */ kaZoomOnClick.prototype.onmouseup = function(e) { e = (e)?e:((event)?event:null); var posX = 0, posY = 0; if (e.pageX && e.pageY) { posX = e.pageX; posY = e.pageY; } else { var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; var scrollX = iebody.scrollLeft?iebody.scrollLeft:(window.pageXOffset?window.pageXOffset:0); var scrollY = iebody.scrollTop?iebody.scrollTop:(window.pageYOffset?window.pageYOffset:0); posX = e.clientX + scrollX; posY = e.clientY + scrollY; } var aPixPos = this.adjustPixPosition( posX, posY); var vpX = this.kaMap.viewportWidth/2; var vpY = this.kaMap.viewportHeight/2; var dx = parseInt(this.kaMap.theInsideLayer.style.left) - this.kaMap.xOrigin - vpX - aPixPos[0]; var dy = parseInt(this.kaMap.theInsideLayer.style.top) - this.kaMap.yOrigin - vpY - aPixPos[1]; this.kaMap.moveBy(-dx, -dy); if (this.type == KAMAP_ZOOMIN) { myZoomIn(); } else if (this.type == KAMAP_ZOOMOUT) { myZoomOut(); } return false; }