//根据services层映射路径从服务器获取数据
$scope.getBorderNode = function () {
var nodes = [];
var n = [];
Home.getBorderNode().then(function (resData) {
for (var k = 0; k < resData.value.length; k++) {
n.push(resData.value[k]);
}
//引入linq.js文件
nodes = n.groupBy(g => g.childId);
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
$scope.showBorder(node);
}
});
};
//加载图形
$scope.showBorder = function (nodes) {
var a = [];
if (nodes[0].borderType === ‘3‘) {
//多边形
for (var i = 0; i < nodes.length; i++) {
a.push([nodes[i].lng, nodes[i].lat]);
}
var polygon = new AMap.Polygon({
path: a,
strokeColor: ‘#FF33FF‘,
strokeWeight: 6,
strokeOpacity: 0.2,
fillOpacity: 0.4,
fillColor: ‘#1791fc‘,
zIndex: 50,
});
$scope.map.add(polygon);
// $scope.map.setFitView([polygon]);
}
//圆形
if (nodes[0].borderType === ‘2‘) {
for (var i = 0; i < nodes.length; i++) {
var circle = new AMap.Circle({
center: [nodes[i].lng, nodes[i].lat],
radius: nodes[i].radius, //半径
borderWeight: 3,
strokeColor: ‘#FF33FF‘,
strokeOpacity: 1,
strokeWeight: 6,
fillOpacity: 0.4,
strokeStyle: ‘dashed‘,
strokeDasharray: [10, 10],
fillColor: ‘#1791fc‘,
zIndex: 50,
});
$scop.map.add(circle);
}
}
};
最后在加载地图信息方法调用,注意异步问题。
APP开发——加载地图上绘制信息