User:Tonestertm/CRS grid bookmarklet

From Wazeopedia

This bookmarklet will use 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 it should land you in the correct neighborhood.

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. Next the CRS 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 segment road types, to consult with a senior California editor. 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.

Copy the code below and make a new bookmark with it. Then, simply click that bookmark with a WME page open.

javascript: (function(){ var i=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 center_lonlat=OL.Layer.SphericalMercator.inverseMercator(W.map.getCenter().lon,W.map.getCenter().lat); var lat=center_lonlat.lat,lon=center_lonlat.lon; if((lat<42&&lat>=39)&&(lon>-124.41&&lon<=-120.0)){ console.log("Northern Climes"); }else if((lat<39&&lat>=34.57)&&(lon>(-124.41+((39-lat)*0.83747178329571))&&lon<=(-120+((39-lat)*1.333)))){ console.log("Midstate",39-lat); }else if((lat<34.57&&lat>32.5)&&(lon>(-120.7+((34.57-lat)*1.73913))&&lon<-114.1)){ console.log("SoCal!"); }else{window.alert("Come back to California!"); 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++; }; while((41.6668-(((majLatIndex-1)+(minLat/5))*0.4165))>lat){ minLat++; }; 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++; }; crsLink+="http://www.dot.ca.gov/hq/tsip/hseb/crs_maps/maplinks/"+majNum+majLet.toLowerCase()+"_table.htm"; 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"; window.confirm("The minor grid, if it exists, is "+majGrid+minLat+minLon+"\nThe approximate grid coordinates are "+latLetter[gridLonIndex-1]+gridLatIndex); window.open(crsLink); })();