I am currently trying to set the bounds of a custom Google map so that the user caot zoom out too far (to the point where the world map starts to tile horizontally), and caot drag too far vertically to avoid this issue.
I've added code as per another question here on SO to set the bounds, however I no longer seem to be able to drag at all. Basically I just want the bounds to be the world map to avoid the issue in the screenshot above. Anything obvious I've missed?
<style>
#map_canvas {
width: 100%;
height: 650px;
} // #map
</style>
<div id="map_canvas"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function CoordMapType(tileSize) {
this.tileSize = tileSize;
}
CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
var div = ownerDocument.createElement('DIV');
div.style.width = this.tileSize.width + 'px';
div.style.height = this.tileSize.height + 'px';
div.style.backgroundImage = 'url(http://www.transparenttextures.com/pattes/dark-denim-3.png)';
retu div;
};
var map;
var mullem = new google.maps.LatLng(50.3873733,7.4952241);
function initialize() {
var latlng = new google.maps.LatLng(50.3873733,7.4952241);
var myOptions = {
disableDefaultUI: true,
zoom: 2
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var myLatLng = new google.maps.LatLng(50.3869012, 7.4950149);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(40.6700, -73.9400),
map: map,
title: 'Sonardyne locations',
icon: 'images/map-marker.png',
zIndex: 999999
});
map.setCenter(new google.maps.LatLng(51.508742,-0.120850));
// MAP BOUNDS
/*var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(83.829945, 160.839844),
new google.maps.LatLng(-72.711903, -165.058594)
);
var lastValidCenter = map.getCenter();
google.maps.event.addListener(map, 'center_changed', function() {
if (allowedBounds.contains(map.getCenter())) {
// still within valid bounds, so save the last valid position
lastValidCenter = map.getCenter();
retu;
}
// not valid anymore => retu to last valid position
map.panTo(lastValidCenter);
});*/
// MAP BOUNDS - END
map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(256, 256)));
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
