User:Tonestertm/CRS grid bookmarklet View history

mNo edit summary
(Rewrite and update to 3.0)
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 version 3.0 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. Occasionally you will find a bit of inaccuracy at the edge of a grid, but in general things should put you in 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 imake 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, as it contains ihe info on which grid, and an '''approximation''' of the location within that grid. The  table is presented for those situations when you may need to access an adjacent map.


{{pre2|<nowiki>javascript:(function()%7Bjavascript%3A%20(function%20()%20%7Bvar%20k%20%3D%200%2Ci%20%3D%200%2CcrsLink%20%3D%20%22%22%2CpdfLink%20%3D%20%22%22%2CmajGrid%20%3D%20%22%22%2CgridInfo%20%3D%20%22%22%2Clatletter%20%3D%20%5B%22A%22%2C%20%22B%22%2C%20%22C%22%2C%20%22D%22%2C%20%22E%22%2C%20%22F%22%2C%20%22G%22%2C%20%22H%22%2C%20%22J%22%2C%20%22K%22%2C%20%22L%22%2C%20%22M%22%2C%20%22N%22%2C%20%22P%22%2C%20%22Q%22%2C%20%22R%22%2C%20%22S%22%2C%20%22T%22%2C%20%22U%22%2C%20%22V%22%2C%20%22W%22%2C%20%22X%22%2C%20%22Y%22%5D%2Clonnumber%20%3D%20%5B%2201%22%2C%20%2202%22%2C%20%2203%22%2C%20%2204%22%2C%20%2205%22%2C%20%2206%22%2C%20%2207%22%2C%20%2208%22%2C%20%2209%22%2C%20%2210%22%2C%20%2211%22%2C%20%2212%22%2C%20%2213%22%2C%20%2214%22%2C%20%2215%22%2C%20%2216%22%2C%20%2217%22%2C%20%2218%22%2C%20%2219%22%2C%20%2220%22%2C%20%2221%22%5D%2CmLatIndex%20%3D%200%2CmLonIndex%20%3D%200%2CmajLet%20%3D%20%22%22%2CmajNum%20%3D%20%22%22%2Cminlon%20%3D%200%2Cminlat%20%3D%201%2CaskCRS%2CpopCRS%3Bvar%20center_lonlat%20%3D%20OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon%2C%20Waze.map.getCenter().lat)%3Bvar%20lat%20%3D%20center_lonlat.lat%2Clon%20%3D%20center_lonlat.lon%3B%2F*if%20(lat%20%3E%2042%20%7C%7C%20lat%20%3C%2039)if%20(lon%20%3C%20-124.5%20%7C%7C%20lon%20%3E%20-120.0)alert(%22Longitude%20out%20of%20bounds%22)%3B*%2Fwhile%20(41.6668%20-%20(k%20*%200.4165)%20%3E%20lat)%20%7B%20%2F*%20Find%20Major%20latitude%20grid%20letter%20*%2Fk%2B%2B%3B%7DmLatIndex%20%3D%20k%3BmajLet%20%3D%20latletter%5Bk%5D%3Bwhile%20(i%20%2F%202%20-%20124%20%3C%20lon)%20%7B%20%2F*%20Find%20Major%20longitude%20grid%20number%20*%2Fi%2B%2B%3B%7DmLonIndex%20%3D%20i%3BmajNum%20%3D%20lonnumber%5Bi%5D%3BmajGrid%20%2B%3D%20majNum%20%2B%20majLet%3Bwhile%20(((((minlon%20%2F%205)%20%2B%20(mLonIndex%20-%201))%20%2F%202)%20-%20124)%20%3C%20lon)%20%7B%20%2F*%20Find%20Lon%20minor%20grid%20ref%20*%2Fminlon%2B%2B%3B%7Dwhile%20((41.6668%20-%20(((mLatIndex%20-%201)%20%2B%20(minlat%20%2F%205))%20*%200.4165))%20%3E%20lat)%20%7B%20%2F*%20Find%20Lat%20minor%20grid%20ref%20*%2Fminlat%2B%2B%3B%7DcrsLink%20%2B%3D%20%22http%3A%2F%2Fwww.dot.ca.gov%2Fhq%2Ftsip%2Fhseb%2Fcrs_maps%2Fmaplinks%2F%22%20%2B%20majNum%20%2B%20majLet.toLowerCase()%20%2B%20%22_table.htm%22%3BpdfLink%20%2B%3D%20%22http%3A%2F%2Fwww.dot.ca.gov%2Fhq%2Ftsip%2Fhseb%2Fcrs_map%2F%22%20%2B%20majNum%20%2B%20majLet.toLowerCase()%20%2B%20minlat%20%2B%20minlon%20%2B%20%22.pdf%22%3BgridInfo%20%2B%3D%20%22%5CnThe%20Major%20CRS%20Grid%20is%20%22%20%2B%20majGrid%20%2B%20%22%5CnThe%20minor%20grid%2C%20if%20it%20exists%2C%20is%20%22%20%2B%20minlat%20%2B%20minlon%20%2B%20%22%5Cn%5CnClick%20OK%20to%20open%20the%20%22%20%2B%20majGrid%20%2B%20%22%20map%20table%20in%20a%20%20new%20tab%22%3BaskCRS%20%3D%20window.confirm(gridInfo)%3Bif%20(askCRS%20%3D%3D%3D%20true)%20%7BpopCRS%20%3D%20window.open(crsLink)%3BpopCRS.alert(%22The%20minor%20grid%2C%20if%20it%20exists%2C%20is%20%22%20%2B%20majGrid%20%2B%20minlat%20%2B%20minlon)%3B%7D%20elsenull%3B%7D)()%7D)()</nowiki>}}
Feedback will be appreciated.
 
