Bookmarklet JumpToOsm

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Bookmarklet JumpToOsm
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 bokmål norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português português do Brasil 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 retrieves zoom and coordinates in current url and opens a page on openstreetmap.org at the same place.

Recognized formats

Current url has to contain the following informations :

  • either 0/0.000/0.000
  • or zoom=0&lat=0.000&lon=0.000 (order not important and possible other parameters in between)

If none of these informations are found, no tab is created (an error message is displayed).

Source

Bookmarklet

javascript:(function(){params=location.href.match(/\d{1,2}\/-?\d{1,3}\.\d+\/-?\d{1,3}\.\d+/);if(params!=null){window.open("http://www.openstreetmap.org/#map="+params[0]);}else{zoom=location.href.match(/zoom=(\d{1,2})/);lat=location.href.match(/lat=(-?\d{1,3}\.\d+)/);lon=location.href.match(/lon=(-?\d{1,3}\.\d+)/);if(zoom!=null&&lat!=null&&lon!=null){window.open("http://www.openstreetmap.org/#map="+zoom[1]+"/"+lat[1]+"/"+lon[1]);}else{alert("Jump%20to%20OpenStreetMap%20impossible.\n\n\Could%20not%20find%20zoom%20and%20coordinates%20in%20url.");}}})()

Readable version

javascript:
(function() {
  params = location.href.match(/\d{1,2}\/-?\d{1,3}\.\d+\/-?\d{1,3}\.\d+/) ;
  if (params!=null){
    window.open("http://www.openstreetmap.org/#map="+params[0]) ;
  } else {
    zoom = location.href.match(/zoom=(\d{1,2})/) ;
    lat = location.href.match(/lat=(-?\d{1,3}\.\d+)/) ;
    lon = location.href.match(/lon=(-?\d{1,3}\.\d+)/) ;
    if (zoom!=null && lat!=null && lon!=null) {
      window.open("http://www.openstreetmap.org/#map="+zoom[1]+"/"+lat[1]+"/"+lon[1]) ;
    } else {
      alert("Jump%20to%20OpenStreetMap%20impossible.\n\n\Could%20not%20find%20zoom%20and%20coordinates%20in%20url.") ;
    }
  }
}
)()

Crédits

Auteur : the_knife
Licence : copyleft