|
| 1 | +angular.module("angular-google-maps-example", ["google-maps"]).value("rndAddToLatLon",function () { |
| 2 | + return Math.floor(((Math.random() < 0.5 ? -1 : 1) * 2) + 1) |
| 3 | +}).controller("controller", function ($scope, $timeout, $log, $http, rndAddToLatLon) { |
| 4 | + // Enable the new Google Maps visuals until it gets enabled by default. |
| 5 | + // See http://googlegeodevelopers.blogspot.ca/2013/05/a-fresh-new-look-for-maps-api-for-all.html |
| 6 | + google.maps.visualRefresh = true; |
| 7 | + |
| 8 | + var versionUrl = window.location.host === "rawgithub.com" ? "http://rawgithub.com/nlaplante/angular-google-maps/master/package.json" : "/package.json"; |
| 9 | + |
| 10 | + $http.get(versionUrl).success(function (data) { |
| 11 | + if (!data) |
| 12 | + console.error("no version object found!!"); |
| 13 | + $scope.version = data.version; |
| 14 | + }); |
| 15 | + |
| 16 | + angular.extend($scope, { |
| 17 | + map: { |
| 18 | + control: {}, |
| 19 | + center: { |
| 20 | + latitude: 45, |
| 21 | + longitude: -73 |
| 22 | + }, |
| 23 | + options: { |
| 24 | + streetViewControl: false, |
| 25 | + panControl: false, |
| 26 | + maxZoom: 20, |
| 27 | + minZoom: 3 |
| 28 | + }, |
| 29 | + zoom: 3, |
| 30 | + dragging: false, |
| 31 | + bounds: {}, |
| 32 | + dynamicMarkers: [], |
| 33 | + refresh: function () { |
| 34 | + $scope.map.control.refresh(origCenter); |
| 35 | + } |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + $scope.refreshMap = function () { |
| 40 | + //optional param if you want to refresh you can pass null undefined or false or empty arg |
| 41 | + $scope.map.control.refresh({latitude: 32.779680, longitude: -79.935493}); |
| 42 | + $scope.map.control.getGMap().setZoom(11); |
| 43 | + }; |
| 44 | + $scope.getMapInstance = function () { |
| 45 | + alert("You have Map Instance of" + $scope.map.control.getGMap().toString()); |
| 46 | + }; |
| 47 | + |
| 48 | +// var oldMarker = null; |
| 49 | + $scope.onMarkerClicked = function (marker) { |
| 50 | +// if(oldMarker){ |
| 51 | +//// oldMarker.options = {animation:google.maps.Animation.DROP}; // or 2 |
| 52 | +// oldMarker.options = {animation:0}; //or null |
| 53 | +// } |
| 54 | + marker.showWindow = false; |
| 55 | + if(marker.options) |
| 56 | + marker.options = null; |
| 57 | + else |
| 58 | + marker.options = {animation:google.maps.Animation.BOUNCE}; //or 1 |
| 59 | +// oldMarker = marker; |
| 60 | + $scope.$apply(); |
| 61 | + }; |
| 62 | + |
| 63 | + $scope.onInsideWindowClick = function () { |
| 64 | + alert("Window hit!"); |
| 65 | + }; |
| 66 | + |
| 67 | + $timeout(function () { |
| 68 | + var dynamicMarkers = [ |
| 69 | + { id: 1, |
| 70 | + latitude: 46, |
| 71 | + longitude: -79 |
| 72 | + }, |
| 73 | + { |
| 74 | + id: 2, |
| 75 | + latitude: 33, |
| 76 | + longitude: -79 |
| 77 | + }, |
| 78 | + { |
| 79 | + id: 3, |
| 80 | + icon: 'assets/images/plane.png', |
| 81 | + latitude: 35, |
| 82 | + longitude: -127 |
| 83 | + }, |
| 84 | + { |
| 85 | + id: 4, |
| 86 | + icon: 'assets/images/plane.png', |
| 87 | + latitude: 35, |
| 88 | + longitude: -128, |
| 89 | + title: '[35,-125]' |
| 90 | + } |
| 91 | + ]; |
| 92 | + _.each(dynamicMarkers, function (marker) { |
| 93 | + marker.closeClick = function () { |
| 94 | + marker.showWindow = false; |
| 95 | + $scope.$apply(); |
| 96 | + }; |
| 97 | + marker.onClicked = function () { |
| 98 | + $scope.onMarkerClicked(marker); |
| 99 | + }; |
| 100 | + }); |
| 101 | + $scope.map.dynamicMarkers = dynamicMarkers; |
| 102 | + }, 2000); |
| 103 | + |
| 104 | + var origCenter = {latitude: $scope.map.center.latitude, longitude: $scope.map.center.longitude}; |
| 105 | +}); |
0 commit comments