Code Monkey home page Code Monkey logo

angularjs-google-maps's Introduction

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 and attribute does it all.
  2. Expose all Original Google Maps V3 api to the user through this directive. No hiding, no wraping, or whatsoever. By doing so, programmers don't need to learn this module again for AngularJS Google Map. You only need to know Google Maps V3 API.

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

To Get Started

For Bower users,

$ bower install ngmap

  1. Include ng-map.min.js as well as google maps.
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script src="http://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.min.js"></script>

  2. name angular app as ngMap, or add it as a dependency

    <html ng-app="ngMap">

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

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

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

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

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.markerCluster as a hash

In case your map directive scope is different from your controller scope, there is an event emitted when a map is initialized.

  • mapsInitialized

Example Usage:

app.controller('parentParentController', function($scope) {
  $scope.$on('mapsInitialized', function(event, maps) {
    maps[0].setCenter( .... )
    ..
  });
});

Advanced Examples

Directives

There are five directives defined with ng-map module. 1. map 2. marker 3. shape 4. marker-cluster

map Directive

It is used as a tag or an attribute.

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

AttributesDescription
centeraddress or latitude/longitude
i.e. center="[40.79,-54,18]", center="toronto, canada"
geo-fallback-centerlatitude/longitude
Coordinates to be loaded when no center is defined and retrieving current location fails i.e. geoFallbackCenter="[40.79,-54,18]"
ANY OPTIONSAs Documented
It requires minimum two options, center and zoom. You can specify all map options as attributes.
  i.e.  zoom="11" center="[40.74, -74.18]"
        zoom-control="true"
        zoom-control-options='{style:"small",position:"bottom_left"}'
        map-type-control="true"
        overview-map-control="true"
        overview-map-control-options="{opened:true}"
        pan-control="true"
        pan-control-options='{position:"left_center"}'
        rotate-control="true"
        rotate-control-options='{position:"right_center"}'
        scale-control="true"
        scale-control-options='{position:"bottom_right", style:"default"}'
        street-view-control="true
        street-view-control-options='{position:"right_center"}'
  
EVENTS You can also specify any map events as an attribute.
i.e. on-click="myfunc" on-click="getRadius()"

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

Map Examples

marker Directive

It is used as a tag or an attribute.

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]
ANY OPTIONS As Documented It reqires `position` as an attribute. You can list <marker options as attribute of marker tag
    i.e. position="[40.76, -74.16]"
        title="Hello Marker"
        animation="Animation.BOUNCE"
        draggable="true"
        visible="true"
        icon="beachflag.png"
EVENTS You can also specify any marker events i.e. on-click="myfunc"

Marker Examples

shape Directive

It is used as a tag or an attribute.

AttributeDescription
name Required, The name of the shape i.e `polygon`, `image`, `polyline`, or `circle`
id Optinal, Used for programming purpose. i.e. $scope.shapes.myCircle
ANY SHAPE OPTIONS You can specify any options as attribute that are specified in documentation following; To see the full list of options of a shape for attributes, please visit the documentation.
 - <a href=https://developers.google.com/maps/documentation/javascript/reference#PolygonOptions>polygon</a><br/>
 - <a href=https://developers.google.com/maps/documentation/javascript/reference#PolylineOptions>polyline</a><br/>
 - <a href=https://developers.google.com/maps/documentation/javascript/reference#GroundOverlayOptions>image</a><br/>
 - <a href=https://developers.google.com/maps/documentation/javascript/reference#CircleOptions>circle</a><br/>
    i.e. position="[40.76, -74.16]"
        title="Hello Marker"
        animation="Animation.BOUNCE" 
        draggable="true"
        visible="true"
        icon="beachflag.png"
ANY SHAPE EVENTS You can also specify any shape options with the prefix of `on-`
- polygon events
- polyline events
- image events
- circle events

Shape Examples

info-window Example

please visit: https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/marker_with_info_window.html

marker-clusterer Directive

AttributeDescription
markers Required, the initial markers for this marker clusterer The properties of each marker must be exactly the same as options of marker directive. The markers are also will be set to `$scope.markers`
ANY OPTION Any MarkerClusterer options

Example:

<map zoom="1" center="[43.6650000, -79.4103000]">
   <marker-clusterer markers="markersData" max-zoom="2">
</marker-clusterer>

For full working example,
please visit https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/marker_clusterer.html

license

MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.