UNPKG

ngmap

Version:
115 lines 15.1 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JSDoc: Index</title> <link href="css/prettify-tomorrow.css" type="text/css" rel="stylesheet"> <link href="css/site.css" type="text/css" rel="stylesheet"> </head> <body ng-app=""> <nav id="toc"> <input placeholder="Filter" id="filter-input" class="col12 block field" type="text"> <div class="nav-wrapper"> <h2><a href="index.html">Index</a></h2> <ul class="module"> <!-- undefined --> <h2 class="module"> <a chref="" ng-click="moduleundefined = !moduleundefined"> module: undefined </a> <i ng-cloak="" ng-show="moduleundefined">+</i> </h2> <li id="undefined" ng-hide="moduleundefined"> <ul class="group"> <h2> <a href="" ng-click="undefinedservice = !undefinedservice"> service </a> <i ng-cloak="" ng-show="undefinedservice">+</i> </h2> <ul ng-hide="undefinedservice"> <li> <a href="Attr2MapOptions.html">Attr2MapOptions</a> </li><li> <a href="GeoCoder.html">GeoCoder</a> </li><li> <a href="GoogleMapsApi.html">GoogleMapsApi</a> </li><li> <a href="NavigatorGeolocation.html">NavigatorGeolocation</a> </li><li> <a href="StreetView.html">StreetView</a> </li> </ul> </ul><ul class="group"> <h2> <a href="" ng-click="undefineddirective = !undefineddirective"> directive </a> <i ng-cloak="" ng-show="undefineddirective">+</i> </h2> <ul ng-hide="undefineddirective"> <li> <a href="bicycling-layer.html">bicycling-layer</a> </li><li> <a href="custom-control.html">custom-control</a> </li><li> <a href="directions.html">directions</a> </li><li> <a href="drawing-manager.html">drawing-manager</a> </li><li> <a href="dynamic-maps-engine-layer.html">dynamic-maps-engine-layer</a> </li><li> <a href="fusion-tables-layer.html">fusion-tables-layer</a> </li><li> <a href="heatmap-layer.html">heatmap-layer</a> </li><li> <a href="info-window.html">info-window</a> </li><li> <a href="kml-layer.html">kml-layer</a> </li><li> <a href="map-data.html">map-data</a> </li><li> <a href="map-lazy-load.html">map-lazy-load</a> </li><li> <a href="map-type.html">map-type</a> </li><li> <a href="maps-engine-layer.html">maps-engine-layer</a> </li><li> <a href="marker.html">marker</a> </li><li> <a href="overlay-map-type.html">overlay-map-type</a> </li><li> <a href="places-auto-complete.html">places-auto-complete</a> </li><li> <a href="shape.html">shape</a> </li><li> <a href="streetview-panorama.html">streetview-panorama</a> </li><li> <a href="traffic-layer.html">traffic-layer</a> </li><li> <a href="transit-layer.html">transit-layer</a> </li> </ul> </ul><ul class="group"> <h2> <a href="" ng-click="undefinedprovider = !undefinedprovider"> provider </a> <i ng-cloak="" ng-show="undefinedprovider">+</i> </h2> <ul ng-hide="undefinedprovider"> <li> <a href="NgMap.html">NgMap</a> </li> </ul> </ul><ul class="group"> <h2> <a href="" ng-click="undefinedfactory = !undefinedfactory"> factory </a> <i ng-cloak="" ng-show="undefinedfactory">+</i> </h2> <ul ng-hide="undefinedfactory"> <li> <a href="NgMapPool.html">NgMapPool</a> </li> </ul> </ul> </li> </ul><ul class="module"> <!-- ngmap --> <h2 class="module"> <a chref="" ng-click="modulengmap = !modulengmap"> module: ngmap </a> <i ng-cloak="" ng-show="modulengmap">+</i> </h2> <li id="ngmap" ng-hide="modulengmap"> <ul class="group"> <h2> <a href="" ng-click="ngmapdirective = !ngmapdirective"> directive </a> <i ng-cloak="" ng-show="ngmapdirective">+</i> </h2> <ul ng-hide="ngmapdirective"> <li> <a href="ngmap.custom-marker.html">custom-marker</a> </li> </ul> </ul> </li> </ul><ul class="module"> <!-- ng_ap --> <h2 class="module"> <a chref="" ng-click="moduleng_ap = !moduleng_ap"> module: ngMap </a> <i ng-cloak="" ng-show="moduleng_ap">+</i> </h2> <li id="ngMap" ng-hide="moduleng_ap"> <ul class="group"> <h2> <a href="" ng-click="ng_apdirective = !ng_apdirective"> directive </a> <i ng-cloak="" ng-show="ng_apdirective">+</i> </h2> <ul ng-hide="ng_apdirective"> <li> <a href="ngMap.ng-map.html">ng-map</a> </li> </ul> </ul> </li> </ul> </div> </nav> <div id="content" class="page-wrap"> <h1 class="title"> Index </h1> <div id="main" class="big-container"> <!-- source code html --> <!-- index.html --> <section class="section-readme"> <article> <h1>Google Maps AngularJS Directive</h1><!-- [![Build Status](https://travis-ci.org/allenhwkim/angularjs-google-maps.png?branch=master)](https://travis-ci.org/allenhwkim/angularjs-google-maps) --> <p><a href="https://ngmap.github.io">Demo</a><br><a href="https://rawgithub.com/allenhwkim/angularjs-google-maps/master/build/docs/index.html">Documentation</a><br><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/street-view_road_trip.html">Road Trip By StreetView</a><br><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/custom-marker.html">Maps Can Talk</a> | <a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/custom-marker-2.html">Custom Marker</a> </p> <p>If you like this, you also may like these:</p> <ul> <li><a href="https://github.com/ng2-ui/map">ng2-map</a> Google Maps Wrapper for Angular 2+</li> <li><a href="https://github.com/allenhwkim/react-openlayers">react-openlayers</a> React + OpenLayers</li> </ul> <h2>Background</h2><p>There is already <a href="https://github.com/nlaplante/angular-google-maps">one</a> for this. However, I found myself taking a totally different approach than the existing one, such as:</p> <ol> <li><p><strong>Everything in tag and attributes.</strong><br>Thus, users don't even need knowledge of JavaScript.</p> </li> <li><p><strong>Expose all original Google Maps V3 API to the user.</strong><br>No hiding, no wrapping or whatsoever. By doing so, programmers don't need to learn how to use this module. You only need to know Google Maps V3 API.</p> </li> </ol> <p>There is a blog that introduces this module. The title of it is '<a href="http://allenhwkim.tumblr.com/post/70986888283/google-map-as-the-simplest-way">Google Map As The Simplest Way</a>'</p> <h2>To get started</h2><p>For Bower users,</p> <p> <code>$ bower install ngmap</code></p> <ol> <li><p>Include <code>ng-map.min.js</code>: <code>&lt;script src=&quot;/bower_components/ngmap/build/scripts/ng-map.min.js&quot;&gt;&lt;/script&gt;</code></p> </li> <li><p>Include Google Maps:<br> <code>&lt;script src=&quot;http://maps.google.com/maps/api/js&quot;&gt;&lt;/script&gt;</code> </p> </li> <li><p>Name your AngularJS app ngMap, or add it as a dependency</p> <p><code>var myApp = angular.module('myApp', ['ngMap']);</code></p> </li> </ol> <p>To get the map instance use the <code>NgMap.getMap()</code> function</p> <pre class="prettyprint source"><code>app.controller('MyController', function(NgMap) { NgMap.getMap().then(function(map) { console.log(map.getCenter()); console.log('markers', map.markers); console.log('shapes', map.shapes); }); });</code></pre><p>For npm users,</p> <p> <code>$ npm install ngmap</code></p> <p>For Meteor users: https://atmospherejs.com/wormy/angularjs-google-maps</p> <h2>Lazy loading of Google Maps JavaScript</h2><p> Simply wrap the map tag with <code>map-lazy-load=&quot;https://maps.google.com/maps/api/js&quot;</code>.</p> <pre class="prettyprint source"><code>&lt;div map-lazy-load=&quot;https://maps.google.com/maps/api/js&quot;> &lt;ng-map center=&quot;41,-87&quot; zoom=&quot;3&quot;>&lt;/ng-map> &lt;/div></code></pre><p> If you need to pass in an API key to the javascript, you can set a scope variable in your controller (e.g. <code>$scope.googleMapsUrl=&quot;https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE&quot;;</code>). This can be set from a constant value in your app to standardise the API key to pass to google for multiple controllers.</p> <pre class="prettyprint source"><code>&lt;div map-lazy-load=&quot;https://maps.google.com/maps/api/js&quot; map-lazy-load-params=&quot;{{googleMapsUrl}}&quot;> &lt;ng-map center=&quot;41,-87&quot; zoom=&quot;3&quot;>&lt;/ng-map> &lt;/div></code></pre><h2>FAQ</h2><h2>Grey area in Google Maps</h2><p>The usual reason why this happens is that the size of the map is changed after the map has been initialized. If you for some reason change the size of the div, you need to trigger the &quot;resize&quot; event and possible recenter the map.</p> <pre class="prettyprint source"><code> var center = map.getCenter(); google.maps.event.trigger(map, &quot;resize&quot;); map.setCenter(center);</code></pre><p>Ref.</p> <ul> <li>http://stackoverflow.com/questions/13901520/grey-area-in-google-maps</li> <li>http://blog.codebusters.pl/en/google-maps-in-hidden-div/</li> </ul> <h2>Check if a marker is within <code>Map</code>, <code>Rectangle</code>, or <code>Circle</code></h2><pre class="prettyprint source"><code>`map.getBounds().contains(marker.getPosition());`</code></pre><ul> <li>http://stackoverflow.com/questions/3648545/how-can-i-check-the-marker-is-or-isnt-in-the-bounds-using-google-maps-v3</li> <li>https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map</li> <li>https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle</li> <li>https://developers.google.com/maps/documentation/javascript/3.exp/reference#Circle</li> </ul> <h2>Calculate distance between two position</h2><p>You can check this out: https://developers.google.com/maps/documentation/javascript/distancematrix. As you see, DistanceMatrix does not require map nor directive.</p> <p>Another way to do this, is to use directions directive. As you see it here: https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/directions2.html, you have access to DirectionsRenderer by using <code>map.directionsRenderers[id]</code></p> <p>https://developers.google.com/maps/documentation/javascript/reference?hl=en#DirectionsRenderer</p> <p>You use <code>getDirections()</code> or <code>directions</code>, then calculate the distance from there. e.g.,</p> <p> Distance: <code>{{ map.directionsRenderers[0].directions.routes[0].legs[0].distance }}</code></p> <h2>Directives</h2><ul> <li>bicycling-layer</li> <li>custom-control</li> <li>custom-marker (NEW)</li> <li>directions (NEW)</li> <li>drawing-manager (NEW)</li> <li>dynamic-maps-engine-layer</li> <li>fusion-tables-layer</li> <li>heatmap-layer</li> <li>info-window</li> <li>kml-layer</li> <li>map</li> <li>map-data</li> <li>map-lazy-load (NEW)</li> <li>map-type</li> <li>map_controller</li> <li>maps-engine-layer</li> <li>marker</li> <li>overlay-map-type</li> <li>places-auto-complete</li> <li>shape</li> <li>street-view-panorama (NEW)</li> <li>traffic-layer</li> <li>transit-layer</li> </ul> <h2>Advanced examples</h2><ul> <li><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/marker-clusterer.html">Marker Clusterer</a></li> <li><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/map_app.html">Starbucks World Wide</a></li> <li><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/street-view_road_trip.html">Road Trip By StreetView</a></li> <li><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/custom-marker.html">Maps Can Talk</a></li> <li><a href="https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/custom-marker-2.html">Custom Marker</a></li> </ul> <h1><a href="CONTRIBUTORS.md">Contributors</a></h1><h1>Contributing</h1><ul> <li>Clone the repository from GitHub.</li> <li>Change to the cloned directory.</li> <li><strong>npm install</strong> to install the build tools</li> <li><strong>gulp build</strong> to build the JavaScript &amp; doc files in the /build folder &amp; run the unit tests.</li> <li><strong>gulp clean</strong> to clean up the repository by removing files and folders from previous build.</li> <li><strong>gulp test</strong> to run the Karma unit test suite.</li> <li><strong>gulp test:e2e</strong> to run the Protractor test suite. For the first test run, you may need to update the protractor webdriver manager. It will show the command on screen if this is required (node_modules/gulp-protractor/node_modules/protractor/bin/webdriver-manager update).</li> <li><strong>gulp test:server</strong> will start a web server for the testapp on http://localhost:8888</li> </ul> <h1>License</h1><p><a href="https://github.com/allenhwkim/angularjs-google-maps/blob/master/LICENSE">MIT License</a></p> </article> </section> <!-- class files --> </div> <footer style="clear:both"> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> using <a href="https://github.com/allenhwkim/angular-jsdoc">Angular-JSDoc template</a> </footer> </div> <script src="js/prettify.js"></script> <script src="js/angular.min.js"></script> <script src="js/site.js"></script> <!--%= prettyJson %--> <script> prettyPrint(); var lineNo = window.location.hash.match(/#line([0-9]+)$/); lineNo && document.querySelector("ol li:nth-child("+(lineNo[1])+")").scrollIntoView(); </script> </body> </html>