Source language: Translate to:

Anyone good at converting JScript webpages into NB?

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Anyone good at converting JScript webpages into NB?

Postby stagmannz » Thu Jan 12, 2012 12:22 pm

Hi, I have a webpage that I use to convert grid references but want to use the equations in NB. The best way i figure would be to use the existing code in the JS webpage and replace the source and results parts with NB variables.

The problem is I have no idea where to start as the code is quite complex. If anyone understands JS and knows how to use it in NB i would really appreciate some help. Attached is the JS code for you to look at. (Note: the code is a complete webpage.)

BTW - I did not make this converter and all credits go to the author (Which I unfortunately do not know!)

Code: Select all
<HTML>
<HEAD>
<STYLE TYPE="text/css">
   BODY {background:beige; margin:0; font-weight:bold}
   TABLE {border:2px solid black; width:100%}
   TD {width:48%; border:2px solid black; font-size:10pt; font-weight:bold;
      text-align:center; color:black; background-color:beige}
   TD.heading {font-size:14pt; text-decoration:underline}
   TD.control {width:4%}
   TEXTAREA {width:100%; height:0; font-size:10pt; font-weight:bold}
   TEXTAREA#result {background-color:lightgrey}
   BUTTON {font-size:9pt; font-weight:bold}
   BUTTON.convert {font-size:12pt}
   SELECT {font-size:6pt; font-weight:bold}