Copy the code below and make a new bookmark with it.
{{pre2|<nowiki>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 = OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon, Waze.map.getCenter().lat); var lat = center_lonlat.lat, lon = center_lonlat.lon;console.log(lat,lon); /* Rough boundary check - within CRS zone? */ 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; } /* Find Major latitude grid letter - major grids are approximately .4165 degrees "tall" */  while (41.6668 - (k * 0.4165) > lat) { k++; } majLatIndex = k; majLet = latLetter[k]; /* Find Major longitude grid number - major grids are approximately .5 degrees "wide" */  while ((i / 2) - 124 < lon) {  i++; } majLonIndex = i;  majNum = lonNumber[i];    majGrid += majNum + majLet;    /* Find Lon minor grid ref - minor grids are 1/5 the width of major grids */  while (((((minLon / 5) + (majLonIndex - 1)) / 2) +  - 124) < lon) { minLon++; }  console.log("minor grid lon " + ((((minLon / 5) + (majLonIndex - 1)) / 2) - 124));    /* Find Lat minor grid ref - minor grids are 1/5 the height of major grids */  while ((41.6668 - (((majLatIndex - 1) + (minLat / 5)) * 0.4165)) > lat) { minLat++; }    console.log("minor grid lat " + (41.6668 - (((majLatIndex - 1) + (minLat / 5)) * 0.4165)));    /* Find approximate CRS grid - CRS grids are VERY roughly 1/10 the size of minor grids - slop on the ends*/  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 lon " + ((((((minLon -1) / 5) + (majLonIndex - 1) + (gridLonIndex / 10)) / 2) ) - 124));  console.log("grid lat " + (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 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" ; popCRS = window.open(crsLink); popCRS.alert("The minor grid, if it exists, is " + majGrid + minLat + minLon + "\nThe approximate grid coordinates are " + latLetter[gridLonIndex - 1] + gridLatIndex);})();)</nowiki>}}

Revision as of 04:10, 22 April 2016

This is version 3.0 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. Occasionally you will find a bit of inaccuracy at the edge of a grid, but in general things should put you in the correct place.

The script includes some rough boundary checking to imake 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, as it contains ihe info on which grid, and an approximation of the location within that grid. The table is presented for those situations when you may need to access an adjacent map.

Feedback will be appreciated.

Copy the code below and make a new bookmark with it.

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 = OpenLayers.Layer.SphericalMercator.inverseMercator(Waze.map.getCenter().lon, Waze.map.getCenter().lat); var lat = center_lonlat.lat, lon = center_lonlat.lon;console.log(lat,lon); /* Rough boundary check - within CRS zone? */ 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; } /* Find Major latitude grid letter - major grids are approximately .4165 degrees "tall" */  while (41.6668 - (k * 0.4165) > lat) { k++; } majLatIndex = k; majLet = latLetter[k]; /* Find Major longitude grid number - major grids are approximately .5 degrees "wide" */   while ((i / 2) - 124 < lon) {  i++; } majLonIndex = i;  majNum = lonNumber[i];    majGrid += majNum + majLet;    /* Find Lon minor grid ref - minor grids are 1/5 the width of major grids */  while (((((minLon / 5) + (majLonIndex - 1)) / 2) +  - 124) < lon) { minLon++; }  console.log("minor grid lon " + ((((minLon / 5) + (majLonIndex - 1)) / 2) +  - 124));    /* Find Lat minor grid ref - minor grids are 1/5 the height of major grids */   while ((41.6668 - (((majLatIndex - 1) + (minLat / 5)) * 0.4165)) > lat) { minLat++; }    console.log("minor grid lat " + (41.6668 - (((majLatIndex - 1) + (minLat / 5)) * 0.4165)));    /* Find approximate CRS grid - CRS grids are VERY roughly 1/10 the size of minor grids - slop on the ends*/  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 lon " + ((((((minLon -1) / 5) + (majLonIndex - 1) + (gridLonIndex / 10)) / 2) ) - 124));  console.log("grid lat " + (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 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" ; popCRS = window.open(crsLink); popCRS.alert("The minor grid, if it exists, is " + majGrid + minLat + minLon + "\nThe approximate grid coordinates are " + latLetter[gridLonIndex - 1] + gridLatIndex);})();)