UNPKG

ngmap

Version:
199 lines 15.2 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <base href="../"> <title>JSDoc: source : info-window.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 : info-window.js </h1> <div id="main" class="big-container"> <!-- source code html --> <article> <pre class="prettyprint source linenums"><code>/** * @ngdoc directive * @name info-window * @param Attr2MapOptions {service} * convert html attribute to Google map api options * @param $compile {service} $compile service * @description * Defines infoWindow and provides compile method * * Requires: map directive * * Restrict To: Element * * NOTE: this directive should **NOT** be used with `ng-repeat` * because InfoWindow itself is a template, and a template must be * reused by each marker, thus, should not be redefined repeatedly * by `ng-repeat`. * * @attr {Boolean} visible * Indicates to show it when map is initialized * @attr {Boolean} visible-on-marker * Indicates to show it on a marker when map is initialized * @attr {Expression} geo-callback * if position is an address, the expression is will be performed * when geo-lookup is successful. e.g., geo-callback="showDetail()" * @attr {String} &lt;InfoWindowOption> Any InfoWindow options, * https://developers.google.com/maps/documentation/javascript/reference?csw=1#InfoWindowOptions * @attr {String} &lt;InfoWindowEvent> Any InfoWindow events, * https://developers.google.com/maps/documentation/javascript/reference * @example * Usage: * &lt;map MAP_ATTRIBUTES> * &lt;info-window id="foo" ANY_OPTIONS ANY_EVENTS">&lt;/info-window> * &lt;/map> * * Example: * &lt;map center="41.850033,-87.6500523" zoom="3"> * &lt;info-window id="1" position="41.850033,-87.6500523" > * &lt;div ng-non-bindable> * Chicago, IL&lt;br/> * LatLng: {{chicago.lat()}}, {{chicago.lng()}}, &lt;br/> * World Coordinate: {{worldCoordinate.x}}, {{worldCoordinate.y}}, &lt;br/> * Pixel Coordinate: {{pixelCoordinate.x}}, {{pixelCoordinate.y}}, &lt;br/> * Tile Coordinate: {{tileCoordinate.x}}, {{tileCoordinate.y}} at Zoom Level {{map.getZoom()}} * &lt;/div> * &lt;/info-window> * &lt;/map> */ /* global google */ (function() { 'use strict'; var infoWindow = function(Attr2MapOptions, $compile, $q, $templateRequest, $timeout, $parse, NgMap) { var parser = Attr2MapOptions; var getInfoWindow = function(options, events, element) { var infoWindow; /** * set options */ if (options.position && !(options.position instanceof google.maps.LatLng)) { delete options.position; } infoWindow = new google.maps.InfoWindow(options); /** * set events */ for (var eventName in events) { if (eventName) { google.maps.event.addListener(infoWindow, eventName, events[eventName]); } } /** * set template and template-related functions * it must have a container element with ng-non-bindable */ var templatePromise = $q(function(resolve) { if (angular.isString(element)) { $templateRequest(element).then(function (requestedTemplate) { resolve(angular.element(requestedTemplate).wrap('&lt;div>').parent()); }, function(message) { throw "info-window template request failed: " + message; }); } else { resolve(element); } }).then(function(resolvedTemplate) { var template = resolvedTemplate.html().trim(); if (angular.element(template).length != 1) { throw "info-window working as a template must have a container"; } infoWindow.__template = template.replace(/\s?ng-non-bindable[='"]+/,""); }); infoWindow.__open = function(map, scope, anchor) { templatePromise.then(function() { $timeout(function() { anchor && (scope.anchor = anchor); var el = $compile(infoWindow.__template)(scope); infoWindow.setContent(el[0]); scope.$apply(); if (anchor && anchor.getPosition) { infoWindow.open(map, anchor); } else if (anchor && anchor instanceof google.maps.LatLng) { infoWindow.open(map); infoWindow.setPosition(anchor); } else { infoWindow.open(map); } $timeout(function() { // to avoid racing condition var infoWindowContainerEl = infoWindow.content.parentElement.parentElement.parentElement; infoWindowContainerEl.className = "ng-map-info-window"; }); }); }); }; return infoWindow; }; var linkFunc = function(scope, element, attrs, mapController) { mapController = mapController[0]||mapController[1]; element.css('display','none'); var orgAttrs = parser.orgAttributes(element); var filtered = parser.filter(attrs); var options = parser.getOptions(filtered, {scope: scope}); var events = parser.getEvents(scope, filtered); var infoWindow = getInfoWindow(options, events, options.template || element); var address; if (options.position && !(options.position instanceof google.maps.LatLng)) { address = options.position; } if (address) { NgMap.getGeoLocation(address).then(function(latlng) { infoWindow.setPosition(latlng); infoWindow.__open(mapController.map, scope, latlng); var geoCallback = attrs.geoCallback; geoCallback && $parse(geoCallback)(scope); }); } mapController.addObject('infoWindows', infoWindow); mapController.observeAttrSetObj(orgAttrs, attrs, infoWindow); mapController.showInfoWindow = mapController.map.showInfoWindow = mapController.showInfoWindow || function(p1, p2, p3) { //event, id, marker var id = typeof p1 == 'string' ? p1 : p2; var marker = typeof p1 == 'string' ? p2 : p3; if (typeof marker == 'string') { //Check if markers if defined to avoid odd 'undefined' errors if ( typeof mapController.map.markers != "undefined" && typeof mapController.map.markers[marker] != "undefined") { marker = mapController.map.markers[marker]; } else if ( //additionally check if that marker is a custom marker typeof mapController.map.customMarkers !== "undefined" && typeof mapController.map.customMarkers[marker] !== "undefined") { marker = mapController.map.customMarkers[marker]; } else { //Better error output if marker with that id is not defined throw new Error("Cant open info window for id " + marker + ". Marker or CustomMarker is not defined") } } var infoWindow = mapController.map.infoWindows[id]; var anchor = marker ? marker : (this.getPosition ? this : null); infoWindow.__open(mapController.map, scope, anchor); if(mapController.singleInfoWindow) { if(mapController.lastInfoWindow) { scope.hideInfoWindow(mapController.lastInfoWindow); } mapController.lastInfoWindow = id; } }; mapController.hideInfoWindow = mapController.map.hideInfoWindow = mapController.hideInfoWindow || function(p1, p2) { var id = typeof p1 == 'string' ? p1 : p2; var infoWindow = mapController.map.infoWindows[id]; infoWindow.close(); }; //TODO DEPRECATED scope.showInfoWindow = mapController.map.showInfoWindow; scope.hideInfoWindow = mapController.map.hideInfoWindow; var map = infoWindow.mapId ? {id:infoWindow.mapId} : 0; NgMap.getMap(map).then(function(map) { infoWindow.visible && infoWindow.__open(map, scope); if (infoWindow.visibleOnMarker) { var markerId = infoWindow.visibleOnMarker; infoWindow.__open(map, scope, map.markers[markerId]); } }); }; //link return { restrict: 'E', require: ['?^map','?^ngMap'], link: linkFunc }; }; // infoWindow infoWindow.$inject = ['Attr2MapOptions', '$compile', '$q', '$templateRequest', '$timeout', '$parse', 'NgMap']; angular.module('ngMap').directive('infoWindow', infoWindow); })(); </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>