2

in one of my client project I'm using ngMap (http://ngmap.github.io/), but I have problem with this "directive": how to user marker cluster and a map like this:

<div ng-controller="MyCtrl">
      <map center="41,-87" zoom="3">

        <info-window id="foo2">
          <div ng-non-bindable="">
            Lat/Lng: {{this.getPosition()}}<br/>
            <ul>
              <li ng-repeat='item in store.items'>{{item}}</li>
            </ul>
          </div>
        </info-window>

        <marker ng-repeat="(id, store) in stores" id="{{id}}"
          position="{{store.position}}"
          on-click="showStore(event, id)"
        ></marker>
      </map>
    </div>

I have searched in the example pages and codes, but there is no documentation about how to use marker cluster in my situation.

Does someone use this ngmap ? Or do I need to change google map angularjs directive ?

Thanks.

ZioBudda
  • 948
  • 2
  • 12
  • 24
  • You can check [**this**](http://stackoverflow.com/questions/20919127/any-documentation-on-angular-google-maps-clustering-options) out, or an angular map library with marker cluster [**example**](https://github.com/allenhwkim/angularjs-google-maps/blob/master/testapp/marker-clusterer.html) – so_jin_ee May 14 '15 at 17:56
  • Hi, I know the example page, but in that page there is no infowindow and infowindow (in ngMap directive) is created inside , outside the controller. In that example all is made inside controller. Thanks however – ZioBudda May 14 '15 at 21:51
  • @ZioBudda have you solve your problem. I have a very similar problem with you – Munkhtsogt May 05 '16 at 07:42

1 Answers1

10

MarkerClusterer is a separate library for the Google Maps JavaScript API v3, here is a working example that demonstrates how to utilize MarkerClusterer with ng-map:

angular.module('mapApp', ['ngMap'])
    .controller('mapController', function ($scope, NgMap) {

        NgMap.getMap().then(function (map) {
            $scope.map = map;
            $scope.initMarkerClusterer();
        });

        $scope.cities = [
            { id: 1, name: 'Oslo', pos: [59.923043, 10.752839] },
            { id: 2, name: 'Stockholm', pos: [59.339025, 18.065818] },
            { id: 3, name: 'Copenhagen', pos: [55.675507, 12.574227] },
            { id: 4, name: 'Berlin', pos: [52.521248, 13.399038] },
            { id: 5, name: 'Paris', pos: [48.856127, 2.346525] }
        ];
        


        $scope.initMarkerClusterer = function () {
            var markers = $scope.cities.map(function (city) {
                return $scope.createMarkerForCity(city);
            });
            var mcOptions = { imagePath: 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m' };
            return new MarkerClusterer($scope.map, markers, mcOptions);
        };


        $scope.createMarkerForCity = function (city) {
            var marker = new google.maps.Marker({
                position: new google.maps.LatLng(city.pos[0], city.pos[1]),
                title: city.name
            });
            google.maps.event.addListener(marker, 'click', function () {
                $scope.selectedCity = city;
                $scope.map.showInfoWindow('myInfoWindow', this);
            });
            return marker;
        }

    });
<script src="https://code.angularjs.org/1.4.8/angular.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js"></script>
    <script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
    <script src="https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script>
<div ng-app="mapApp" ng-controller="mapController">
        <ng-map default-style="true" zoom="3" center="59.339025, 18.065818">
            <info-window id="myInfoWindow">
                <div ng-non-bindable>
                    <h4>{{selectedCity.name}}</h4>
                </div>
            </info-window>
        </ng-map>
    </div>
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • The library doesn't support any more. Please check this [MarkerClustererPlus](https://github.com/googlemaps/v3-utility-library/tree/master/markerclustererplus) instead – Denis Aug 15 '18 at 18:34