【发布时间】:2015-12-02 05:07:39
【问题描述】:
问题:
我正在尝试在 angular-map 加载之前将 1369 个地图标记放在它上面,但我遇到了一致性问题。地图加载所有 1369 的一半时间,另一半将加载随机数。
Map.js
angular.module('dogMap')
.controller('MapCtrl', function($scope, $meteor, uiGmapGoogleMapApi) {
uiGmapGoogleMapApi.then(function(maps) {
var dogParks = $meteor.collection(DogParks);
$scope.map = {
zoom: 4,
bounds: {},
center: {
latitude: 40.1451,
longitude: -99.6680
}
};
function assignMarkersToMap() {
markers = [];
for (var i=0; i < (dogParks.length - 1); i++) {
markers.push({
latitude: dogParks[i].latitude,
longitude: dogParks[i].longitude,
title: dogParks[i].name,
id: dogParks[i]._id,
icon: "https://developers.google.com/maps/documentation/javascript
/examples/full/images/beachflag.png"
});
};
return markers;
};
$scope.markers = [];
// Get the bounds from the map once it's loaded
$scope.$watch(function() {
return $scope.map.bounds;
}, function(nv, ov) {
// Only need to regenerate once
if (!ov.southwest && nv.southwest) {
var markers = []
$scope.markers = assignMarkersToMap();
}
}, true);
$scope.markerCount = function() {
console.log($scope.markers.length);
};
$scope.windowCoords = {};
$scope.parkName = "cool";
$scope.onClick = function(marker, eventName, model) {
$scope.map.center.latitude = model.latitude;
$scope.map.center.longitude = model.longitude;
$scope.map.zoom = 11;
$scope.windowCoords.latitude = model.latitude;
$scope.windowCoords.longitude = model.longitude;
$scope.parkName = model.title;
$scope.show = true;
};
$scope.closeClick = function() {
$scope.show = false;
};
$scope.options = {
scrollwheel: false
};
$scope.show = false;
});
});
map.html
<h1>Testing Map View</h1>
<div id="map_canvas">
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="false"
options="options" bounds="map.bounds" control="googlemap">
<ui-gmap-markers models="markers" coords="'self'" icon="'icon'"
options="'options'" doRebuildAll="true" click="onClick">
<ui-gmap-window show="show" coords='windowCoords' closeClick="closeClick()">
<div>{{parkName}}</div>
</ui-gmap-window>
</ui-gmap-markers>
</ui-gmap-google-map>
</div>
<button ng-click="markerCount();">Marker Count</button>
【问题讨论】:
-
对当前工作代码有一个工作小提琴会有所帮助
标签: angularjs google-maps meteor