Created
January 13, 2016 02:00
-
-
Save randomradio/fe81fae23d74c1be28cc to your computer and use it in GitHub Desktop.
openLayer google map integration
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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>The HTML5 Herald</title> | |
<meta name="description" content="The HTML5 Herald"> | |
<meta name="author" content="SitePoint"> | |
<link rel="stylesheet" href="ol.css"> | |
<script src="https://maps.google.com/maps/api/js?v=3&sensor=false"></script> | |
<script src="ol.js"></script> | |
<!--[if lt IE 9]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
</head> | |
<body style="height: 100%; width: 100%;"> | |
<div id="gmap" style="height: 800px; width: 100%"></div> | |
<div id="olmap" style="height: 800px; width: 100%"></div> | |
<script> | |
var gmap = new google.maps.Map(document.getElementById('gmap'), { | |
disableDefaultUI: true, | |
keyboardShortcuts: false, | |
draggable: false, | |
disableDoubleClickZoom: true, | |
scrollwheel: false, | |
streetViewControl: false | |
}); | |
var view = new ol.View({ | |
// make sure the view doesn't go beyond the 22 zoom levels of Google Maps | |
maxZoom: 21 | |
}); | |
view.on('change:center', function() { | |
var center = ol.proj.transform(view.getCenter(), 'EPSG:3857', 'EPSG:4326'); | |
gmap.setCenter(new google.maps.LatLng(center[1], center[0])); | |
}); | |
view.on('change:resolution', function() { | |
gmap.setZoom(view.getZoom()); | |
}); | |
var vector = new ol.layer.Vector({ | |
source: new ol.source.Vector({ | |
url: | |
'your url or use features', | |
format: new ol.format.GeoJSON(), | |
}), | |
style: new ol.style.Style({ | |
fill: new ol.style.Fill({ | |
color: 'rgba(255, 255, 255, 0.6)' | |
}), | |
stroke: new ol.style.Stroke({ | |
color: '#319FD3', | |
width: 1 | |
}) | |
}) | |
}); | |
var olMapDiv = document.getElementById('olmap'); | |
var map = new ol.Map({ | |
layers: [vector], | |
interactions: ol.interaction.defaults({ | |
altShiftDragRotate: false, | |
dragPan: false, | |
rotate: false | |
}).extend([new ol.interaction.DragPan({kinetic: null})]), | |
target: olMapDiv, | |
view: view | |
}); | |
view.setCenter([0, 0]); | |
view.setZoom(1); | |
olMapDiv.parentNode.removeChild(olMapDiv); | |
gmap.controls[google.maps.ControlPosition.TOP_LEFT].push(olMapDiv); | |
</script> | |
<!--<script src="script.js"></script>--> | |
<!--<script src="tiles.js"></script>--> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment