One of the functionalities I have allows users to see nearby locations based on their position and selected radius. These locations fall into different categories, and now I want to customize the markers' colors based on those categories.
Here is a snippet of my current code:
$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']);
};
Here's a glimpse at my HTML setup:
<ng-map id="custom" default-style="false"
center="46.1478781,14.4326283" zoom="9">
<!-- Default marker in red -->
<marker position="{{location.basicData[0].latitude}},{{location.basicData[0].longitude}}" id="{{$index}}"
on-click="showSites(event, n.id_location)">
</marker>
<!-- Custom-colored markers 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>
Check out the current result https://i.sstatic.net/41Ncy.png
Here is an example of one of the near bay objects:
$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'
}
];
I am seeking suggestions or guidance on how to render these near bay markers with different colors based on their category. Any additional information needed will be provided upon request. Thank you!