我正在尝试使用 ng-map 中的 ng-repeat 将地图标记动态添加到地图中,如下所示,
<div id="map-canvas">
<ng-map default-style="true">
<marker id='ID{{school.id}}' ng-repeat="school in vm.schools" position="{{school.location}}" on-click="vm.showDetail(school)" icon="assets/img/marker-excellent.png">
</marker>
<info-window id="marker-info">
<div ng-non-bindable="">
<h5>{{vm.school.name}}</h5>
</div>
</info-window>
</ng-map>
</div>
这将创建具有相同标记图标的多个标记。我想根据 {{school.rating}} 的值使用不同的标记图标。但是,当 ng-repeat 正在运行以在地图上呈现标记时,我无法弄清楚如何根据 rating 的值更改标记图标 url。
目前,我正在做以下事情,但我认为这是一种低效的方法。
<div id="map-canvas">
<ng-map default-style="true">
<marker id='ID{{school.id}}' ng-if="school.overallRating >= 4.5" ng-repeat="school in filteredSchools = (search.schools | filter:boardsFilter)" position="{{school.location}}" on-click="search.showDetail(school)" icon="assets/img/marker-excellent.png">
</marker>
<marker id='ID{{school.id}}' ng-if="school.overallRating < 4.5 && school.overallRating >= 3.5" ng-repeat="school in filteredSchools = (search.schools | filter:boardsFilter)" position="{{school.location}}" on-click="search.showDetail(school)" icon="assets/img/marker-good.png">
</marker>
<marker id='ID{{school.id}}' ng-if="school.overallRating < 3.5 && school.overallRating >= 2.0" ng-repeat="school in filteredSchools = (search.schools | filter:boardsFilter)" position="{{school.location}}" on-click="search.showDetail(school)" icon="assets/img/marker-average.png">
</marker>
<info-window id="marker-info">
<div ng-non-bindable="">
<h5>{{vm.school.name}}</h5>
</div>
</info-window>
</ng-map>
</div>
在这里,我使用 ng-if 放置了多个标记指令,每个都具有 ng-repeat 但不同的条件
我想知道是否有更有效的方法来使用带有 ng-repeat 的单个标记指令