我知道还有其他类似的问题,但这特定于我在MEAN.js应用程序中使用ngmap的实现。
一切看起来像它正在按应有的方式工作..
页面加载时,我两次收到此错误:
Uncaught TypeError: Cannot read property 'x' of undefined common.js:210
这是错误跟踪:
这是我的HTML:
<div class="row">
<div class="col-md-12">
<ng-map>
<marker data-ng-repeat="device in panelController.model.projects.focused.devices"
position="{{[device.location.lat, device.location.lng]}}"
title="{{device.name}}"
animation="none"
draggable="false"
visible="true"
icon="modules/core/img/dashboard/marker.png">
</marker>
</ng-map>
</div>
</div>
以及相关的控制器代码:
self.completeProjectLoad = function(project) {
/* ======= New functionality to set bound box around markers ======= */
function getLocations() {
var locations = [];
for (var i=0; i < project.devices.length; i++) {
locations[i] = [project.devices[i].location.lat, project.devices[i].location.lng];
}
return locations;
}
var locatedDevices = getLocations();
var bounds = new google.maps.LatLngBounds();
// create bounds around all located devices
for (var i=0; i < locatedDevices.length; i++) {
// get the latitude and longitude in the google maps expected format
var latlng = new google.maps.LatLng(locatedDevices[i][0], locatedDevices[i][1]);
//extend the bounds to contain each device
bounds.extend(latlng)
}
// self.mapCenter = bounds.getCenter;
/* ====== End of new functionality ======= */
// Set the bounds of map to include all devices
NgMap.getMap().then(function(map) {
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
})
};
所有这些共同构成了这一点:
正如我所说,SEEM可以正常工作,但是我怀疑这是一个错误,以后会困扰我。
感谢任何帮助或想法。提前致谢
最佳答案
我不使用ngmap,但有完全相同的错误消息:
未捕获的TypeError:无法读取未定义common.js的属性'x':179
当我没有定义center
或zoom
选项时,这正在发生。我通过添加这些选项来映射初始化进行了修复。
# this is coffeescript
map = new google.maps.Map(
document.getElementById('map-search')
center: new google.maps.LatLng(42, -71)
zoom: 10
)