Difference between revisions of "User:Tonestertm/CRS grid bookmarklet"

From Wazeopedia
m
m (Tonestertm moved page Tonestertm/CRS grid bookmarklet to User:Tonestertm/CRS grid bookmarklet: Page was created in the wrong wikispace)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is version 0.1.2 of a bookmarklet (my very first javascript code "from scratch" :) ) which will take the coordinates from the '''center''' of your screen and find the appropriate CRS Grid map. With this version, I'm primarily looking for feedback as to whether it's working properly, and whether the intermediate step (first alert popup) is really necessary. There may be the tiniest bit of inaccuracy at the edge of a grid, but in general things should put you in the correct place. Ultimately, I expect to put this in the CA Wiki as a resource.  
+
This is a bookmarklet which will take the coordinates from the '''center''' of your WME window and find the appropriate CRS Grid map. Occasionally you may find a bit of inaccuracy at the edge of a grid, but in general it should put you in approximately the correct place.  
  
Round 2 will include some rough boundary checking, to be sure you're in California, as the state hasn't been magnanimous enough to provide FC maps for OR, NV, AZ or MX.  
+
The script includes some rough boundary checking to make sure you're in California, as the state hasn't been magnanimous enough to provide FC maps for OR, NV, AZ or MX.  
  
Also, I ''can'' currently link directly to the particular pdf map, but haven't figured how to account for areas where there is no "minor grid" map. In addition, the decision to leave the table as a clunky-looking full-size tab was deliberate, owing to the idea that you may need to access an adjacent map; this seems to me easier than the state's approach, where the tiny window disappears behind the main browser window, but I'm interested in others' thoughts. Feedback will be appreciated.
+
Be sure to examine the popup closely before dismissing it, as it contains the info on which grid you'll need to select, and an '''approximation''' of the location within that grid. The table is presented, rather than the script taking you straight to the assigned grid, to simplify those situations when you may need to access an adjacent map.
  
{{pre2|<nowiki>javascript: (function () {     var k = 0,       i = 0,       crsLink = "",       pdfLink = "",       majGrid = "",       gridInfo = "",       latletter = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y"],       lonnumber = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"],       mLatIndex = 0,       mLonIndex = 0,       majLet = "",        majNum = "",       minlon = 0,       minlat = 1,        askCRS,       popCRS;   var center_lonlat = OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon, Waze.map.getCenter().lat);     var lat = center_lonlat.lat,       lon = center_lonlat.lon;   if (lat > 42 || lat < 39)       if (lon < -124.5 || lon > -120.0)           /* alert("Longitude out of bounds"); */      while (41.6668 - (k * 0.4165) > lat) { /* Find Major latitude grid letter */        k++;   }           mLatIndex = k;   majLet = latletter[k];           while (i / 2 - 124 < lon) { /* Find Major longitude grid number */        i++;   }   mLonIndex = i;   majNum = lonnumber[i];   majGrid += majNum + majLet;   while (((((minlon / 5) + (mLonIndex - 1)) / 2) - 124) < lon) { /* Find Lon minor grid ref */       minlon++;   }   while ((41.6668 - (((mLatIndex - 1) + (minlat / 5)) * 0.4165)) > lat) { /* Find Lat minor grid ref */       minlat++;   }    crsLink += "http://www.dot.ca.gov/hq/tsip/hseb/crs_maps/maplinks/" + majNum + majLet.toLowerCase() + "_table.htm";   pdfLink += "http://www.dot.ca.gov/hq/tsip/hseb/crs_map/" + majNum + majLet.toLowerCase() + minlat + minlon + ".pdf";   gridInfo += "\nThe Major CRS Grid is " + majGrid + "\nThe minor grid, if it exists, is " + minlat + minlon + "\n\nClick OK to open the " + majGrid + " map table in a  new tab";   askCRS = window.confirm(gridInfo);      if (askCRS === true) {        popCRS = window.open(crsLink);       popCRS.alert("The minor grid, if it exists, is " + majGrid + minlat + minlon);       } else            null;        })();</nowiki>}}
+
Be sure, before lowering any segments, to consult with a senior editor in the area. There are ''occasional'' deviations from the official map, for Waze purposes such as continuity along higher-typed routes.
 +
 
 +
Feedback will be appreciated. Thanks to SAR85 for inspiring me to finally dig in and learn some javascript, (and fielding plenty of stupid questions from an old dog, about this new trick), and to autenil for coaching about preparing code for bookmarklets.
 +
 
 +
"Installation" of a bookmarklet is performed by creating a new bookmark, and copy/pasting '''all''' of the code below into the URL destination field. The bookmarklet can then be run by clicking the bookmark while your WME window is centered over the spot where you wish to examine FC.
 +
{{pre2|<nowiki>javascript:(function(){var%20i=0,k=0,minLon=0,majLatIndex=0,majLonIndex=0,crsLink="",pdfLink="",majGrid="",gridInfo="",majLet="",majNum="",gridLet="",latLetter=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y"],lonNumber=["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],minLat=1,gridNum=0,gridLatIndex=0,gridLonIndex=0,askCRS,popCRS;var%20center_lonlat=OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon,Waze.map.getCenter().lat);var%20lat=center_lonlat.lat,lon=center_lonlat.lon;console.log(lat,lon);if((lat<42&&lat>=39)&&(lon>-124.41&&lon<=-120.0)){console.log("Northern%20Climes");}else%20if((lat<39&&lat>=34.57)&&(lon>(-124.41+((39-lat)*0.83747178329571))&&lon<=(-120+((39-lat)*1.333)))){console.log("Midstate",39-lat);}else%20if((lat<34.57&&lat>32.5)&&(lon>(-120.7+((34.57-lat)*1.73913))&&lon<-114.1)){console.log("SoCal!");}else{window.alert("Come%20back%20to%20California!");return;}while(41.6668-(k*0.4165)>lat){k++;}majLatIndex=k;majLet=latLetter[k];while((i/2)-124<lon){i++;}majLonIndex=i;majNum=lonNumber[i];majGrid+=majNum+majLet;while(((((minLon/5)+(majLonIndex-1))/2)+-124)<lon){minLon++;}console.log("minor%20grid%20lon%20"+((((minLon/5)+(majLonIndex-1))/2)+-124));while((41.6668-(((majLatIndex-1)+(minLat/5))*0.4165))>lat){minLat++;}console.log("minor%20grid%20lat%20"+(41.6668-(((majLatIndex-1)+(minLat/5))*0.4165)));while(((((((minLon-1+(gridLonIndex/10))/5)+(majLonIndex-1))/2))-124)<lon){gridLonIndex++;};while((41.6668-(((majLatIndex-1)+((minLat-1+(gridLatIndex/10))/5))*0.4165))>lat){gridLatIndex++;};console.log(majLonIndex,majLatIndex,minLat,minLon,gridLonIndex,gridLatIndex);console.log("grid%20lon%20"+((((((minLon-1)/5)+(majLonIndex-1)+(gridLonIndex/10))/2))-124));console.log("grid%20lat%20"+(41.6668-(((majLatIndex-1)+((minLat-1)/5)+(gridLatIndex/10))*0.4165)));crsLink+="http://www.dot.ca.gov/hq/tsip/hseb/crs_maps/maplinks/"+majNum+majLet.toLowerCase()+"_table.htm";pdfLink+="http://www.dot.ca.gov/hq/tsip/hseb/crs_map/"+majNum+majLet.toLowerCase()+minLat+minLon+".pdf";gridInfo+="\nThe%20Major%20CRS%20Grid%20is%20"+majGrid+"\nThe%20minor%20grid,%20if%20it%20exists,%20is%20"+minLat+minLon+"\n\nClick%20OK%20to%20open%20the%20"+majGrid+"%20map%20table%20in%20a%20%20new%20tab";popCRS=window.open(crsLink);popCRS.confirm("The%20minor%20grid,%20if%20it%20exists,%20is%20"+majGrid+minLat+minLon+"\nThe%20approximate%20grid%20coordinates%20are%20"+latLetter[gridLonIndex-1]+gridLatIndex);})();</nowiki>}}

Latest revision as of 06:56, 7 August 2016

This is a bookmarklet which will take the coordinates from the center of your WME window and find the appropriate CRS Grid map. Occasionally you may find a bit of inaccuracy at the edge of a grid, but in general it should put you in approximately the correct place.

The script includes some rough boundary checking to make sure you're in California, as the state hasn't been magnanimous enough to provide FC maps for OR, NV, AZ or MX.

Be sure to examine the popup closely before dismissing it, as it contains the info on which grid you'll need to select, and an approximation of the location within that grid. The table is presented, rather than the script taking you straight to the assigned grid, to simplify those situations when you may need to access an adjacent map.

Be sure, before lowering any segments, to consult with a senior editor in the area. There are occasional deviations from the official map, for Waze purposes such as continuity along higher-typed routes.

Feedback will be appreciated. Thanks to SAR85 for inspiring me to finally dig in and learn some javascript, (and fielding plenty of stupid questions from an old dog, about this new trick), and to autenil for coaching about preparing code for bookmarklets.

"Installation" of a bookmarklet is performed by creating a new bookmark, and copy/pasting all of the code below into the URL destination field. The bookmarklet can then be run by clicking the bookmark while your WME window is centered over the spot where you wish to examine FC.

javascript:(function(){var%20i=0,k=0,minLon=0,majLatIndex=0,majLonIndex=0,crsLink="",pdfLink="",majGrid="",gridInfo="",majLet="",majNum="",gridLet="",latLetter=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y"],lonNumber=["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],minLat=1,gridNum=0,gridLatIndex=0,gridLonIndex=0,askCRS,popCRS;var%20center_lonlat=OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon,Waze.map.getCenter().lat);var%20lat=center_lonlat.lat,lon=center_lonlat.lon;console.log(lat,lon);if((lat<42&&lat>=39)&&(lon>-124.41&&lon<=-120.0)){console.log("Northern%20Climes");}else%20if((lat<39&&lat>=34.57)&&(lon>(-124.41+((39-lat)*0.83747178329571))&&lon<=(-120+((39-lat)*1.333)))){console.log("Midstate",39-lat);}else%20if((lat<34.57&&lat>32.5)&&(lon>(-120.7+((34.57-lat)*1.73913))&&lon<-114.1)){console.log("SoCal!");}else{window.alert("Come%20back%20to%20California!");return;}while(41.6668-(k*0.4165)>lat){k++;}majLatIndex=k;majLet=latLetter[k];while((i/2)-124<lon){i++;}majLonIndex=i;majNum=lonNumber[i];majGrid+=majNum+majLet;while(((((minLon/5)+(majLonIndex-1))/2)+-124)<lon){minLon++;}console.log("minor%20grid%20lon%20"+((((minLon/5)+(majLonIndex-1))/2)+-124));while((41.6668-(((majLatIndex-1)+(minLat/5))*0.4165))>lat){minLat++;}console.log("minor%20grid%20lat%20"+(41.6668-(((majLatIndex-1)+(minLat/5))*0.4165)));while(((((((minLon-1+(gridLonIndex/10))/5)+(majLonIndex-1))/2))-124)<lon){gridLonIndex++;};while((41.6668-(((majLatIndex-1)+((minLat-1+(gridLatIndex/10))/5))*0.4165))>lat){gridLatIndex++;};console.log(majLonIndex,majLatIndex,minLat,minLon,gridLonIndex,gridLatIndex);console.log("grid%20lon%20"+((((((minLon-1)/5)+(majLonIndex-1)+(gridLonIndex/10))/2))-124));console.log("grid%20lat%20"+(41.6668-(((majLatIndex-1)+((minLat-1)/5)+(gridLatIndex/10))*0.4165)));crsLink+="http://www.dot.ca.gov/hq/tsip/hseb/crs_maps/maplinks/"+majNum+majLet.toLowerCase()+"_table.htm";pdfLink+="http://www.dot.ca.gov/hq/tsip/hseb/crs_map/"+majNum+majLet.toLowerCase()+minLat+minLon+".pdf";gridInfo+="\nThe%20Major%20CRS%20Grid%20is%20"+majGrid+"\nThe%20minor%20grid,%20if%20it%20exists,%20is%20"+minLat+minLon+"\n\nClick%20OK%20to%20open%20the%20"+majGrid+"%20map%20table%20in%20a%20%20new%20tab";popCRS=window.open(crsLink);popCRS.confirm("The%20minor%20grid,%20if%20it%20exists,%20is%20"+majGrid+minLat+minLon+"\nThe%20approximate%20grid%20coordinates%20are%20"+latLetter[gridLonIndex-1]+gridLatIndex);})();