User:Hanoj/bookmarlet

From OpenStreetMap Wiki
Jump to navigation Jump to search

bookmarlet for switch OSM->gMaps->Mapy.cz fork of FR:Bookmarklet_osm-google_maps and regex test

javascript:
(function() {
 params=location.href.match(/openstreetmap\.org.+#map=(\d{1,2})\/(-?\d{1,3}\.\d+)\/(-?\d{1,3}\.\d+)/);
 if(params!=null){
   window.open("https://www.google.com/maps/@" + params[2] + "," + params[3] + "," + params[1] + "z");
 }
 else {
   params=location.href.match(/www\.google\..{2,4}\/maps.+@(-?\d{1,3}\.\d+),(-?\d{1,3}\.\d+),(\d+\.?\d{0,2})z/);
   if(params!=null){
     window.open("http://www.mapy.cz/?x=" + params[2] + "&y=" + params[1] + "&z=" + params[3]);
   }
   else {
     params=location.href.match(/mapy\.cz.+x=(-?\d{1,3}.\d+)&y=(-?\d{1,2}\.\d+)&z\=(\d{1,3})/);
   if(params!=null){
     window.open("http://www.openstreetmap.org/#map=" + params[3] + "/" + params[2] + "/" + params[1]);
     }
     else {
       alert("OSM->gMaps->Mapy.cz\nimpossible");
     }
   }
 }
})
()