我对 AngularJS 相当陌生,目前正在使用 google map http://angular-ui.github.io/angular-google-maps/
我已经阅读了文档,但我想做的就是 显示簇中的数字标记。
以及集群的单击时,应显示弹出工具文本。 API 并没有广泛涵盖这一点。 我想要实现的示例在这里
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>
map Controller ,遵循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);
});
最佳答案
我终于明白了。群集中的标记数量已经存在,只是它是黑色字体而不是颜色,这隐藏了它,因为标记图标也是黑色的。 单击标记时还可以显示弹出窗口 在文档中。
关于javascript - 在 Angular 谷歌地图中显示集群中的标记数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28103266/