MapJumper/CodeCommented

From OpenStreetMap Wiki
Jump to: navigation, search
javascript:(
function(){ // create anonymous function to protect vars
 // build mJ object
 var mJ={'_':['frvipofm.net/osm/mapjumper/','&mode=hub'],'$_':document.location.search};
 // get shortcut
 mJ.$p=prompt('Choose:%20\n_:mapJumper hub\n+:new window');
 // check shortcut and put it into $
 mJ.$=mJ[/^[_\w]+/.exec(mJ.$p)];
 // build destination url
 mJ.$_='http://'+mJ.$[0]+'?'
  // build zoom param
  +/zoom=[0-9]+/.exec(mJ.$_) // get value
  // build lat param
  +'&'
  +(mJ.$[2]?mJ.$[2]:'lat') // custom or default key
  +/lat(=[-\.0-9]+)/.exec(mJ.$_)[1] // get value
  // build lon param
  +'&'
  +(mJ.$[3]?mJ.$[3]:'lon') // custom or default key
  +/(lon|lng)(=[-\.0-9]+)/.exec(mJ.$_)[2] // get value
  // build layer param
  +'&layers='+mJ.$[1]; // get value
 // check non-alpha or _ char in shortcut to open a new window
 if(/[^_\w]/.exec(mJ.$p)){ 
  // new window
  void(open(mJ.$_))
 }else{
  // change location
  document.location=mJ.$_
 }
})(); // execute anonymous function