Created
December 7, 2017 14:18
-
-
Save guillaumebcom/c98d33fd9ddafc1826e6bf9171857c5a to your computer and use it in GitHub Desktop.
Tumblr Geo-tagging - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{block:IfEnableGeotag} | |
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={text:Google Maps Key}&sensor=false"></script> | |
<script type="text/javascript"> | |
var map; // global Google Map object | |
google.maps.visualRefresh = true; // enable new gmap look for opt-inners | |
// start Google Map | |
google.maps.event.addDomListener(window, 'load', function() { | |
var mapOptions = { | |
center: $(".post:first").data('coords') || new google.maps.LatLng(45.764, 4.835), | |
zoom: 15, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
scrollwheel: false, | |
mapTypeControlOptions: { | |
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, | |
position: google.maps.ControlPosition.LEFT_BOTTOM | |
}, | |
panControl: false, | |
scaleControl: true, | |
streetViewControl: false, | |
styles: [{ | |
"featureType": "landscape.natural.terrain", | |
"elementType": "geometry.fill", | |
"stylers": [{ | |
"visibility": "off" | |
}] | |
}, { | |
"featureType": "poi.attraction", | |
"elementType": "geometry.fill", | |
"stylers": [{ | |
"visibility": "off" | |
}] | |
}, {}], | |
}; | |
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); | |
// The coordinates are loaded when the tags are created and attached to the canvas. | |
map.panTo($('#map-canvas').data('coords')); | |
}); | |
XMLHttpRequest.prototype.originalSend=XMLHttpRequest.prototype.send; | |
XMLHttpRequest.prototype.send=function(s){ | |
this.addEventListener('load',function(){ | |
// event handling to refresh the map if a post is being scrolled into view | |
$("#content").scroll(function() { | |
$(".post").map(function() { | |
if (! $(this).data('currentlyInView') && $(this).offset().top > 70 && $(this).offset().top < 180 ) { | |
// the post is visible, we need to refresh the map | |
moveToPostLocation(this); | |
return; | |
} | |
}); | |
}); | |
},false); | |
this.originalSend(s); | |
} | |
</script> | |
{/block:IfEnableGeotag} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment