Last active
August 29, 2015 14:23
-
-
Save danicarrion/c914f315325ed909a34e to your computer and use it in GitHub Desktop.
Map with image overlay (GMaps)
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- See Javier Arce's original for Leaflet: http://bl.ocks.org/javierarce/e7ec4b39013aa03ebd5e --> | |
<title>Map with image overlay | CartoDB.js</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="https://maps.googleapis.com/maps/api/js?libraries=visualization&sensor=false"></script> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<script> | |
function main() { | |
var myLatlng = new google.maps.LatLng(40.712216, -74.22655); | |
var mapOptions = { | |
zoom: 13, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById('map'), mapOptions); | |
cartodb.createLayer(map, 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json') | |
.addTo(map) | |
.on('done', function(layer) { | |
layer.setInteraction(true); | |
var imageUrl = 'https://farm4.staticflickr.com/3731/14101168818_932d707f90_o.jpg'; | |
// This is the trickiest part - you'll need accurate coordinates for the | |
// corners of the image. You can find and create appropriate values at | |
// http://maps.nypl.org/warper/ or | |
// http://www.georeferencer.org/ | |
var swBound = new google.maps.LatLng(40.712216, -74.22655); | |
var neBound = new google.maps.LatLng(40.773941, -74.12544); | |
var bounds = new google.maps.LatLngBounds(swBound, neBound); | |
imageOverlay = new google.maps.GroundOverlay(imageUrl, bounds); | |
imageOverlay.setMap(map); | |
}).on('error', function() { | |
cartodb.log.log("some error occurred"); | |
}); | |
} | |
// you could use $(window).load(main); | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same as https://gist.github.com/javierarce/e7ec4b39013aa03ebd5e, but with Google Maps