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

From Wazeopedia
m
(Correcting the code)
Line 5: Line 5:
 
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.
 
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.
  
{{pre2|<nowiki>javascript: (function () {
+
{{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; /*      center_lonlat = new OpenLayers.LonLat(Waze.map.center.lon, Waze.map.center.lat);   center_lonlat.transform(new OpenLayers.Projection('EPSG:900913'), new OpenLayers.Projection('EPSG:4326'));  */    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>}}
 
     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);
 
 
 
    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>}}
 

Revision as of 04:40, 15 November 2015

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.

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.

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.

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;  /*      center_lonlat = new OpenLayers.LonLat(Waze.map.center.lon, Waze.map.center.lat);   center_lonlat.transform(new OpenLayers.Projection('EPSG:900913'), new OpenLayers.Projection('EPSG:4326'));  */    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;        })();