UNPKG

ngmap

Version:
115 lines 11 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <base href="../"> <title>JSDoc: source : marker.js</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"> source : marker.js </h1> <div id="main" class="big-container"> <!-- source code html --> <article> <pre class="prettyprint source linenums"><code>/** * @ngdoc directive * @name marker * @param Attr2Options {service} convert html attribute to Google map api options * @param NavigatorGeolocation It is used to find the current location * @description * Draw a Google map marker on a map with given options and register events * * Requires: map directive * * Restrict To: Element * * @attr {String} position address, 'current', or [latitude, longitude] * example: * '1600 Pennsylvania Ave, 20500 Washingtion DC', * 'current position', * '[40.74, -74.18]' * @attr {Boolean} centered if set, map will be centered with this marker * @attr {Expression} geo-callback if position is an address, * the expression is will be performed when geo-lookup is successful. * e.g., geo-callback="showStoreInfo()" * @attr {Boolean} no-watcher if true, no attribute observer is added. * Useful for many ng-repeat * @attr {String} &lt;MarkerOption> * [Any Marker options](https://developers.google.com/maps/documentation/javascript/reference?csw=1#MarkerOptions) * @attr {String} &lt;MapEvent> * [Any Marker events](https://developers.google.com/maps/documentation/javascript/reference) * @example * Usage: * &lt;map MAP_ATTRIBUTES> * &lt;marker ANY_MARKER_OPTIONS ANY_MARKER_EVENTS">&lt;/MARKER> * &lt;/map> * * Example: * &lt;map center="[40.74, -74.18]"> * &lt;marker position="[40.74, -74.18]" on-click="myfunc()">&lt;/div> * &lt;/map> * * &lt;map center="the cn tower"> * &lt;marker position="the cn tower" on-click="myfunc()">&lt;/div> * &lt;/map> */ /* global google */ (function() { 'use strict'; var parser, $parse, NgMap; var getMarker = function(options, events) { var marker; if (NgMap.defaultOptions.marker) { for (var key in NgMap.defaultOptions.marker) { if (typeof options[key] == 'undefined') { console.log('setting default marker options', key, NgMap.defaultOptions.marker); options[key] = NgMap.defaultOptions.marker[key]; } } } if (!(options.position instanceof google.maps.LatLng)) { options.position = new google.maps.LatLng(0,0); } marker = new google.maps.Marker(options); /** * set events */ if (Object.keys(events).length > 0) { console.log("markerEvents", events); } for (var eventName in events) { if (eventName) { google.maps.event.addListener(marker, eventName, events[eventName]); } } return marker; }; var linkFunc = function(scope, element, attrs, mapController) { mapController = mapController[0]||mapController[1]; var orgAttrs = parser.orgAttributes(element); var filtered = parser.filter(attrs); var markerOptions = parser.getOptions(filtered, scope, {scope: scope}); var markerEvents = parser.getEvents(scope, filtered); console.log('marker options', markerOptions, 'events', markerEvents); var address; if (!(markerOptions.position instanceof google.maps.LatLng)) { address = markerOptions.position; } var marker = getMarker(markerOptions, markerEvents); mapController.addObject('markers', marker); if (address) { NgMap.getGeoLocation(address).then(function(latlng) { marker.setPosition(latlng); markerOptions.centered && marker.map.setCenter(latlng); var geoCallback = attrs.geoCallback; geoCallback && $parse(geoCallback)(scope); }); } //set observers mapController.observeAttrSetObj(orgAttrs, attrs, marker); /* observers */ element.bind('$destroy', function() { mapController.deleteObject('markers', marker); }); }; var marker = function(Attr2MapOptions, _$parse_, _NgMap_) { parser = Attr2MapOptions; $parse = _$parse_; NgMap = _NgMap_; return { restrict: 'E', require: ['^?map','?^ngMap'], link: linkFunc }; }; marker.$inject = ['Attr2MapOptions', '$parse', 'NgMap']; angular.module('ngMap').directive('marker', marker); })(); </code></pre> </article> <!-- index.html --> <!-- 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>