</STYLE>
<SCRIPT LANGUAGE=JavaScript>
//Set ellipsoid parameters.
ell  = new Array(
   "WGS84|6378137|0.00669438",
   "International 1924|6378388.000|0.00672267"
)
//**Start Encode**
function DMStoDec(a,e) {
   /* Converts degrees as DD MM SS.SSS N/S to return decimal degrees to edecimal places. */
   a = "" + a
   var k = b = c = 0
   for (var i=0; i<a.length; i++) {
      var d = a.charAt(i).toUpperCase()
      if ("+-0123456789.".indexOf(d)==-1) {
         if (k!=i) {
            b = b*60 + parseFloat(a.substring(k,i))*(1 - 2*(b<0))
            c++
         }
         k = i + 1
      }
   }
   if (k!=a.length) {
      b = b*60 + parseFloat(a.substring(k,i))*(1 - 2*(b<0))
      c++
   }
   b /= Math.pow(60,c - 1)
   b = Math.round(b*Math.pow(10,e))/Math.pow(10,e)
   if ((d=="S") || (d=="W")) {b = -b}
   return b
}
function degtoDMS(a,b,c) {
   /* Convert decimal degrees to DD MM SS.SSS N/S where a = decimal degrees;
   b = 0 for latitude, 1 for longitude, c = decimal places for seconds.
   Returns array as degrees, minutes, seconds, NS or EW.*/
   var d = new Array()
   if (b==null) {b = 0}
   if (c==null) {c = 0}
   var e = Math.abs(a)
   for (var i=0; i<2; i++) {
      d[i] = Math.floor(e)
      e = (e % 1)*60
   }
   var f = Math.pow(10,c)
   d[2] = Math.floor(e*f + 0.5)/f
   for (var i=2; i>0; i--) {
      if (d[i]==60) {
         d[i] = 0
         d[i - 1]++
      }
      if (d[i]<10) {d[i] = "0" + d[i]}
   }
   if (c>0) {
      if (parseFloat(d[2])==Math.floor(d[2])) {d[2] += "."}
      d[2] = (d[2] + "000000000000").substring(0,c + 3)
   }
   e = "000" + d[0]
   d[0] = e.substring(e.length - 3 + (b==0))
   d[3] = ((a<0) ? "SW" : "NE").substring(b,b + 1)
   return d
}
function UTMtoMGRS(g,d) {
   /* Convert UTM to MGRS where g is array as UTM Zone + letter, Easting,
   Northing; d = number of figures in grid reference. Returns MGRS value. */
   var ok = ((d>0) && (d<12) && ((d % 2)==0)) ? true : false
   var a = g[0] + " "
   var z = parseInt(a,10)
   var e = "ABCDEFGHJKLMNPQRSTUVWXYZ"
   var f = ""
   for (var i=0; i<2; i++) {
      var b = g[i + 1]
      var j = Math.floor(b/100000)
      b -= j*100000
      if (i==0) {
         if ((j<1) || (j>8)) {ok = false}
         j += ((z - 1) % 3)*8 - 1
      }
      else {
         if ((z % 2)==0) {j += 5}
         while (j>19) {j -= 20}
      }
      if ((j>=0) && (j<(24 - 4*i))) {a += e.charAt(j)}
      else {ok = false}
      j = ((b>0) ? Math.floor(Math.log(b)*Math.LOG10E) : 0)
      f  += " " + ("00000".substring(0,4 - j) + b).substring(0,d/2)
   }
   a = (ok==true) ? (a + f) : "Invalid"
   return a
}
function MGRStoUTM(a) {
   /* Convert MGRS to UTM where a is MGRS. Returns array as UTM Zone & letter,
   Easting, Northing. */
   a = a.toUpperCase().split(" ").join("")
   var b = "ABCDEFGHJKLMNPQRSTUVWXYZ"
   var z = parseInt(a,10)
   var ok = ((z>0) && (z<61)) ? true : false
   var c = ("" + z).length
   var d = (a.length - c - 3)/2
   var j = a.charAt(c).toUpperCase()
   if (((d % 1)!=0) || (d<1) || (d>5) || (b.indexOf(j)==-1)) {ok = false}
   for (var i=0; i<2; i++) {
      var f = b.indexOf(a.charAt(c + 1 + i))
      if ((f<0) || (f>(23 - 4*i))) {ok = false}
      var g = a.substring(c + 3 + d*i,c + 3 + d*(i + 1))
      var h = "000000" + parseInt(g,10)
      if (h.substring(h.length - d)!=g) {ok = false}
      g = h*Math.pow(10,5 - d)
      if (i==0) {var e = ((f % 8) + 1)*100000 + g}
      else {f = (f - 5*((z % 2)==0))*100000 + g}
   }
   g = 885000*(b.indexOf(a.charAt(c).toUpperCase()) - 11.5)
   f += 2000000*(Math.round((g - f)/2000000))
   if (f<0) {f += 10000000}
   if (ok) {return new Array(z + j.toLowerCase(),e,f)}
   else {return "Invalid"}
}
function datum(name,semimajor,e2) {
   this.name = name
   this.aa = semimajor
   this.e2 = e2
   this.A = 1 - e2/4*(1+3*e2/16*(1+5*e2/12))
   this.B = 3*e2/8*(1 + e2/4*(1 + 15*e2/32))
   this.C = 15*e2*e2*(1 + 3*e2/4)/256
   this.D = 35*e2*e2*e2/3072
}
function geotoUTM(d,g,k,cm) {
   /* Convert geographic co-ordinate to UTM where d is ellipsoid, g is array as
   latitude, longitude; cm is central meridian in decimal degrees (where cm is
   not set the default central meridian is applied.  Returns array as
   UTM Zone & letter, Easting, Northing to k decimal places. */
   var la = g[0]
   var lo = g[1]
   while (cm == null) {cm = 3 + 6*Math.floor(lo/6)}
   var zone = Math.floor(1 + (cm + 180)/6)
   var j = Math.floor(la/8) + 12
   zone += "ABCDEFGHJKLMNPQRSTUVWXYZ".charAt(j).toLowerCase()
   lo -= cm
   var toRad = Math.PI/180
   la *= toRad
   lo *= toRad
   with (Math) {
      var b = 0.9996*d.aa
      var c = 1 - d.e2
      var e = cos(la)
      var f = tan(la)
      var h = e*e
      var M = b*(d.A*la - d.B*2*h*f + d.C*sin(4*la) - d.D*sin(6*la))
      var n = h*d.e2/c
      var t = f*f
      var v = b/sqrt(1 - t*h*d.e2)
      var Vp = lo*e
      var Vp2 = Vp*Vp
   }
   var e = (((((2*t - 58)*t + 14)*n + (t - 18)*t + 5)*Vp2/20 + n - t + 1)*Vp2/6 + 1)*v*Vp
   e += 500000
   k = Math.pow(10,k)
   e = Math.round(e*k)/k
   var n = ((((t -58)*t + 61)*Vp2/30 + (9 + 4*n)*n - t + 5)*Vp2/12 + 1)*v*Vp2*f/2 + M
   if (la < 0) {n += 10000000}
   n = Math.round(n*k)/k
   return new Array(zone,e,n)
}
function UTMtoGeo(d,a,z,cm) {
   /* Convert UTM to geographic co-ordinatewhere d is ellipsoid, a is array as
   UTM Zone & letter, Easting, Northing; cm is central meridian in decimal degrees
   (where cm is not set the default central meridian is applied). Returns array as
   latitude, longitude to z decimal places. */
   z = Math.pow(10,z)
   var p = a[0]
   var x = a[1]
   var y = a[2]
   while (cm==null) {cm = 6*(parseInt(p,10) - 0.5) - 180}
   p = p.charAt(p.length - 1).toLowerCase()
   if (p < "n") {y -= 10000000}
   var b = 0.9996*d.aa
   var c = 1 - d.e2
   var la = y/(b*c)
   var dlat = 1
   with (Math) {
      while (abs(dlat)>10e-10) {
         var e = cos(la)
         var f = tan(la)
         var h = e*e
         var M = b*(d.A*la - d.B*2*h*f + d.C*sin(4*la) - d.D*sin(6*la))
         var n = h*d.e2/c
         var t = f*f
         var v = b/sqrt(1 - t*h*d.e2)
         dlat = (y - M)*(1 + n)/v
         la += dlat
      }
      U = (x - 500000)/v
      U2 = U*U
      e = ((((4*t + 3)*2*n + (6*t + 7)*4*t + 5)*U2/20 - n - 2*t - 1)*U2/6 + 1)*U/e
      la -= ((((2 + t)*45*t + 61)*U2/30 + (4*n - 1)*n + (3*n - 1)*3*t -5)*U2/12 + 1)*U2/2*(1 + n)*f
      return new Array(Math.round(la*180/PI*z)/z,Math.round((cm + e*180/PI)*z)/z)
   }
}
function convertDMS(a) {
   var f = ""
   a = a.split(" ").join("").toUpperCase()
   var b = "" + parseFloat(a)
   if ((b=="0") || (b=="NaN")) {
      b = "0"
      a = "0" + a
      while (a.substring(0,2)=="00") {a = a.substring(1)}
   }
   var c = a.charAt(a.indexOf(b) + b.length)
   if (c=="") {c = a.charAt(0)}
   var d = new Array(c,a.charAt(a.length - 1))
   b = a.split(c)
   for (var i=0; i<2; i++) {
      e = "" + parseFloat(b[i])
      if (e=="NaN") {e = "0"}
      b[i] = (e=="0") ? e : b[i].substring(0,b[i].indexOf(e) + e.length)
      e = b[i].indexOf(".")
      e = (e==-1) ? b[i].length : e
      while ((e!=(2 + i)) && (e!=(4 + i)) && (e<(6 + i))) {
         b[i] = "0" + b[i]
         e++
      }
      c = 0
      while ((e>0) && (c<3)) {
         e -= 2 + i*(c==0)
         f += ((e==0) ? b[i] : b[i].substring(0,2 + i*(c==0)))
         f += "   °'\"".charAt(c + 3*separator.selectedIndex)
         b[i] = b[i].substring(2 + i*(c==0))
         c++
      }
      if (i==0) {
         f += (d[i]!="S") ? "N" : "S"
         f += unescape("%09")
      }
      else {f += (d[i]!="W") ? "E" : "W"}
   }
   return f
}
function removeSep(a) {
   for (var i=0; i<5; i++) {
      a = a.split((" °'\"" + unescape("%09")).charAt(i)).join("")
   }
   return a
}
function doAction(a) {
   conversion.options(conversion.selectedIndex).def = "" + decimals.selectedIndex
      + noFigs.selectedIndex + separator.selectedIndex
   var tab = unescape("%09")
   var items = a.split("\r\n")
   var r = v = ""
   var total = items.length
   if (items[total - 1]=="") {total--}
   if (total==0) {return}
   faults = new Array()
   cm = (forceZone.checked==true) ? 6*(zoneSel.selectedIndex + 0.5) - 180 : null
   for (var i=0; i<items.length; i++) {
      if (items[i]=="") {
         total--
         break
      }
      switch (conversion.selectedIndex) {
         case 0:
            var q = convertDMS(items[i])
            break
         case 1:
            var q = ""
            var b = items[i].split(tab)
            for (var j=0; j<b.length; j++) {
               q += DMStoDec(b[j],decimals.selectedIndex)
               if (j<(b.length - 1)) {q += tab}
            }
            break
         case 2:
            var q = geotoUTM(selDatum,items[i].split(tab),decimals.selectedIndex,cm)
               .join(tab)
            break
         case 3:
            var q = UTMtoMGRS(items[i].split(tab),(2 + 2*noFigs.selectedIndex))
            break
         case 4:
            var q = MGRStoUTM(items[i]).join(tab)
            break
         case 5:
            var q = UTMtoGeo(selDatum,items[i].split(tab),decimals.selectedIndex)
               .join(tab)
            break
         case 6:
            var q = ""
            var b = items[i].split(tab)
            for (var j=0; j<b.length; j++) {
               b[j] = degtoDMS(b[j],j,decimals.selectedIndex)
               for (var k=0; k<3; k++) {
                  b[j][k] += "   °'\"".charAt(k + 3*separator.selectedIndex)
               }
               if (b.length==1) {b[j][3] = ""}
               q += b[j].join("")
               if (j<(b.length - 1)) {q += tab}
            }
            break
         case 7:
            var q = removeSep(items[i])
            break
         case 8:
            var q = UTMtoMGRS(geotoUTM(selDatum,items[i].split(tab),5),
               (2 + 2*noFigs.selectedIndex))
            break
         case 9:
            var q = UTMtoGeo(selDatum,MGRStoUTM(items[i]),decimals.selectedIndex)
               .join(tab)
      }
      if ((q.indexOf("NaN")!=-1) || (q.indexOf("Invalid")!=-1)) {
         q = "Invalid"
         faults[faults.length] = i + 1
      }
      if (i<(items.length - 1)) {q += "\r\n"}
      if (addNos.checked==true) {
         r += (i + 1) + tab
         v += (i + 1) + tab + items[i] + "\r\n"
      }
      r += q
      window.status = i + 1 + " of " + total + " converted"
   }
   result.value = r
   if (addNos.checked==true) {
      source.value = v
      clrRowNos.disabled = false
   }
   var b = faults.length
   if (b>0) {alert(b + " fault" + ((b==1) ? "" : "s") + " encountered at line"
      + ((b==1) ? ":" : "s:") + "\n\n" + faults)}
   else {
      switch (conversion.selectedIndex) {
         case 0:
         case 1:
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
            conversion.selectedIndex++
            break
         case 7:
            conversion.selectedIndex = 0
            break
         case 8:
            conversion.selectedIndex = 4
            break
         case 9:
            conversion.selectedIndex = 6
      }
      setOptions()
   }
}
function setOptions() {
   var a = conversion.selectedIndex
   decimals.disabled = ((a==0) || (a==3) || (a==7) || (a==8))
   noFigs.disabled = ((a!=3) && (a!=8))
   separator.disabled = (a!=6)
   forceZone.disabled = zoneSel.disabled = ((a!=2) && (a!=8))
   var a = conversion.options[conversion.selectedIndex].def.split("")
   decimals.selectedIndex = a[0]
   noFigs.selectedIndex = a[1]
   separator.selectedIndex = a[2]
}
function setEllipsoid(a) {
   var b = ell[a].split("|")
   selDatum  = new datum(b[0],b[1],b[2])
}
function setUp() {
   setEllipsoid(0)
   source.style.height = result.style.height = document.body.clientHeight
      - exterior.offsetHeight
   source.focus()
}
function clearRowNos() {
   var items = result.value.split("\r\n")
   var srcItems = source.value.split("\r\n")
   for (var i=0; i<items.length; i++) {
      items[i] = items[i].substring(items[i].indexOf(unescape("%09")) + 1)
      srcItems[i] = srcItems[i].substring(srcItems[i].indexOf(unescape("%09")) + 1)
   }
   result.value = items.join("\r\n")
   source.value = srcItems.join("\r\n")
   clrRowNos.disabled = true
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="setUp()">
   <TABLE ID=exterior>
      <TR>
         <TD COLSPAN=3 CLASS="heading">GENERAL PURPOSE CONVERTER</TD>
      </TR>
      <TR>
         <TD>
            Convert:<SELECT ID="conversion" ONCHANGE="setOptions()">
            <OPTION def="000">DDMMSS to DD MM SS</OPTION>
            <OPTION def="700">DD MM SS to decimal degrees</OPTION>
            <OPTION def="000">Decimal degrees to UTM</OPTION>
            <OPTION def="020">UTM to MGRS</OPTION>
            <OPTION def="020">MGRS to UTM</OPTION>
            <OPTION def="700">UTM to decimal degrees</OPTION>
            <OPTION def="000">Decimal degrees to DD MM SS</OPTION>
            <OPTION def="000">DD MM SS to DDMMSS</OPTION>
            <OPTION def="020">Decimal degrees to MGRS</OPTION>
            <OPTION def="720">MGRS to decimal degrees</OPTION>
            </SELECT><BR>
            Ellipsoid:<SELECT ID="ellipsoid"
               ONCHANGE="setEllipsoid(this.selectedIndex)">
               <SCRIPT LANGUAGE=JavaScript>
                  for (var i=0; i<ell.length; i++) {
                     document.writeln("<OPTION>" +
                        ell[i].split("|")[0] + "</OPTION>")
                  }
               </SCRIPT>
            </SELECT><BR>
            <INPUT TYPE=CHECKBOX ID="forceZone" DISABLED
               ONCLICK="zoneSel.disabled=!this.checked"><LABEL FOR="forceZone">
               Force to Zone:</LABEL>
               <SELECT ID="zoneSel" DISABLED>
               <SCRIPT LANGUAGE=JavaScript>
                  for (var i=1; i<61; i++) {
                     document.writeln("<OPTION>" + i + "</OPTION>")
                  }
               </SCRIPT>
            </SELECT>
            <INPUT TYPE=CHECKBOX ID="addNos"><LABEL FOR="addNos">Add row numbers
               </LABEL><BR>
            SOURCE
         </TD>
         <TD ROWSPAN=3 CLASS="control">
            <BUTTON ONCLICK="doAction(source.value)" CLASS="convert" TITLE="Click to start conversion from Source Area">
               >></BUTTON><BR><BR>
            <BUTTON ONCLICK="doAction(result.value)" CLASS="convert" TITLE="Click to start conversion from Results Area">
               [<SUB>></SUB></BUTTON><BR><BR>
            <BUTTON ONCLICK="clrRowNos.click();source.value=result.value;
               result.value=''" CLASS="convert" TITLE="Click to copy from Results Area into Source Area"><<</BUTTON>
         </TD>
         <TD>
            Decimal Places:<SELECT ID="decimals" DISABLED>
               <SCRIPT LANGUAGE=JavaScript>
                  for (var i=0; i<11; i++) {
                     document.writeln("<OPTION>" + i + "</OPTION>")
                  }
               </SCRIPT>
            </SELECT><BR>
            MGRS to:<SELECT ID="noFigs" DISABLED>
               <SCRIPT LANGUAGE=JavaScript>
                  for (var i=1; i<6; i++) {
                     document.writeln("<OPTION>" + i*2
                        + " figures</OPTION>")
                  }
               </SCRIPT>
            </SELECT><BR>
            DD MM SS Separator:<SELECT ID=separator>
               <OPTION>Spaces</OPTION>
               <OPTION>°  '  "</OPTION>
            </SELECT><BR>
            RESULTS
         </TD>
      </TR>
      <TR>
         <TD><TEXTAREA ID="source" WRAP="OFF"></TEXTAREA></TD>
         <TD><TEXTAREA ID="result"  WRAP="OFF" ONFOCUS="this.blur()">
            </TEXTAREA></TD>
      </TR>
      <TR>
         <TD>
            <BUTTON ONCLICK="source.createTextRange().execCommand('Paste')">
               Paste from Clipboard</BUTTON>   
            <BUTTON ONCLICK="source.value=''">Clear</BUTTON>
         </TD>
         <TD>
            <BUTTON ONCLICK="clearRowNos()" ID="clrRowNos" DISABLED>Clear Row Nos
               </BUTTON>   
            <BUTTON ONCLICK="result.createTextRange().execCommand('Copy')">
               Copy to Clipboard</BUTTON>   
            <BUTTON ONCLICK="clrRowNos.click();result.value=''">Clear</BUTTON>
         </TD>
      </TR>
   </TABLE>
</BODY>
</HTML>


Thanks
stagmannz
 
Posts: 15
Joined: Tue Feb 22, 2011 11:34 pm

Postby Tony Kroos » Fri Jan 13, 2012 12:57 am

so, what conversion type do you need?
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby stagmannz » Fri Jan 13, 2012 1:13 am

Generally I want to use MGRS->Dec. Lat long but also most the other conversions. I want to feed the results into a map server to locate the point on a map so all results would be in Dec. Lat long.
stagmannz
 
Posts: 15
Joined: Tue Feb 22, 2011 11:34 pm

Postby domino » Fri Jan 13, 2012 3:16 am

I have created an nb app that basically does just this.. maybe even using the same javascript source.

To be honest I cant remember exactly how I did it as it was a couple of years ago, but if I can find the pub I'll get back to you.

I do remember that NB User Gaev helped me with a key bit of code to get it all working.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby stagmannz » Fri Jan 13, 2012 8:21 pm

Thanks Dave, any help would be appreciated!
stagmannz
 
Posts: 15
Joined: Tue Feb 22, 2011 11:34 pm

Postby domino » Sat Jan 14, 2012 7:40 am

Good news and bad news for now...

Here's some grabs of the exe to show you what it does. Can`t find the pub to give you any programming details at the moment but I know I have it on a disk somewhere but will keep looking if you think it's similar to what you're looking for.

Image

Image

Once initialised i.e. extracting resources such as mdb, .js and webpages etc from a stream (Alberto's excellent streams plugin) the Bing map is displayed and operated in the normal way scrolling, zooming etc.

(Our requirement is to get decimal lat long and UK Ordnance Survey grid references for active and disused airfields and airfield structures.)

Map is scrolled and zoomed manually until the target is map centered - at that point the "Mark" button (circled) is pressed. Doing this populates the decimal lat/long and OS Grid Ref fields.

There is an option to store that data and a screen grab to the database.

Screen grab 2 shows the saved data - note that the conversion to DMS lat long has also ocurred as part of that process - so everyone has the data in the format they require.

There's a batch processor to convert csv lat longs between all required formats.

It does other stuff as well but I've covered the main bit.

Critically I'm using MS Virtual Earth/Bing - Not Google. If you must use Google much would be different.

That's it for now.. if I can find the pub I may be able to give you more detail - as I mentioned before Gaev helped me with a javascript function that was the key to extracting the map data to feed to the .js converter and making this whole thing work.
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Tony Kroos » Sat Jan 14, 2012 10:05 am

copy & save this and CALL as a function:

Code: Select all
{NeoBook Function}
Version=5,70
Language=JScript
Param=[%1]|Text|MGRS coordinate
{End}
function MGRStoUTM(a) {
   /* Convert MGRS to UTM where a is MGRS. Returns array as UTM Zone & letter,
   Easting, Northing. */
   a = a.toUpperCase().split(" ").join("")
   var b = "ABCDEFGHJKLMNPQRSTUVWXYZ"
   var z = parseInt(a,10)
   var ok = ((z>0) && (z<61)) ? true : false
   var c = ("" + z).length
   var d = (a.length - c - 3)/2
   var j = a.charAt(c).toUpperCase()
   if (((d % 1)!=0) || (d<1) || (d>5) || (b.indexOf(j)==-1)) {ok = false}
   for (var i=0; i<2; i++) {
      var f = b.indexOf(a.charAt(c + 1 + i))
      if ((f<0) || (f>(23 - 4*i))) {ok = false}
      var g = a.substring(c + 3 + d*i,c + 3 + d*(i + 1))
      var h = "000000" + parseInt(g,10)
      if (h.substring(h.length - d)!=g) {ok = false}
      g = h*Math.pow(10,5 - d)
      if (i==0) {var e = ((f % 8) + 1)*100000 + g}
      else {f = (f - 5*((z % 2)==0))*100000 + g}
   }
   g = 885000*(b.indexOf(a.charAt(c).toUpperCase()) - 11.5)
   f += 2000000*(Math.round((g - f)/2000000))
   if (f<0) {f += 10000000}
   if (ok) {return new Array(z + j.toLowerCase(),e,f)}
   else {return "Invalid"}
}

nbsetvar ("[MGRStoUTM]", MGRStoUTM("[%1]"))

result will be placed in [MGRStoUTM] variable

this is MGRS to uTM converter, next you'll probably need UTM to GEO coordinates converter, create a UTMtoGEO function in similar way.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby stagmannz » Sat Jan 14, 2012 11:44 pm

:lol:
Thanks Dave and Tony,

I will have a crack at that Function soon, Its pretty much what i'm after, ill give the other coordinates a go too. Thank you heaps for this!

Dave, Im still pretty interested in your pub, I must say it looks pretty impressive.

Once again thanks guys
stagmannz
 
Posts: 15
Joined: Tue Feb 22, 2011 11:34 pm

Postby domino » Sun Jan 15, 2012 4:17 am

stagmannz

It seems to me that Tony has summed up very concisely what you need to get your pub running... and essentially what I had to do to make mine work.

I found converting geographical/map/chart coordinates from one format to another for display can be quite time consuming... decimals are easy but DMS with the symbols & conventions etc .....

Maybe my pub has given you one or two ideas about ways to make your pub useful to wider audiences.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Tony Kroos » Mon Jan 16, 2012 2:19 am

I would prepare a full set of functions from your html code,
but... I'm really noob in geo-location and coordinates, I don't know what kind of arguments are passed to function (ellipsoids, zones, letters, wtf? :))) and what result I should get at the end.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby stagmannz » Tue Jan 17, 2012 9:19 pm

Thanks guys, I have been busy on other projects lately but will put that code to use once i get a spare moment.

Yea that JS is pretty daunting, even with little to no JS experience I would assume its pretty complex!!
stagmannz
 
Posts: 15
Joined: Tue Feb 22, 2011 11:34 pm


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest