UNPKG

ngmap

Version:
158 lines 13 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <base href="../"> <title>JSDoc: source : shape.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 : shape.js </h1> <div id="main" class="big-container"> <!-- source code html --> <article> <pre class="prettyprint source linenums"><code>/** * @ngdoc directive * @name shape * @param Attr2MapOptions {service} convert html attribute to Google map api options * @description * Initialize a Google map shape in map with given options and register events * The shapes are: * . circle * . polygon * . polyline * . rectangle * . groundOverlay(or image) * * Requires: map directive * * Restrict To: Element * * @attr {Boolean} centered if set, map will be centered with this marker * @attr {Expression} geo-callback if shape is a circle and the center is * an address, the expression is will be performed when geo-lookup * is successful. e.g., geo-callback="showDetail()" * @attr {String} &lt;OPTIONS> * For circle, [any circle options](https://developers.google.com/maps/documentation/javascript/reference#CircleOptions) * For polygon, [any polygon options](https://developers.google.com/maps/documentation/javascript/reference#PolygonOptions) * For polyline, [any polyline options](https://developers.google.com/maps/documentation/javascript/reference#PolylineOptions) * For rectangle, [any rectangle options](https://developers.google.com/maps/documentation/javascript/reference#RectangleOptions) * For image, [any groundOverlay options](https://developers.google.com/maps/documentation/javascript/reference#GroundOverlayOptions) * @attr {String} &lt;MapEvent> [Any Shape events](https://developers.google.com/maps/documentation/javascript/reference) * @example * Usage: * &lt;map MAP_ATTRIBUTES> * &lt;shape name="SHAPE_NAME ANY_SHAPE_OPTIONS ANY_SHAPE_EVENTS">&lt;/shape> * &lt;/map> * * Example: * * &lt;map zoom="11" center="[40.74, -74.18]"> * &lt;shape id="polyline" name="polyline" geodesic="true" * stroke-color="#FF0000" stroke-opacity="1.0" stroke-weight="2" * path="[[40.74,-74.18],[40.64,-74.10],[40.54,-74.05],[40.44,-74]]" > * &lt;/shape> * &lt;/map> * * &lt;map zoom="11" center="[40.74, -74.18]"> * &lt;shape id="polygon" name="polygon" stroke-color="#FF0000" * stroke-opacity="1.0" stroke-weight="2" * paths="[[40.74,-74.18],[40.64,-74.18],[40.84,-74.08],[40.74,-74.18]]" > * &lt;/shape> * &lt;/map> * * &lt;map zoom="11" center="[40.74, -74.18]"> * &lt;shape id="rectangle" name="rectangle" stroke-color='#FF0000' * stroke-opacity="0.8" stroke-weight="2" * bounds="[[40.74,-74.18], [40.78,-74.14]]" editable="true" > * &lt;/shape> * &lt;/map> * * &lt;map zoom="11" center="[40.74, -74.18]"> * &lt;shape id="circle" name="circle" stroke-color='#FF0000' * stroke-opacity="0.8"stroke-weight="2" * center="[40.70,-74.14]" radius="4000" editable="true" > * &lt;/shape> * &lt;/map> * * &lt;map zoom="11" center="[40.74, -74.18]"> * &lt;shape id="image" name="image" * url="https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg" * bounds="[[40.71,-74.22],[40.77,-74.12]]" opacity="0.7" * clickable="true"> * &lt;/shape> * &lt;/map> * * For full-working example, please visit * [shape example](https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/shape.html) */ /* global google */ (function() { 'use strict'; var getShape = function(options, events) { var shape; var shapeName = options.name; delete options.name; //remove name bcoz it's not for options console.log("shape", shapeName, "options", options, 'events', events); /** * set options */ switch(shapeName) { case "circle": if (!(options.center instanceof google.maps.LatLng)) { options.center = new google.maps.LatLng(0,0); } shape = new google.maps.Circle(options); break; case "polygon": shape = new google.maps.Polygon(options); break; case "polyline": shape = new google.maps.Polyline(options); break; case "rectangle": shape = new google.maps.Rectangle(options); break; case "groundOverlay": case "image": var url = options.url; var opts = {opacity: options.opacity, clickable: options.clickable, id:options.id}; shape = new google.maps.GroundOverlay(url, options.bounds, opts); break; } /** * set events */ for (var eventName in events) { if (events[eventName]) { google.maps.event.addListener(shape, eventName, events[eventName]); } } return shape; }; var shape = function(Attr2MapOptions, $parse, NgMap) { var parser = Attr2MapOptions; var linkFunc = function(scope, element, attrs, mapController) { mapController = mapController[0]||mapController[1]; var orgAttrs = parser.orgAttributes(element); var filtered = parser.filter(attrs); var shapeOptions = parser.getOptions(filtered, {scope: scope}); var shapeEvents = parser.getEvents(scope, filtered); var address, shapeType; shapeType = shapeOptions.name; if (!(shapeOptions.center instanceof google.maps.LatLng)) { address = shapeOptions.center; } var shape = getShape(shapeOptions, shapeEvents); mapController.addObject('shapes', shape); if (address && shapeType == 'circle') { NgMap.getGeoLocation(address).then(function(latlng) { shape.setCenter(latlng); shape.centered && shape.map.setCenter(latlng); var geoCallback = attrs.geoCallback; geoCallback && $parse(geoCallback)(scope); }); } //set observers mapController.observeAttrSetObj(orgAttrs, attrs, shape); element.bind('$destroy', function() { mapController.deleteObject('shapes', shape); }); }; return { restrict: 'E', require: ['?^map','?^ngMap'], link: linkFunc }; // return }; shape.$inject = ['Attr2MapOptions', '$parse', 'NgMap']; angular.module('ngMap').directive('shape', shape); })(); </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>