User:Tonestertm/CRS grid bookmarklet View history

mNo edit summary
mNo edit summary
Line 8: Line 8:


Copy the code below and make a new bookmark with it.  
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>}}
{{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:33, 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);})();