我对 AngularJS 相当陌生,目前正在使用来自 http://angular-ui.github.io/angular-google-maps/的谷歌地图
我已经浏览了文档,但我想要做的就是在集群中显示数字标记。
以及集群的 OnClick,应显示弹出工具文本。该 api 没有广泛涵盖这一点。我想要实现的例子是here
http://104.131.42.57/frontend/index.html
以下是我当前的代码:
HTML 指令
<div ng-controller="MapsController">
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" bounds="map.bounds">
<ui-gmap-markers doCluster="true" clusterOptions="clusterOptions" models="puMarkers" coords="'self'" icon="'icon'">
</ui-gmap-markers>
</ui-gmap-google-map>
地图控制器,遵循 api 文档。
controllers.controller('MapsController', function($scope,mapService) {
var locationArray ;
$scope.map = {
center: {
latitude: 8.69128,
longitude: 8.5208073
},
zoom: 6,
bounds: {}
};
$scope.options = {
scrollwheel: false
};
$scope.clusterOptions = {
gridSize: 60,
ignoreHidden: true,
minimumClusterSize: 5,
imageExtension: 'png',
imagePath: 'assets/img/cluster',
imageSizes: [72] };
var createRandomMarker = function(i, bounds, idKey,point) {
var ret = {
latitude: point.g,
longitude: point.f,
title: 'm' + i,
icon: 'assets/img/marker.png',
options: { title: point.t }
};
ret[idKey] = i;
return ret;
};
$scope.puMarkers = [];
// 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 = [];
/* Load Markers from Rest Services*/
var promise = mapService.getPollingUnits(1);
promise.success(function(retData,status,headers,config) {
if (retData.error == false) {
var i = 1 ;
locationArray = retData.events;
locationArray.forEach(function(item){
markers.push(createRandomMarker( i, $scope.map.bounds, "id", item ));
i++;
});
}
});
$scope.puMarkers = markers;
}
}, true);
});