SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    mt hope
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    x,y, to list or txt file

    Hi ,
    I have a script which allows me to mouse click and extract x,y, coordinates. My problem is creating a list of multiple coordinates to copy and paste into a text file. The ideal would be to interactively choose points of which x,y coordinates to collect and directly write them to a text file. I understand that would require javascript (client side) and php or something (server side). Is that right?

    here is my script so far

    <SCRIPT LANGUAGE=JAVASCRIPT>
    function getInString (haystack, haystackStart, needlePrefix, needleStop) {
    var needle = null;
    var pos = haystack.indexOf(needlePrefix, haystackStart);
    var start = 0;
    var stop = 0;
    if (pos != -1) {
    start = pos + needlePrefix.length;
    stop = haystack.indexOf(needleStop,start);
    if (stop == -1) {
    stop = haystack.length;
    }
    needle = haystack.substring(start,stop);
    }
    return needle;
    }

    function cleanUp() {
    //opener.parent.MapFrame.revertToDefaultTool();
    }

    function startUp() {
    //window.focus();
    }

    var paramstr = document.location.search;
    var hasElevation = false;
    var elev = null;
    var lon = null;
    var decLon = null;
    var lat = null;
    var decLat = null;
    var units = null;
    var USNG = null;
    var source = null;

    if (paramstr != null && paramstr != "") {
    paramstr = paramstr.toUpperCase();
    elev = getInString(paramstr,0,'ELEVATION=','&');
    if (elev != null & elev != "") {
    if (opener.parent.MapFrame.useMetric == false)
    elev = Math.round(elev);
    hasElevation = true;
    lon = getInString(paramstr,0,'X=','&');
    if (lon != null) {
    decLon = lon;
    lon = opener.parent.MapFrame.ConvertToDDMMSS(lon);
    }
    lat = getInString(paramstr,0,'Y=','&');
    if (lat != null) {
    decLat = lat;
    lat = opener.parent.MapFrame.ConvertToDDMMSS(lat);
    }
    if (decLat != null && decLon != null) {
    USNG = opener.parent.MapFrame.LLtoUSNG(decLat, decLon);

    // Parse USNG for input params to USNGtoUTM Function
    var USNGArray = USNG.split(" ",20);
    var zone = parseInt(USNGArray[0]);
    var gzdLet = USNGArray[0].charAt(USNGArray[0].length -1);
    var sqLet1 = USNGArray[1].charAt(0);
    var sqLet2 = USNGArray[1].charAt(1);
    var USNGEasting = USNGArray[2];
    var USNGNorthing = USNGArray[3];
    var ret={};
    // get UTM Coordinates and put into a UTM String
    opener.parent.MapFrame.USNGtoUTM(zone,gzdLet,sqLet1,sqLet2,USNGEasting,USNGNorthing,ret);

    var UTM = ret.zone+" "+(Math.round(ret.E))+" "+(Math.round(ret.N));


    }
    units = getInString(paramstr,0,'UNITS=','&');
    source = getInString(paramstr,0,'SOURCE=','&');
    if (source != null) {
    source = unescape(source);
    }
    if ((decLon > -141 && decLat > 60) || elev < -5000 || elev > 21000)
    {
    elev = "Not Available";
    units = "";
    }
    else
    if (opener.parent.MapFrame.useMetric)
    {
    units = "Meters";
    elev = Math.round(elev * (3048/1000)) / 10;
    }
    }
    }
    </SCRIPT>
    </head>
    <body class="toolPage" marginwidth="5" marginheight="5" onload="startUp();" onUnload="cleanUp();">
    <a href="http://www.usgs.gov" target="_blank"><img src="images/80x22_green.gif" border="0" alt="USGS"></a>
    <h3>Elevation Lookup Results</h3>
    <SCRIPT LANGUAGE="JAVASCRIPT">
    document.open();
    if (hasElevation) {
    var docOut = "";
    docOut += + '<p><b>Latitude /b> ' + lat + '</p>'
    + '<p><b>Longitude : </b> ' + lon + '</p>'
    + '<p><b>U.S. National Grid (USNG) Coordinates: </b><br/> ' + USNG + '</p>'
    + '<p><b>Universal Transverse Mercator (UTM) Coordinates: </b><br/> ' + UTM + '</p>'
    + '<p><b>Source : </b><br/> ' + source + '</p>';
    document.writeln(docOut);
    }
    document.close();
    this.focus();
    </SCRIPT>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,489
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No other takers for this one so

    I can give you a script to record the click positions in an array the you can send the array to PHP in some form and do what you want with it

    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>

    <
    body>
    <
    script language="JavaScript" type="text/javascript">
    <!--


    var 
    ClicPosAry=new Array();
    var 
    ClkCnt=0;
    var 
    lock=0;

    document.onmousedown=function(event) {tndMseDown(event);}


    function 
    tndMseDown(event) {
     
    tndDragCk=true;
     if(!
    event) var event=window.event;
     var 
    tndx=event.pageX;
     if(
    tndx==nulltndx=event.clientX;
     var 
    tndy=event.pageY;
     if(
    tndy==nulltndy=event.clientY;
     
    tndDragX=tndxtndDragY=tndy;
     
    ClicPosAry[ClkCnt]=new Array();
     
    ClicPosAry[ClkCnt][0]=tndx;
     
    ClicPosAry[ClkCnt][1]=tndy;
     
    ClkCnt++;
     
    ShowClicks();
    }

    function 
    ShowClicks(){
     if (
    lock){return; }
     
    val=''
     
    for (i=0;i<ClicPosAry.length;i++){
      
    val+='\nClick '+(i+1)+' X = '+ClicPosAry[i][0]+' Y = '+ClicPosAry[i][1]
     }
     
    document.getElementById('Result').value=val;
    }

    //-->
    </script>
    <textarea id="Result" rows="20" cols="30" style="font-size:10px;" onfocus="javascript:lock=1;" onblur="javascript:document.getElementById('Result').value='';lock=0;" ></textarea>
    </body>

    </html> 

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    mt hope
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    Thanks for the help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •