Reputation: 1
I am trying to do something similar to: http://www.google.com/intl/en/+/demo/
Namely I aim to:
Anybody seen better solution for 1st point than: http://econym.org.uk/gmap/range.htm ?
Upvotes: 0
Views: 1408
Reputation: 70075
I think the secret sauce you're looking for in #1 would be the minZoom
and maxZoom
settings in imageMapTypeOptions
. Documentation is at http://code.google.com/apis/maps/documentation/javascript/reference.html#ImageMapTypeOptions
The solution at http://econym.org.uk/gmap/range.htm uses the deprecated Google Maps API v2, but the page at http://www.google.com/intl/en/+/demo/ uses Google Maps API v3, so they are probably doing it in substantially different ways.
Here's basically how the Google page is doing it:
function initMap() {
var mapOptions = {backgroundColor: MAP_BACKGROUND_COLOR,
center: new google.maps.LatLng(MAP_INIT_LAT, MAP_INIT_LNG),
zoom: 6,
zoomControl: true,
zoomControlOptions:{
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_BOTTOM
},
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
},
mapTypeControl: false,
mapTypeControlOptions: {
mapTypeIds: [MAP_TYPE_NAME]
},
disableDoubleClickZoom: true
};
map = new.google.maps.Map(document.getElementById("mapCanvas"), mapOptions);
var imageMapTypeOptions = {getTileUrl: getTileUrl,
tileSize: new google.maps.Size(MAP_TILE_SIZE, MAP_TILE_SIZE),
isPng: false,
minZoom: MIN_ZOOM,
maxZoom: MAX_ZOOM,
name: MAP_TYPE_NAME
};
map.mapTypes.set(MAP_TYPE_NAME, new google.maps.ImageMapType(imageMapTypeOptions));
map.setMapTypeId(MAP_TYPE_NAME);
initMarkers();
google.maps.event.addListener(map, "zoom_changed", onZoomChanged);
mapIdleListener = google.maps.event.addListener(map, "idle", onMapLoaded);
onZoomChanged()
}
function onZoomChanged() {
featureButtonsActivated && closeInfobox();
var a = map.getZoom();
for (id in section)
section[id].type != TYPE_FEATURE && (a >= section[id].zoom.min && a <= section[id].zoom.max ? createMarker(id) : removeMarker(id))
}
function getTileUrl(point, number) {
return getTilesFrom('http://www.gstatic.com/plus/demo/', point, number)
}
function getTilesFrom(cdnUrl, point, number) {
point = getNormalizedCoord(point, number);
if (!point)
return null;
cdnUrl = cdnUrl + "/" + number + "-" + point.x + "-" + point.y + ".jpg";
switch (number) {
case 2:
if (point.y <= 0 || point.y >= 3)
cdnUrl = WHITE_TILE_PATH;
break;
case 3:
if (point.y <= 1 || point.y >= 6)
cdnUrl = WHITE_TILE_PATH;
break;
case 4:
if (point.y <= 4 || point.y >= 11)
cdnUrl = WHITE_TILE_PATH;
break;
case 5:
if (point.y <= 10 || point.y >= 22)
cdnUrl = WHITE_TILE_PATH;
break;
case 6:
if (point.y <= 21 || point.y >= 43)
cdnUrl = WHITE_TILE_PATH
}
return cdnUrl;
}
Looking at this code, it appears to me that Google is returning JPG images and not HTML for their tiles. If you can explain what features make you think it's HTML rather than JPG images, maybe we can try to figure out how they're implementing that feature.
Upvotes: 2