Advertisement
Technical_13

MVGP permalink back to Munzee Map

Aug 2nd, 2019
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var munzMapButton = document.createElement( 'img' );
  2. munzMapButton.id = 'gotoMapBtn';
  3. munzMapButton.class = 'btn';
  4. munzMapButton.title = 'View location on Munzee Map and copy to clipboard.';
  5. munzMapButton.src = 'https://yt3.ggpht.com/-uzybXB9pgSg/AAAAAAAAAAI/AAAAAAAAAAA/JGU1V_Fn4Tg/s68-c-k-no-mo-rj-c0xffffff/photo.jpg';
  6. munzMapButton.style = 'width: 48px; height: 48px; border: 1px solid #000000; margin: 2px; cursor: pointer;';
  7.  
  8. var munzMapNavigate = document.createElement( 'a' );
  9. munzMapNavigate.id = 'gotoMap';
  10. munzMapNavigate.appendChild( munzMapButton );
  11.  
  12. document.getElementById( 'toolbox' ).prepend( munzMapNavigate );
  13.  
  14. var loadGeoHash = document.createElement( 'script' );
  15. loadGeoHash.src = 'https://www.munzee.com/javascript/map/geohash.js';
  16. loadGeoHash.type = 'text/javascript';
  17. document.getElementsByTagName( 'head' )[ 0 ].appendChild( loadGeoHash );
  18.  
  19. var rawScript = document.createElement( 'script' );
  20. rawScript.type = 'text/javascript';
  21. rawScript.innerText = 'document.getElementById( "gotoMap" ).addEventListener( "mouseover", function(){' +
  22.     'var strMapZoom = parseFloat( map._zoom - 1 );' +
  23.     'if ( strMapZoom === parseInt( strMapZoom ) ) { strMapZoom = strMapZoom.toFixed( 1 ); }' +
  24.     'var strMunzMap = "https://www.munzee.com/map/" + geohash.encode( map.getCenter().lat, map.getCenter().lng, 9 ) + "/" + strMapZoom;' +
  25.     'document.getElementById( "gotoMap" ).href = strMunzMap;' +
  26. //        'console.log("Set href to: %o",document.getElementById( "gotoMap" ).href)' +
  27.     ';} );' +
  28.     'document.getElementById( "gotoMapBtn" ).addEventListener( "click", function( e ){' +
  29.     'var strMapZoom = parseFloat( map._zoom - 1 );' +
  30.     'if ( strMapZoom === parseInt( strMapZoom ) ) { strMapZoom = strMapZoom.toFixed( 1 ); }' +
  31.     'var strMunzMap = "https://www.munzee.com/map/" + geohash.encode( map.getCenter().lat, map.getCenter().lng, 9 ) + "/" + strMapZoom;' +
  32.     'var el = document.createElement( "textarea" );' +
  33.     'el.value = strMunzMap;' +
  34.     'el.setAttribute( "readonly", "" );' +
  35.     'el.style = { display: "none" };' +
  36.     'document.body.appendChild( el );' +
  37.     'el.select();' +
  38.     'document.execCommand( "copy" );' +
  39.     'document.body.removeChild( el );' +
  40. //        'console.log("if ( %o )...: %o", e.ctrlKey,e);' +
  41.     'if ( !e.ctrlKey ) {' +
  42.     'e.preventDefault();' +
  43.     'alert( "Permalink <" + strMunzMap + "> copied to your clipboard!\\n\\n(Please [CTRL]-[Click] if you want to open map in new tab.)" );' +
  44.     '} else { alert( "Permalink copied to your clipboard!" ); }' +
  45.     '} );';
  46. document.getElementsByTagName( 'head' )[ 0 ].appendChild( rawScript );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement