diff --git a/app/assets/javascripts/darkswarm/directives/map_search.js.coffee b/app/assets/javascripts/darkswarm/directives/map_search.js.coffee new file mode 100644 index 0000000000..ff204d5acc --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/map_search.js.coffee @@ -0,0 +1,31 @@ +Darkswarm.directive 'mapSearch', ($timeout)-> + # Install a basic search field in a map + restrict: 'E' + require: '^googleMap' + replace: true + template: '' + link: (scope, elem, attrs, ctrl)-> + $timeout => + map = ctrl.getMap() + input = (document.getElementById("pac-input")) + map.controls[google.maps.ControlPosition.TOP_LEFT].push input + searchBox = new google.maps.places.SearchBox((input)) + + google.maps.event.addListener searchBox, "places_changed", -> + places = searchBox.getPlaces() + return if places.length is 0 + # For each place, get the icon, place name, and location. + markers = [] + bounds = new google.maps.LatLngBounds() + for place in places + bounds.extend place.geometry.location + #map.setCenter place.geometry.location + map.panToBounds place.geometry.viewport + #map.fitBounds bounds + + # Bias the SearchBox results towards places that are within the bounds of the + # current map's viewport. + google.maps.event.addListener map, "bounds_changed", -> + bounds = map.getBounds() + searchBox.setBounds bounds + diff --git a/app/assets/stylesheets/darkswarm/map.css.sass b/app/assets/stylesheets/darkswarm/map.css.sass index a8028c24d1..2050cf5063 100644 --- a/app/assets/stylesheets/darkswarm/map.css.sass +++ b/app/assets/stylesheets/darkswarm/map.css.sass @@ -10,3 +10,7 @@ img // https://github.com/zurb/foundation/issues/112 max-width: none height: auto + + #pac-input + padding: 4px + font-size: 2em diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index f831d93d17..595704709c 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -11,7 +11,7 @@ %link{href: "https://fonts.googleapis.com/css?family=Open+Sans:400,700", rel: "stylesheet", type: "text/css"}/ = yield :scripts - %script{src: "//maps.googleapis.com/maps/api/js?sensor=false"} + %script{src: "//maps.googleapis.com/maps/api/js?libraries=places&sensor=false"} = stylesheet_link_tag "darkswarm/all" = javascript_include_tag "darkswarm/all" diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml index e7f6006ae4..ce4052be57 100644 --- a/app/views/map/index.html.haml +++ b/app/views/map/index.html.haml @@ -3,5 +3,6 @@ .map-container{"fill-vertical" => true} %map{"ng-controller" => "MapCtrl"} %google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"} + %map-search %markers{models: "OfnMap.enterprises", fit: "true", coords: "'self'", icon: "'icon'", click: "'reveal'"} diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index a2fbf23873..44ebb3cfd3 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -56,6 +56,7 @@ describe ProductDistribution do adjustment.label.should == "Product distribution by #{distributor.name} for Pear" adjustment.amount.should == 1.23 + # TODO ROB this has an intermittent failure # And it should have some associated metadata md = adjustment.metadata md.enterprise.should == distributor