Bookmarklet osm-google maps

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Bookmarklet osm-google maps
Afrikaans Alemannisch aragonés asturianu azərbaycanca Bahasa Indonesia Bahasa Melayu Bân-lâm-gú Basa Jawa Baso Minangkabau bosanski brezhoneg català čeština dansk Deutsch eesti English español Esperanto estremeñu euskara français Frysk Gaeilge Gàidhlig galego Hausa hrvatski Igbo interlingua Interlingue isiXhosa isiZulu íslenska italiano Kiswahili Kreyòl ayisyen kréyòl gwadloupéyen kurdî latviešu Lëtzebuergesch lietuvių magyar Malagasy Malti Nederlands Nedersaksies norsk norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português română shqip slovenčina slovenščina Soomaaliga suomi svenska Tiếng Việt Türkçe Vahcuengh vèneto Wolof Yorùbá Zazaki српски / srpski беларуская български қазақша македонски монгол русский тоҷикӣ українська Ελληνικά Հայերեն ქართული नेपाली मराठी हिन्दी অসমীয়া বাংলা ਪੰਜਾਬੀ ગુજરાતી ଓଡ଼ିଆ தமிழ் తెలుగు ಕನ್ನಡ മലയാളം සිංහල ไทย မြန်မာဘာသာ ລາວ ភាសាខ្មែរ ⵜⴰⵎⴰⵣⵉⵖⵜ አማርኛ 한국어 日本語 中文(简体)‎ 吴语 粵語 中文(繁體)‎ ייִדיש עברית اردو العربية پښتو سنڌي فارسی ދިވެހިބަސް

This bookmarklet enables you to jump from a osm.org map to google maps at the same position and zoom and vice versa.

Bookmarklet

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\.[a-z]{2,4}(?:\.[a-z]{2})?\/maps\/.*@(-?\d{1,3}\.\d+),(-?\d{1,3}\.\d+),(\d+\.?\d{0,2})(a|m|z)/);if(params!=null){switch(params[4]){case"z":z=params[3];break;case"m":z=20-Math.log(params[3]/86.875)/Math.log(2);break;case"a":z=20-Math.log(params[3]/186.0278)/Math.log(2);break;}window.open("http://www.openstreetmap.org/#map="+Math.round(z)+"/"+params[1]+"/"+params[2]);}else{alert("openstreetmap%20%3C-%3E%20google%20maps\nimpossible");}}})()

Readable version

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\.[a-z]{2,4}(?:\.[a-z]{2})?\/maps\/.*@(-?\d{1,3}\.\d+),(-?\d{1,3}\.\d+),(\d+\.?\d{0,2})(a|m|z)/) ;
    if (params != null) {
      switch(params[4]) {
        case "z": z = params[3] ; break ;
        case "m": z = 20 - Math.log(params[3] / 86.875) / Math.log(2) ; break ;
        case "a": z = 20 - Math.log(params[3] / 186.0278) / Math.log(2) ; break ;
      }
      window.open("http://www.openstreetmap.org/#map=" + Math.round(z) + "/" + params[1] + "/" + params[2]) ;
    }
    else {
      alert("openstreetmap <-> google maps\nimpossible") ;
    }
  }
}
)()

Bookmarklet for opening current view (OSM or GMaps) in OSM editor

This is an edited version of the above bookmarklet which opens the current view for editing in the OSM iD editor. You need to be logged in.

Bookmarklet

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.openstreetmap.org/edit#map=" + params[1] + "/" + params[2] + "/" + params[3]) ;
    }
    else {
        params = location.href.match(/www\.google\.[a-z]{2,4}(?:\.[a-z]{2})?\/maps\/.*@(-?\d{1,3}\.\d+),(-?\d{1,3}\.\d+),(\d+\.?\d{0,2})(a|m|z)/) ;
        if (params != null) {
            switch(params[4]) {
                case "z": z = params[3] ; break ;
                case "m": z = 20 - Math.log(params[3] / 86.875) / Math.log(2) ; break ;
                case "a": z = 20 - Math.log(params[3] / 186.0278) / Math.log(2) ; break ;
            }
            window.open("https://www.openstreetmap.org/edit#map=" + Math.round(z) + "/" + params[2] + "/" + params[1]) ;
        }
        else {
            alert("google maps->OSM edit\nimpossible") ;
        }
    }
}
)()

You can also edit in the Strava iD fork if you replace

"https://www.openstreetmap.org/edit#map="

with

"http://strava.github.io/iD/#background=Bing&map="

(This is more useful than having a bookmarklet that does the same thing as clicking "edit")

Credits

Author : the_knife
Licence : "copyleft"