5

I am using Angular-google-maps, HTML code follows

  <ui-gmap-google-map center='mapData.map.center' zoom='mapData.map.zoom' 
  events="mapEvents">
    <ui-gmap-markers models="mapData.map.markers" coords="'self'">
    </ui-gmap-markers>
  </ui-gmap-google-map>

in JS calling

angular.extend(this, $controller('MapsMixinController', 
{$scope:$scope, map:mapData.data[0].map}));

MapsMixinController as follows. Calling this controller from js code. Markers are showing & on click able to mark.

MapsMixinController.js

/**
 * Controller providing common behaviour for the other map controllers
 */
angular
    .module('app')
    .controller('MapsMixinController', ['$scope', 'GeolocationService', 'uiGmapGoogleMapApi', 'map',
        function($scope, GeolocationService, GoogleMapApi, map) {
            var _this = this;

            $scope.mapEvents = {
                click: function(mapModel, eventName, originalEventArgs) {
                    var e = originalEventArgs[0];
                    if (e.latLng) {
                        $scope.mapData.map.markers.push({
                            id: new Date().getTime(),
                            latitude: e.latLng.lat(),
                            longitude: e.latLng.lng()
                        });
                        // This event is outside angular boundary, hence we need to call $apply here
                        $scope.$apply();
                    }
                }
            };

            // Returns a default map based on the position sent as parameter
            this.getDefaultMap = function(position) {
                return {
                    markers: [],
                    center: {
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude
                    },
                    zoom: 14
                };
            };

            // Initialize the google maps api and configure the map
            GoogleMapApi.then(function() {
                GeolocationService().then(function(position) {
                    $scope.mapData.map = map || _this.getDefaultMap(position);
                }, function() {
                    $scope.error = "Unable to set map data"; // TODO use translate
                });
            });
        }
    ]);

How can I show title on mouse hover on markers? And on click how to show description on markers?

1 Answers1

2

You can add title property alone with latitude and longtitude property while creating marker data.

    /**
 * Controller providing common behaviour for the other map controllers
 */
angular
    .module('app')
    .controller('MapsMixinController', ['$scope', 'GeolocationService', 'uiGmapGoogleMapApi', 'map',
        function($scope, GeolocationService, GoogleMapApi, map) {
            var _this = this;

            $scope.mapEvents = {
                click: function(mapModel, eventName, originalEventArgs) {
                    var e = originalEventArgs[0];
                    if (e.latLng) {
                        $scope.mapData.map.markers.push({
                            id: new Date().getTime(),
                            latitude: e.latLng.lat(),
                            longitude: e.latLng.lng(),
                            title: "Mouse over text"
                        });
                        // This event is outside angular boundary, hence we need to call $apply here
                        $scope.$apply();
                    }
                }
            };

            // Returns a default map based on the position sent as parameter
            this.getDefaultMap = function(position) {
                return {
                    markers: [],
                    center: {
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude
                    },
                    zoom: 14
                };
            };

            // Initialize the google maps api and configure the map
            GoogleMapApi.then(function() {
                GeolocationService().then(function(position) {
                    $scope.mapData.map = map || _this.getDefaultMap(position);
                }, function() {
                    $scope.error = "Unable to set map data"; // TODO use translate
                });
            });
        }
    ]);
Sathish
  • 106
  • 8
  • 1
    Sathish, your plunkr is about "marker" not "markers". None of the answers solves how to show a diferent title for each marker in "markerS" – JoeCool Aug 12 '16 at 20:03