<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div>I tried the ruler tool putting<span style="font-family: monospace;"> </span><span style="font-family: monospace;"><br></span><pre>myKaRuler = new myKaRuler( myKaMap);</pre>on the myOnLoad() function of startup.js<br><br>However I always get an exception message saying<br><span style="font-weight: bold;">ReferenceError: myKaRuler is not defined<br><br></span>I already added the javascript call for myKaRuler<br><script type="text/javascript" src="tools/kaRuler/kaRuler.js"></script><br><br>Can anyone help me please?<br><br>this is the kaRuler.js code<br>/**<br> * myKaRuler constructor<br> *<br> * construct a new myKaRuler object of a given type for a given kaMap <br>instance<br> *<br> * oKaMap - a kaMap instance<br> *<br> */<br>function myKaRuler(
oKaMap ) {<br>alert("ruler");<br> kaTool.apply( this, [oKaMap] );<br> this.name = 'myKaRuler';<br> this.cursor = 'default';<br> <br> this.canvas = null;<br> <br> // the units abrevations (if map units is DD, the distance is in <br>kilometers)<br> this.unitsAbrevations = new Array("ft","in","km","m","mi","km");<br> <br> //this is the HTML element that is visible<br> this.domObj = document.createElement( 'div' );<br> this.domObj.id = 'measureResult';<br> this.domObj.style.position = 'absolute';<br> this.domObj.style.top = '-300px';<br> this.domObj.style.left =
'-300px';<br> this.domObj.style.width = '150px';<br> this.domObj.style.height = '65px';<br> this.domObj.style.zIndex = 300;<br> this.domObj.style.visibility = 'hidden';<br> this.domObj.style.backgroundColor = 'white';<br> this.domObj.style.border = '1px solid #999999';<br> this.domObj.style.fontFamily = 'Verdana, Arial';<br> this.domObj.style.fontSize = '10px';<br> document.body.appendChild( this.domObj );<br> // the jsgraphic object<br> this.jg = null;<br> // store the user clicks coordinates<br> this.startx = null;<br> this.starty = null;<br> this.endx =
null;<br> this.endy = null;<br> // the total polyline length<br> this.total = 0.0;<br> <br> this.input = getRawObject('coords');<br> <br> for (var p in kaTool.prototype) {<br> if (!myKaRuler.prototype[p])<br> myKaRuler.prototype[p]= kaTool.prototype[p];<br> }<br>};<br><br>/**<br> * activate this tool. Activating the tool causes any existing tools to be<br> * deactivated.<br> */<br>myKaRuler.prototype.activate = function() {<br> this.kaMap.activateTool( this );<br> document.kaCurrentTool = this;<br>
<br> this.domObj.innerHTML = "<h3>&nbsp;Seg : <input type='text' <br>id='measureSeg' <br>style='border:none;background-color:transparent;width:75px;' /> <br>"+this.unitsAbrevations[this.kaMap.getCurrentMap().units]+"<br><br>&nbsp;Tot <br>: <input type='text' id='measureTot' <br>style='border:none;background-color:transparent;width:75px;' /> <br>"+this.unitsAbrevations[this.kaMap.getCurrentMap().units];<br> <br> if(this.canvas == null){<br> this.canvas = this.kaMap.createDrawingCanvas( 300 );<br> this.canvas.id = "measureCanvas";<br> }<br> if(this.jg ==
null){<br> this.jg = new jsGraphics("measureCanvas");<br> this.jg.setColor("#ff0000");<br> this.jg.setStroke(3);<br> }<br> this.domObj.style.visibility='visible';<br>};<br><br>/**<br> * deactivate this tool. <br> */<br>myKaRuler.prototype.deactivate = function() {<br> this.kaMap.deactivateTool( this );<br> document.kaCurrentTool = null;<br> this.jg.clear();<br> this.jg=null;<br> this.kaMap.removeDrawingCanvas(this.canvas);<br> this.canvas=null;<br>
this.domObj.style.visibility='hidden';<br>};<br><br>/*<br> * draw line representing the measure.<br> *<br> */<br>myKaRuler.prototype.drawLine = function() {<br> this.jg.drawLine((this.startx-this.kaMap.xOrigin), <br>(this.starty-this.kaMap.yOrigin),<br> (this.endx-this.kaMap.xOrigin), <br>(this.endy-this.kaMap.yOrigin)); // co-ordinates related to "myCanvas"<br> this.jg.paint();<br> this.startx = this.endx;<br> this.starty = this.endy;<br>};<br><br>/**<br> * myKaRuler.onmouseout( e )<br> *<br> * called when the mouse leaves theInsideLayer. hide the result box<br> *<br> * e - object, the event object or null (in ie)<br> */<br>myKaRuler.prototype.onmouseout = function(e)
{<br> e = (e)?e:((event)?event:null);<br> if (!e.target) e.target = e.srcElement;<br> this.domObj.style.visibility='hidden';<br>};<br><br>/**<br> * myKaRuler.onmouseout( e )<br> *<br> * called when the mouse leaves theInsideLayer. show the result box<br> *<br> * e - object, the event object or null (in ie)<br> */<br>myKaRuler.prototype.onmouseover = function(e) {<br> e = (e)?e:((event)?event:null);<br> if (!e.target) e.target = e.srcElement;<br> this.domObj.style.visibility='visible';<br>};<br><br>/**<br> * myKaRuler.onmousemove( e )<br> *<br> * called when the mouse moves over theInsideLayer.<br> *<br> * e - object, the event object or null (in ie)<br> */<br>myKaRuler.prototype.onmousemove = function(e) {<br> e =
(e)?e:((event)?event:null);<br><br> //show coordinate<br> var x = e.pageX || (e.clientX +<br> (document.documentElement.scrollLeft || <br>document.body.scrollLeft));<br> var y = e.pageY || (e.clientY +<br> (document.documentElement.scrollTop || document.body.scrollTop));<br> var aPixPos = this.adjustPixPosition( x,y );<br> var geoCoo= this.kaMap.pixToGeo(aPixPos[0],aPixPos[1]);<br> var gX = geoCoo[0];<br> var gY = geoCoo[1];<br> var gX= (parseInt(gX*10000))/10000;<br> var gY=
(parseInt(gY*10000))/10000;<br> if(this.input)<br> {<br> if(this.kaMap.getCurrentMap().units == 5)<br> this.input.value = "Lon.: "+gX+" Lat.: "+gY;<br> else<br> this.input.value = "X: "+gX+" Y: "+gY;<br> }<br> //**//<br> this.domObj.style.left = (e.clientX+5)+"px";<br> this.domObj.style.top = (e.clientY+5)+"px";<br> <br> if(this.startx !==
null)<br> {<br> this.endx=-aPixPos[0];<br> this.endy=-aPixPos[1];<br> if(this.kaMap.getCurrentMap().units == 5) {<br> document.getElementById("measureSeg").value = <br>this.measureSphericalDistance2Points(this.startx,this.starty,this.endx,this.endy);<br> }else{<br> document.getElementById("measureSeg").value = <br>this.measure2points(this.startx,this.starty,this.endx,this.endy);<br> }<br> }<br>
return false;<br>}<br>;<br>/**<br> * myKaRuler.onmousedown( e )<br> *<br> * called when a mouse button is pressed over theInsideLayer.<br> *<br> * e - object, the event object or null (in ie)<br> */<br>myKaRuler.prototype.onmousedown = function(e) {<br> e = (e)?e:((event)?event:null);<br> if (e.button==2) {<br> this.jg.clear();<br> this.startx=this.starty=this.endx=this.endy=null;<br> document.getElementById("measureSeg").value="0.0";<br>
document.getElementById("measureTot").value="0.0";<br> this.total = 0.0;<br> return this.cancelEvent(e);<br> } else {<br> if (this.kaMap.isIE4) document.onkeydown = <br>kaTool_redirect_onkeypress;<br> document.onkeypress = kaTool_redirect_onkeypress;<br> <br> var x = e.pageX || (e.clientX +<br> (document.documentElement.scrollLeft || <br>document.body.scrollLeft));<br> var y = e.pageY || (e.clientY +<br>
(document.documentElement.scrollTop || <br>document.body.scrollTop));<br> var aPixPos = this.adjustPixPosition( x,y );<br> if(this.endx == null)<br> {<br> this.startx=this.endx=-aPixPos[0];<br> this.starty=this.endy=-aPixPos[1];<br> }<br> else<br> {<br>
this.endx=-aPixPos[0];<br> this.endy=-aPixPos[1];<br> }<br> <br> if(this.kaMap.getCurrentMap().units == 5) {<br> this.total += <br>this.measureSphericalDistance2Points(this.startx,this.starty,this.endx,this.endy);<br> }else{<br> this.total +=
<br>this.measure2points(this.startx,this.starty,this.endx,this.endy);<br> }<br> this.total = parseInt(this.total*100)/100;<br> document.getElementById("measureTot").value = this.total;<br> this.drawLine();<br> <br> e.cancelBubble = true;<br> e.returnValue = false;<br> if (e.stopPropogation) e.stopPropogation();<br> if (e.preventDefault) e.preventDefault();<br> return false;<br>
}<br>};<br><br>/**<br> * myKaRuler.onmouseup( e )<br> *<br> * called when a mouse button is clicked over theInsideLayer.<br> *<br> * e - object, the event object or null (in ie)<br> */<br>myKaRuler.prototype.onmouseup = function(e) {<br> e = (e)?e:((event)?event:null);<br> return false;<br>};<br>/**<br>* myKaRuler.measureSphericalDistance2Points<br>*<br>* pix1,piy1 - pixel coordinates of the first point<br>* pix2,piy2 - pixel coordinates of the second point<br>*<br>* This function is used to calculate the distance between two points in <br>decimel degree unit.<br>* It assume that the earth is a perfect sphere, so the calculation isn't <br>accurate.<br>* In fact the further you are from the equator the least accurate the <br>calulation is.<br>*/<br>myKaRuler.prototype.measureSphericalDistance2Points = <br>function(pix1,piy1,pix2,piy2)<br>{<br> var pt1 =
this.kaMap.pixToGeo(pix1,piy1);<br> var pt2 = this.kaMap.pixToGeo(pix2,piy2);<br> /* Convert all the degrees to radians */<br> var la1 = pt1[0] * Math.PI/180.0;<br> var lo1 = pt1[1] * Math.PI/180.0;<br> var la2 = pt2[0] * Math.PI/180.0;<br> var lo2 = pt2[1] * Math.PI/180.0;<br> /* Find the Great Circle distance */<br> var EARTH_RADIUS = 6378;//kilometers //3956;//miles<br> var distance = <br>Math.acos(Math.sin(la1)*Math.sin(la2)+Math.cos(la1)*Math.cos(la2)*Math.cos(lo2-lo1)) <br>* EARTH_RADIUS ;<br> return distance ;<br>};<br><br>/**<br>* myKaRuler.measureSphericalDistance2Points<br>*<br>* p1X,p1Y - pixel coordinates of the first point<br>* p2X,p2Y - pixel coordinates of the second point<br>*<br>* This function is used to calculate the distance between two points in <br>planar
projection.<br>* I use the Pythagor algorythm. The result unit is the same as the <br>projection unit and is round<br>* at two decimals.<br>*/<br>myKaRuler.prototype.measure2points = function(p1X,p1Y,p2X,p2Y)<br>{<br> // Diff X/Y between current new and previous click<br> var x_delta = p1X - p2X;<br> var y_delta = p1Y - p2Y;<br> // Segment length in Pixel<br> var segLenPix = Math.sqrt((Math.pow(x_delta, 2)) + <br>(Math.pow(y_delta, 2)));<br> // Segment length in map coordinates, write values to input boxes<br> var extent = this.kaMap.getGeoExtents();<br> var xdelta_geo = extent[2]-extent[0];<br> var segLenGEO = parseInt( ((segLenPix/this.kaMap.viewportWidth ) * <br>xdelta_geo)*100 )/100;<br> return segLenGEO;<br>};<br><span style="font-weight: bold;"></span><span
style="font-family: monospace;"></span></div></div><br>
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a></body></html>