Skip to content

sterlingmichel/angularjs-google-maps

 
 

Repository files navigation

GoogleMap AngularJS Directive

Build Status

Marker Cluster

Demo     Documentation

There is already one for this. However, I found myself doing totally different approach for this purpose than the existing one, such as;

  1. Everything in tag and attributes
    Therefore, basic users does not even have to know what Javascript is. Tag does it all.

  2. Expose the original Google Maps V3 api
    By doing so, programmers don't need to learn this module.

There is a blog that introduces this module.
The title of it is 'Google Map As The Simplest Way'

To Get Started

  1. include ng-map.js or ng-map.min.js and ngMap module to be active.
  <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script src="http://code.angularjs.org/1.2.5/angular.js"></script>
  <script src="http://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.min.js"></script>
  
  1. name angular app as ngMap, or add it as a dependency

    <html ng-app="ngMap">

  2. use map tag, and optionally, marker, and shape tags

    <map style="display:block;height:300px" />  
    

Examples

To use it in your app, please include 'ngMap' as dependency.

var myApp = angular.module('myApp', ['ngMap']); <html ng-app="myApp">

You will also have these three scope variables after these directives are initialized.

  • $scope.map
  • $scope.markers as a hash
  • $scope.shapes as a hash
  • $scope.infoWindow as a hash
  • $scope.markerCluster as a hash

In case your map directive scope is different from your controller scope, there are event emitted when each is initialized. There are three events emitted;

  • mapInitialized
  • markersInitialized
  • shpaesInitialized
  • infoWindowInitialized
  • markerClusterInitialized

Example Usage:

app.controller('parentParentController', function($scope) {
  $scope.$on('mapInitialized', function(event, map) {
    map.setCenter( .... )
    ..
  });
});

Directives

There are five directives defined with ng-map module.

  1. map
  2. marker
  3. shape
  4. info-window
  5. marker-cluster

map Tag(Directive)

As documented, it requires minimum two options, center and zoom. You can specify all map options as attributes.

These are attributes of map tag which is EXACTLY the same as the documentation except the following for the convenience

AttributesDescription
centeraddress or latitude/langitude
i.e. center="[40.79,-54,18]", center="toronto, canada"
EVENTS You can also specify any map events as an attribute.
i.e. on-click="myfunc"

For usage of map controls, please refer to this example.

marker Tag(Directive)

As documented, it reqires position as an attribute. You can list any maker options as attribute of marker tag

These are attributes of marker tag which ate EXACTLY the same as the documentation except the following for the convenienece.

AttributeDescription
id Used for programming purpose. i.e. $scope.markers.myId
position 'current', address, or latitude/longitude
i.e. 'current location', 'current position', 'Toronto, Canada', or [40.74, -74.18]
EVENTS You can also specify any marker events i.e. on-click="myfunc"

shape Tag(Directive)

shape tag always requires name attribute

  • name (the name of shape)
    i.e. polygon, image, polyline, or circle.

  • optionally, you can provide id for programming purpose. i.e. $scope.shapes.myCircle

All other attributes are based on the name you specified.
To see the full list of options of a shape for attributes, please visit the documentation.

license

MIT License

About

Google maps v3 angularjs directive module

Resources

License

Stars

Watchers

Forks

Packages

No packages published