Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 999f99f

Browse files
committed
Gruntfile:
- version appended to non minified version same as develop Map.Control: - refresh and getGMap are now more functional oriented - the directive looks for a controller to have control= defined. The object is extended with refresh and getGMap which are direct callback hooks to the directive itself. Refresh: Accepts optional coordinates to panTo or Center on a new postion after refresh / "resize" is triggered issue #230 See example.html for map.control.refresh and map.control.getGMap
1 parent f798704 commit 999f99f

File tree

6 files changed

+57
-21
lines changed

6 files changed

+57
-21
lines changed

Gruntfile.coffee

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ module.exports = (grunt) ->
6161

6262
concat:
6363
options:
64+
banner: "/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today(\"yyyy-mm-dd\") %>\n * <%= pkg.description %>\n * <%= pkg.repository.type %>: <%= pkg.repository.url %>\n */\n"
6465
separator: ";"
6566

6667
dist:
6768
src: ["tmp/output_coffee.js", "lib/*.js"]
6869
dest: "tmp/output.js"
6970

7071
copy:
71-
options:
72-
banner: "/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today(\"yyyy-mm-dd\") %>\n * <%= pkg.description %>\n * <%= pkg.repository.type %>: <%= pkg.repository.url %>\n */\n"
73-
7472
dist:
7573
files: [
7674
src: "tmp/output.js"

dist/angular-google-maps.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*! angular-google-maps 1.0.12 2014-02-17
2+
* AngularJS directives for Google Maps
3+
* git: https://github.com/nlaplante/angular-google-maps.git
4+
*/
15
/*
26
Author Nick McCready
37
Intersection of Objects if the arrays have something in common each intersecting object will be returned
@@ -2420,7 +2424,7 @@ Nick Baugh - https://github.com/niftylettuce
24202424
center: "=center",
24212425
zoom: "=zoom",
24222426
dragging: "=dragging",
2423-
refresh: "&refresh",
2427+
control: "=",
24242428
windows: "=windows",
24252429
options: "=options",
24262430
events: "=events",
@@ -2571,19 +2575,29 @@ Nick Baugh - https://github.com/niftylettuce
25712575
}
25722576
}
25732577
scope.map = _m;
2574-
google.maps.event.trigger(_m, "resize");
2575-
if (!angular.isUndefined(scope.refresh())) {
2576-
scope.$watch("refresh()", function(newValue, oldValue) {
2578+
if ((attrs.control != null) && (scope.control != null)) {
2579+
scope.control.refresh = function(maybeCoords) {
25772580
var coords;
2578-
if ((newValue != null) && !oldValue) {
2579-
coords = getCoords(newValue);
2581+
if (_m == null) {
2582+
return;
2583+
}
2584+
google.maps.event.trigger(_m, "resize");
2585+
if (((maybeCoords != null ? maybeCoords.latitude : void 0) != null) && ((maybeCoords != null ? maybeCoords.latitude : void 0) != null)) {
2586+
coords = getCoords(maybeCoords);
25802587
if (isTrue(attrs.pan)) {
25812588
return _m.panTo(coords);
25822589
} else {
25832590
return _m.setCenter(coords);
25842591
}
25852592
}
2586-
});
2593+
};
2594+
/*
2595+
I am sure you all will love this. You want the instance here you go.. BOOM!
2596+
*/
2597+
2598+
scope.control.getGMap = function() {
2599+
return _m;
2600+
};
25872601
}
25882602
scope.$watch("center", (function(newValue, oldValue) {
25892603
var coords;

dist/angular-google-maps.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example-controller.js

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function ExampleController($scope, $timeout, $log, $http) {
4949

5050
angular.extend($scope, {
5151
map: {
52+
control:{},
5253
version: "uknown",
5354
heatLayerCallback: function (layer) {
5455
//set the heat layers backend data
@@ -307,6 +308,16 @@ function ExampleController($scope, $timeout, $log, $http) {
307308
$scope.map.templatedInfoWindow.show = false;
308309
// $scope.map.infoWindow.coords = null;
309310
};
311+
$scope.refreshMap = function() {
312+
//optional param if you want to refresh you can pass null undefined or false or empty arg
313+
$scope.map.control.refresh({latitude:32.779680,longitude:-79.935493});
314+
$scope.map.control.getGMap().setZoom(11);
315+
return;
316+
};
317+
$scope.getMapInstance = function() {
318+
alert("You have Map Instance of" + $scope.map.control.getGMap().toString());
319+
return;
320+
}
310321
$scope.map.clusterOptionsText = JSON.stringify($scope.map.clusterOptions);
311322
$scope.$watch('map.clusterOptionsText', function (newValue, oldValue) {
312323
if (newValue !== oldValue)

example/example.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ <h2>angular-google-maps example <span ng-cloak>{{version}}</span></h2>
4242
bounds="map.bounds"
4343
events="map.events"
4444
options="map.options"
45-
pan="true" >
45+
pan="true"
46+
control="map.control"
47+
>
4648

4749
<layer type="TrafficLayer" show="map.showTraffic"></layer>
4850
<layer type="BicyclingLayer" show="map.showBicycling"></layer>
@@ -125,6 +127,8 @@ <h2>angular-google-maps example <span ng-cloak>{{version}}</span></h2>
125127
geodesic='p.geodesic' fit="false" editable="p.editable" draggable="p.draggable"></polyline>
126128
</div>
127129
<button class="btn btn-danger pull-right" ng-click="removeMarkers()">Clear Map</button>
130+
<button class="btn btn-success pull-right" ng-click="refreshMap()">Refresh Map</button>
131+
<button class="btn btn-success pull-right" ng-click="getMapInstance()">Get Map Instance</button>
128132
</div>
129133
<div class="span5">
130134
<fieldset>

src/coffee/directives/map.coffee

+17-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ angular.module("google-maps").directive "googleMap", ["$log", "$timeout", ($log,
6262
center: "=center" # required
6363
zoom: "=zoom" # required
6464
dragging: "=dragging" # optional
65-
refresh: "&refresh" # optional
65+
control: "=" # optional
6666
windows: "=windows" # optional TODO is this still needed looks like dead code
6767
options: "=options" # optional
6868
events: "=events" # optional
@@ -177,17 +177,26 @@ angular.module("google-maps").directive "googleMap", ["$log", "$timeout", ($log,
177177

178178
# Put the map into the scope
179179
scope.map = _m
180-
google.maps.event.trigger _m, "resize"
181-
182-
# Check if we need to refresh the map
183-
unless angular.isUndefined(scope.refresh())
184-
scope.$watch "refresh()", (newValue, oldValue) ->
185-
if newValue? and not oldValue
186-
coords = getCoords(newValue)
180+
# google.maps.event.trigger _m, "resize"
181+
182+
# check if have an external control hook to direct us manually without watches
183+
#this will normally be an empty object that we extend and slap functionality onto with this directive
184+
if attrs.control? and scope.control?
185+
scope.control.refresh = (maybeCoords) =>
186+
return unless _m?
187+
google.maps.event.trigger _m, "resize" #actually refresh
188+
#do we have new coords to goto along with the refresh?
189+
if maybeCoords?.latitude? and maybeCoords?.latitude?
190+
coords = getCoords(maybeCoords)
187191
if isTrue(attrs.pan)
188192
_m.panTo coords
189193
else
190194
_m.setCenter coords
195+
###
196+
I am sure you all will love this. You want the instance here you go.. BOOM!
197+
###
198+
scope.control.getGMap = ()=>
199+
_m
191200

192201
# Update map when center coordinates change
193202
scope.$watch "center", ((newValue, oldValue) ->

0 commit comments

Comments
 (0)