我正在忙着将我的地图从api2移动到3并且沿途遇到一些颠簸。当使用下面的代码时,我得到一个灰色块,并且地图不会渲染。控制台说" Uncaught TypeError:无法读取属性' Map'未定义"。我正在编辑别人的工作,所以我并没有完全了解这一点,如果您能发现某些内容或需要更多细节,请告诉我。
// Initialise the required maps
Tour_Map = new Object();
Tour_Map.maps = new Array();
if (typeof (Tour_Map.GoogleMap) == 'undefined' || (!Tour_Map.GoogleMap instanceof Object)) {
Tour_Map.GoogleMap = function() {
function Map (init, options) {
// Check that we have the required information.
if (init == null
|| typeof (init) != 'object'
|| typeof (init.map_container) == 'undefined') {
alert('init failed');
return false;
}
// Only proceed if the map container is visible
if ($('#' + init.map_container).is(":visible")) {
// Set the default map options.
var map_options = {
'url': null,
'zoom': 4,
'lat': -3.5777508205127946,
'lng': 28.1195068359375,
'enableGoogleBar': 0,
'googleBarOptions': {style: "new"},
'directions': null,
'markers': null,
'route': null,
'map': null
}
//Create map
var __map = new google.maps.Map(
document.getElementById(init.map_container), {
center: new google.maps.LatLng(map_options.lat, map_options.lng),
zoom: map_options.zoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Return the Google Map
this.__map = __map;
return this;
} // if map container is visible
else {
return null;
}
} // Map constructor end
// Return our publically-accessible object.
return ({Map: Map});
}();
}
$(window).load(function() {
// Create the Google Maps by looping through the maps array created earlier
if (typeof (Tour_Map.maps) !== 'undefined') {
for (var i in Tour_Map.maps) {
Tour_Map.maps[i].map = new Tour_Map.GoogleMap.Map(Tour_Map.maps[i].init, Tour_Map.maps[i].options);
}
}
});
循环允许创建多个地图,并且在带有地图特色的页面上,有以下代码:
DSA_Map.maps.push({
init : {
map_container: 'map_branches'
},
options: {
zoom : 5,
lat : -23.92175976307374,
lng : 24.120724868774414,
directions: 1,
markers : [{exp:channel:entries orderby="title" sort="asc" channel="locations" dynamic="off" category="12|13|14" limit="5000" disable="{lv_disable_all}" {lv_tag_caching}}{exp:tied_entries this_entry_id="{entry_id}" tie="<branches" allow_php="yes" orderby="title" sort="asc"}<?php $locations[] = '<dd class="location">{title} <a class="expander">+</a></dd>'."\n";$locations[] = '<dd class="branch"><a href="#map_branches" id="marker_index'.$i++.'">{tied:title}</a></dd>'."\n"; ?>{embed="branch-finder/.js" entry_id="{tied:entry_id}" count="<?php echo $i;$i++; ?>"},{/exp:tied_entries}{/exp:channel:entries}]
}
});