From 91890d644d5da972b6c3d787b0b86240e0aced44 Mon Sep 17 00:00:00 2001 From: Michael Ensing Date: Tue, 9 Aug 2016 04:37:18 -0400 Subject: [PATCH 1/2] Added search box to top-right corner (Requires Google Maps Places in API) --- static/map.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++ templates/map.html | 3 ++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/static/map.js b/static/map.js index f5b82a14..31416934 100644 --- a/static/map.js +++ b/static/map.js @@ -144,8 +144,57 @@ function initMap() { "json"); }); } + + initSearchBox(); }; +function initSearchBox() { + // Create the search box and link it to the UI element. + var input = document.getElementById('pac-input'); + var searchBox = new google.maps.places.SearchBox(input); + map.controls[google.maps.ControlPosition.TOP_RIGHT].push(input); + + // Bias the SearchBox results towards current map's viewport. + map.addListener('bounds_changed', function() { + searchBox.setBounds(map.getBounds()); + }); + + var markers = []; + // Listen for the event fired when the user selects a prediction and retrieve + // more details for that place. + searchBox.addListener('places_changed', function() { + var places = searchBox.getPlaces(); + + if (places.length == 0) { + return; + } + + // For each place, get the icon, name and location. + var bounds = new google.maps.LatLngBounds(); + places.forEach(function(place) { + if (!place.geometry) { + if(verbose) + console.log("Returned place contains no geometry"); + return; + } + var icon = { + url: place.icon, + size: new google.maps.Size(71, 71), + origin: new google.maps.Point(0, 0), + anchor: new google.maps.Point(17, 34), + scaledSize: new google.maps.Size(25, 25) + }; + + if (place.geometry.viewport) { + // Only geocodes have viewport. + bounds.union(place.geometry.viewport); + } else { + bounds.extend(place.geometry.location); + } + }); + map.fitBounds(bounds); + }); +} function pokemonLabel(name, id, disappear_time, latitude, longitude) { var disappear_date = new Date(disappear_time); diff --git a/templates/map.html b/templates/map.html index 7498b911..a0755cf3 100644 --- a/templates/map.html +++ b/templates/map.html @@ -258,6 +258,7 @@

Settings

+
@@ -269,6 +270,6 @@

Settings

- + From dadb41dd21f6ac7df3e59293fcf73b9ab6cba047 Mon Sep 17 00:00:00 2001 From: Michael Ensing Date: Tue, 9 Aug 2016 05:28:55 -0400 Subject: [PATCH 2/2] removed a verbose flag console out (holdover from another addition) --- static/map.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/map.js b/static/map.js index 31416934..66e9a47b 100644 --- a/static/map.js +++ b/static/map.js @@ -173,8 +173,7 @@ function initSearchBox() { var bounds = new google.maps.LatLngBounds(); places.forEach(function(place) { if (!place.geometry) { - if(verbose) - console.log("Returned place contains no geometry"); + //console.log("Returned place contains no geometry"); return; } var icon = {