Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Added callback functionality for ui-map. #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1>Marker</h1>
google maps-->
<div id="map_canvas" ui-map="myMap" class="col-md-8 map"
ui-event="{'map-click': 'addMarker($event, $params)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
ui-options="mapOptions">
ui-options="mapOptions" ui-on-finish="myCallback">
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ angular.module('doc.ui-map', ['ui.map', 'prettifyDirective', 'ui.bootstrap', 'pl

$scope.myMarkers = [];

$scope.myCallback = function() {
console.log('callback called');
};

$scope.mapOptions = {
center: new google.maps.LatLng(35.784, -78.670),
zoom: 15,
Expand Down
5 changes: 5 additions & 0 deletions src/ui-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
model.assign(scope, map);

bindMapEvents(scope, mapEvents, map, elm);

if (attrs.uiOnFinish) {
// call the callback
scope[attrs.uiOnFinish](map);
}
}
};
}]);
Expand Down
12 changes: 12 additions & 0 deletions test/mapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ describe('uiMap', function () {
google.maps.event.trigger(scope.gmap, 'dragend');
expect(scope.county).toBe(2);
});

it('should execute the passed callback after having compiled the directive', function() {
scope.callbackCalled = false;
scope.gmapCallback = function(map) {
if (map) {
scope.callbackCalled = true;
}
};

$compile("<div><div ui-map='gmap' ui-on-finish='gmapCallback'></div></div>")(scope);
expect(scope.callbackCalled).toBeTruthy();
});
});

describe('test infoWindow', function () {
Expand Down