I am using Angular Google maps with a list of markers. As the map zooms in I would like the list to shrink to only show the markers currently in view.
I have created a plunker with some code. Any help on how I could filter the list as the map zooms?
<!DOCTYPE html>
<html ng-app="ngMap">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="https://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script>
angular.module('ngMap').controller('MyCtrl', function() {
var vm=this;
vm.positions =[
{pos:[40.71, -74.15]},
{pos:[40.72, -74.20]},
{pos:[40.73, -74.18]},
{pos:[40.77, -74.19]},
{pos:[40.75, -74.17]},
{pos:[40.76, -74.16]},
{pos:[40.74, -74.20]}
];
vm.showData = function() {
alert(this.data.foo);
}
});
</script>
</head>
<body>
<div ng-controller="MyCtrl as vm">
<ng-map zoom="11" center="[40.74, -74.18]">
<marker ng-repeat="p in vm.positions"
position="{{p.pos}}"
title="pos: {{p.pos}}"></marker>
</ng-map>
<div>
<div ng-repeat="p in vm.positions">{{p.pos}}</div>
</div>
</div>
</body>
As far as I can tell from the documentation, there is no directive or configuration that will do this for you.
I created the following work-around that will filter the positions any time the bounds of the map change (filtering out those positions which do not fall between the bounds of the map), which I believe is what you're after.
UPDATE 10/23/18
Here is a better solution ---> https://embed.plnkr.co/pe6Hv5wHknxtwn4F5aST/