javascript - 如何根据类别为 ng-map 标记着色

标签 javascript angularjs google-maps google-maps-api-3

我有这个功能,可以根据您的位置和选定的半径渲染附近的海湾位置。那些靠近海湾的位置有不同的类别,现在我不想根据这些类别对标记进行着色。

这是我当前的代码,因此显示数据

$scope.radius = 10;
nearBaysFactory.getNearBayInRadius(data.basicData[0].latitude, data.basicData[0].longitude, $scope.radius).then(function (data) {
    $scope.nearNearBays = data.nearBays;
    NgMap.getMap().then(function(map) {
    });
});

$scope.showSites = function (evt, id) {
    angular.forEach($scope.nearNearBays, function(value){
        if (value.id_near_bay == id) {
            $scope.selectedSite =
                value.name + "<br>" +
                value.address + "<br>" +
                "Category: " + value.category;
        }
    });
    $scope.showInfoWindow.apply(this, [evt, 'bar-info-window']);
};

我的html

<ng-map id="custom" default-style="false"
        center="46.1478781,14.4326283" zoom="9">
    <!-- this marker should be red as it is by default -->
    <marker position="{{location.basicData[0].latitude}},{{location.basicData[0].longitude}}" id="{{$index}}"
            on-click="showSites(event, n.id_location)">
    </marker>
    <!-- Those markers should be different colors based on near bay category -->
    <marker ng-repeat="n in nearNearBays" position="{{n.latitude}},{{n.longitude}}" id="{{$index}}"
            on-click="showSites(event, n.id_near_bay)" color="blue">
    </marker>
    <info-window id="bar-info-window">
        <div ng-non-bindable>
            <div id="siteNotice"></div>
            <h1 id="firstHeading" class="firstHeading" style="font-size: 17px;">
                <div ng-bind-html="selectedSite"></div>
            </h1>
            <div id="bodyContent">
                <p>
                    <a href="/#/nearbays/nearbay/{{selectedSite.id_near_bay}}">Open near bay</a>
                </p>
            </div>
        </div>
    </info-window>
</ng-map>

这是当前结果 enter image description here

这是一个近海湾物体的示例

$scope.test = [
    {
        name: 'name 1',
        address: 'Address 1',
        id_resort_category: '8',
        category : 'Towing service'
    },
    {
        name: 'name 2',
        address: 'Address 2',
        id_resort_category: '1',
        category : 'Spa'
    }
];

所以我正在寻找的是一些建议,实现方式,如何实现根据他的类别将那些附近的海湾标记呈现不同的颜色。如果您需要任何其他信息,请告诉我,我会提供。谢谢

最佳答案

在代码中,您可以使用条件语句来设置标记上的icon 属性。

您可以找到不同的图标here

关于javascript - 如何根据类别为 ng-map 标记着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43569950/

相关文章:

google-maps - 如何获取谷歌地图中两点之间的最短路径

ios - iOS:如何知道GMSMapView的缩放级别

javascript - 无法使用 Asp.Net 查看 Google map ,错误为 :InvalidKeyOrUnauthorizedURLmapError

javascript - div关闭时停止播放YouTube视频

c# - 是否可以将 XmlDocument 存储为 Javascript 中的变量

javascript - AngularJS - 使用 ng-repeat 根据数字打印输入

javascript - Angular Ng-Repeat 与键值列表

javascript - create-react-app/react-native-elements 错误

javascript - 定时规划Mysql数据库清理

javascript - 使用 AngularJS $Resource 在 MySQL 中添加和删除数据