From 86963a291392cf3c9d475868af606f118453f768 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Jun 2019 08:49:54 +0000 Subject: [PATCH] Add geocoding to map. #221 --- templates/job-order/bingmaps.js.twig | 43 +++++++++++++++++----------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/templates/job-order/bingmaps.js.twig b/templates/job-order/bingmaps.js.twig index 0630e96e..ec1cad7f 100644 --- a/templates/job-order/bingmaps.js.twig +++ b/templates/job-order/bingmaps.js.twig @@ -10,7 +10,8 @@ function GetMap() { map = new Microsoft.Maps.Map('#m_gmap', { center: new Microsoft.Maps.Location(14.6091, 121.0223), - culture: 'fil-Latn' + culture: 'fil-Latn', + zoom: 13 }); Microsoft.Maps.Events.addHandler(map, 'click', selectPoint); @@ -30,29 +31,22 @@ function GetMap() }); map.entities.push(pin); - map.setCenter(location); + map.setView({ + center: location + }); // set value in hidden input $('#map_lat').val(locTemp.latitude); $('#map_lng').val(locTemp.longitude); } - - map.setCenter(lat, lng); - - // set value in hidden input - $('#map_lat').val(lat); - $('#map_lng').val(lng); } -} - -$(function() { function geocodeQuery(query) { var searchRequest = { where: query, callback: function (r) { // clear map - map.entities.remove(pin); + map.entities.clear(); // Add the first result if (r && r.results && r.results.length > 0) { pin = new Microsoft.Maps.Pushpin(r.results[0].location, { @@ -60,19 +54,26 @@ $(function() { icon: '/assets/images/icon-destination.png' }); map.entities.push(pin); - map.setCenter(location); - + map.setView({ + center: location + }); // set value in hidden input $('#map_lat').val(locTemp.latitude); $('#map_lng').val(locTemp.longitude); } + else { + alert('wala'); + } }, errorCallback: function (e) { alert("No results found"); } }; + alert(query); + searchManager.geocode(searchRequest); } + var handleAction = function() { var text = $.trim($('#m_gmap_address').val()); if (!searchManager) { @@ -81,6 +82,9 @@ $(function() { searchManager = new Microsoft.Maps.Search.SearchManager(map); geocodeQuery(encodeURIComponent(text)); }); + } else { + map.entities.clear(); + geocodeQuery(encodeURIComponent(text)); } } @@ -97,6 +101,11 @@ $(function() { } }); +} + +$(function() { + + {% if ftags.set_map_coordinate %} // check if we need to set map var location = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }}); @@ -109,7 +118,9 @@ $(function() { }); map.entities.push(pin); - map.setCenter(location); + map.setView({ + center: location + }); // set value in hidden input $('#map_lat').val(locTemp.latitude); @@ -124,7 +135,7 @@ $(function() { var hmap = new Microsoft.Maps.Map('#hub_map', { center: new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }}), - culture: 'fil-Latn'; + culture: 'fil-Latn' }; var dest = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }},