NgMap 设置标记颜色
NgMap set marker color
我在我的网络应用程序中使用 ng-map
。在地图视图中,我使用 marker
显示不同的位置。我想更改每个标记的颜色,具体取决于我从获取位置的对象内部的 isOpned
字段。我尝试将 background-color
样式添加到我的标记中,但没有任何反应。
这是我的代码:
<ng-map zoom-to-include-markers="auto"
id="map"
map-type-id="ROADMAP"
street-view-control-options="{position: 'LEFT_CENTER'}">
<marker ng-repeat="p in paths" position="{{p.positions}}"></marker>
</ng-map>
修改 ng maps 中的代码(因为 post 中没有添加示例代码)这是想法
Plunker 演示
JS
var app = angular.module('myApp', ['ngMap']);
app.controller('mapController', function($interval) {
var vm = this;
vm.positions =[
[40.71, -74.21], [40.72, -74.20], [40.73, -74.19], [40.74, -74.18],
[40.75, -74.17], [40.76, -74.16], [40.77, -74.15], [40.77, -74.15]
];
var colorsDynamic=['ff8a80','880e4f','4a148c','311b92','3d5afe','76ff03','f57c00','5d4037']
$interval(function() {
var numMarkers = Math.floor(Math.random() * 4)+4; //between 4 to 8 markers
vm.positions = [];
vm.icon=[];//empty array of icon
for (i = 0; i < numMarkers; i++) {
var lat = 40.71 + (Math.random() / 100);
var lng = -74.21 + (Math.random() / 100);
vm.positions.push([lat, lng]);
//pushing dynamic icon color
vm.icon.push('http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|'+colorsDynamic[i])
}
}, 2000);
});
Html
<div ng-controller="mapController as vm">
<ng-map zoom="14" center="[40.71, -74.21]">
<marker ng-repeat="p in vm.positions track by $index" position="{{p}}" icon="{{vm.icon[$index]}}"></marker>
</ng-map>
我在我的网络应用程序中使用 ng-map
。在地图视图中,我使用 marker
显示不同的位置。我想更改每个标记的颜色,具体取决于我从获取位置的对象内部的 isOpned
字段。我尝试将 background-color
样式添加到我的标记中,但没有任何反应。
这是我的代码:
<ng-map zoom-to-include-markers="auto"
id="map"
map-type-id="ROADMAP"
street-view-control-options="{position: 'LEFT_CENTER'}">
<marker ng-repeat="p in paths" position="{{p.positions}}"></marker>
</ng-map>
修改 ng maps 中的代码(因为 post 中没有添加示例代码)这是想法
Plunker 演示
JS
var app = angular.module('myApp', ['ngMap']);
app.controller('mapController', function($interval) {
var vm = this;
vm.positions =[
[40.71, -74.21], [40.72, -74.20], [40.73, -74.19], [40.74, -74.18],
[40.75, -74.17], [40.76, -74.16], [40.77, -74.15], [40.77, -74.15]
];
var colorsDynamic=['ff8a80','880e4f','4a148c','311b92','3d5afe','76ff03','f57c00','5d4037']
$interval(function() {
var numMarkers = Math.floor(Math.random() * 4)+4; //between 4 to 8 markers
vm.positions = [];
vm.icon=[];//empty array of icon
for (i = 0; i < numMarkers; i++) {
var lat = 40.71 + (Math.random() / 100);
var lng = -74.21 + (Math.random() / 100);
vm.positions.push([lat, lng]);
//pushing dynamic icon color
vm.icon.push('http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|'+colorsDynamic[i])
}
}, 2000);
});
Html
<div ng-controller="mapController as vm">
<ng-map zoom="14" center="[40.71, -74.21]">
<marker ng-repeat="p in vm.positions track by $index" position="{{p}}" icon="{{vm.icon[$index]}}"></marker>
</ng-map>