Reputation: 8053
Let's say you open this map:
https://www.google.com.au/maps/@-33.8654593,151.2082297,15z
When you pan, you see that the map is being loaded. It's of course better now, as maps are vectors drawn in a canvas element. But still you need to wait for a while.
The same happens when you use panTo
method of a Map object in Google Maps API (docs). And this is mainly my problem. I want to pan using JavaScript to some area of a Google Map which is already preloaded, so user see the whole view sharp even when animating.
Is there any way to specify a region of a map to preload so you don't see it loading?
Upvotes: 1
Views: 1819
Reputation: 8053
In addition to @Gady's answer I prepared a trick which did a job for me - I made a map just bigger than my screen, so invisible areas are loaded as well. Here's the code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { width: 300%; left: -100%; height: 300%; top: -100%; }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
It's copied from here + my little tweak. Remember to replace API_KEY
with working key generated here.
Upvotes: 0
Reputation: 4995
No, unfortunately there is no way to do this as part of the JavaScript API.
Upvotes: 1