Browse Source

Fixed default google map bug

pull/75/head
Zach Wise 13 years ago
parent
commit
f4082fb63f
  1. 52
      source/js/VMM.ExternalAPI.js

52
source/js/VMM.ExternalAPI.js

@ -233,6 +233,14 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
} }
}, },
defaultType: function(name) {
if (name.toLowerCase() == "satellite" || name.toLowerCase() == "hybrid" || name.toLowerCase() == "terrain" || name.toLowerCase() == "roadmap") {
return true;
} else {
return false;
}
},
map_subdomains: ["", "a.", "b.", "c.", "d."], map_subdomains: ["", "a.", "b.", "c.", "d."],
map_attribution: { map_attribution: {
@ -269,7 +277,7 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
"apple": { "apple": {
"url": "http://gsp2.apple.com/tile?api=1&style=slideshow&layers=default&lang=en_US&z={z}&x={x}&y={y}&v=9", "url": "http://gsp2.apple.com/tile?api=1&style=slideshow&layers=default&lang=en_US&z={z}&x={x}&y={y}&v=9",
"minZoom": 4, "minZoom": 4,
"maxZoom": 20, "maxZoom": 14,
"attribution": "apple" "attribution": "apple"
}, },
"watercolor": { "watercolor": {
@ -281,7 +289,6 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
}, },
createMap: function(m) { createMap: function(m) {
trace(VMM.ExternalAPI.googlemaps.stamen_map_attribution);
/* MAP PROVIDERS /* MAP PROVIDERS
Including Stamen Maps Including Stamen Maps
http://maps.stamen.com/ http://maps.stamen.com/
@ -295,11 +302,19 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
map_attribution = VMM.ExternalAPI.googlemaps.map_attribution[VMM.ExternalAPI.googlemaps.map_providers[name].attribution]; map_attribution = VMM.ExternalAPI.googlemaps.map_attribution[VMM.ExternalAPI.googlemaps.map_providers[name].attribution];
return VMM.ExternalAPI.googlemaps.map_providers[name]; return VMM.ExternalAPI.googlemaps.map_providers[name];
} else { } else {
throw 'No such provider: "' + name + '"'; if (VMM.ExternalAPI.googlemaps.defaultType(name)) {
trace("GOOGLE MAP DEFAULT TYPE");
return google.maps.MapTypeId[name.toUpperCase()];
} else {
trace("Not a maptype: " + name );
}
} }
} }
google.maps.VeriteMapType = function(name) { google.maps.VeriteMapType = function(name) {
if (VMM.ExternalAPI.googlemaps.defaultType(name)) {
return google.maps.MapTypeId[name.toUpperCase()];
} else {
var provider = mapProvider(name); var provider = mapProvider(name);
return google.maps.ImageMapType.call(this, { return google.maps.ImageMapType.call(this, {
"getTileUrl": function(coord, zoom) { "getTileUrl": function(coord, zoom) {
@ -320,6 +335,7 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
"minZoom": provider.minZoom, "minZoom": provider.minZoom,
"maxZoom": provider.maxZoom "maxZoom": provider.maxZoom
}); });
}
}; };
google.maps.VeriteMapType.prototype = new google.maps.ImageMapType("_"); google.maps.VeriteMapType.prototype = new google.maps.ImageMapType("_");
@ -328,9 +344,12 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
================================================== */ ================================================== */
var layer; var layer;
if (type.of(VMM.master_config.Timeline.maptype) == "string") { if (type.of(VMM.master_config.Timeline.maptype) == "string") {
if (VMM.ExternalAPI.googlemaps.defaultType(VMM.master_config.Timeline.maptype)) {
layer = google.maps.MapTypeId[VMM.master_config.Timeline.maptype.toUpperCase()];
} else {
layer = VMM.master_config.Timeline.maptype; layer = VMM.master_config.Timeline.maptype;
}
} else { } else {
layer = "toner"; layer = "toner";
} }
@ -374,50 +393,45 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
} }
var unique_map_id = m.id.toString() + "_gmap"; var unique_map_id = m.id.toString() + "_gmap";
VMM.attachElement("#" + m.id, "<div class='google-map' id='" + unique_map_id + "' style='width=100%;height=100%;'></div>"); VMM.attachElement("#" + m.id, "<div class='google-map' id='" + unique_map_id + "' style='width=100%;height=100%;'></div>");
var map = new google.maps.Map(document.getElementById(unique_map_id), map_options); var map = new google.maps.Map(document.getElementById(unique_map_id), map_options);
map.mapTypes.set(layer, new google.maps.VeriteMapType(layer));
/* ATTRIBUTION if (VMM.ExternalAPI.googlemaps.defaultType(VMM.master_config.Timeline.maptype)) {
================================================== */
} else {
map.mapTypes.set(layer, new google.maps.VeriteMapType(layer));
// ATTRIBUTION
var map_attribution_html = "<div class='map-attribution'><div class='attribution-text'>" + map_attribution + "</div></div>"; var map_attribution_html = "<div class='map-attribution'><div class='attribution-text'>" + map_attribution + "</div></div>";
VMM.appendElement("#"+unique_map_id, map_attribution_html); VMM.appendElement("#"+unique_map_id, map_attribution_html);
}
loadKML(); loadKML();
/* KML // KML
================================================== */
function loadKML() { function loadKML() {
var kml_url = m.url + "&output=kml"; var kml_url = m.url + "&output=kml";
kml_url = kml_url.replace("&output=embed", ""); kml_url = kml_url.replace("&output=embed", "");
var kml_layer = new google.maps.KmlLayer(kml_url, {preserveViewport:true}); var kml_layer = new google.maps.KmlLayer(kml_url, {preserveViewport:true});
kml_layer.setMap(map);
var infowindow = new google.maps.InfoWindow(); var infowindow = new google.maps.InfoWindow();
kml_layer.setMap(map);
google.maps.event.addListenerOnce(kml_layer, "defaultviewport_changed", function() { google.maps.event.addListenerOnce(kml_layer, "defaultviewport_changed", function() {
map.fitBounds(kml_layer.getDefaultViewport() ); map.fitBounds(kml_layer.getDefaultViewport() );
if (has_location) { if (has_location) {
map.panTo(location); map.panTo(location);
} }
if (has_zoom) { if (has_zoom) {
map.setZoom(zoom); map.setZoom(zoom);
} }
}); });
google.maps.event.addListener(kml_layer, 'click', function(kmlEvent) { google.maps.event.addListener(kml_layer, 'click', function(kmlEvent) {
var text = kmlEvent.featureData.description; var text = kmlEvent.featureData.description;
trace(kmlEvent.featureData.infoWindowHtml)
showInfoWindow(text); showInfoWindow(text);
function showInfoWindow(c) { function showInfoWindow(c) {
//trace("showInfoWindow")
infowindow.setContent(c); infowindow.setContent(c);
infowindow.open(map); infowindow.open(map);
} }

Loading…
Cancel
Save