Extract showing search result

This commit is contained in:
Rohan Mitchell
2016-07-01 13:32:14 +10:00
parent a9a68151ec
commit e6bdd2303d

View File

@@ -10,7 +10,7 @@ Darkswarm.directive 'mapSearch', ($timeout) ->
map = ctrl.getMap()
searchBox = scope.createSearchBox map
scope.respondToSearch map, searchBox
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
@@ -19,11 +19,16 @@ Darkswarm.directive 'mapSearch', ($timeout) ->
map.controls[google.maps.ControlPosition.TOP_LEFT].push input
return new google.maps.places.SearchBox(input)
scope.respondToSearch = (map, searchBox) ->
google.maps.event.addListener searchBox, "places_changed", ->
places = searchBox.getPlaces()
for place in places when place.geometry.viewport?
map.fitBounds place.geometry.viewport
scope.bindSearchResponse = (map, searchBox) ->
google.maps.event.addListener searchBox, "places_changed", =>
scope.showSearchResult map, searchBox
scope.showSearchResult = (map, searchBox) ->
places = searchBox.getPlaces()
for place in places when place.geometry.viewport?
map.fitBounds place.geometry.viewport
scope.$apply ->
model.$setViewValue elem.val()
# Bias the SearchBox results towards places that are within the bounds of the
# current map's viewport.