From c1e3eec48a3e3d8f466c356c2a6ee4210e7e6d74 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 13 Nov 2020 20:18:18 +0000 Subject: [PATCH] --- ayanova/src/api/gzutil.js | 85 +++++++++++++++--------- ayanova/src/views/cust-customer.vue | 1 - ayanova/src/views/home-user-settings.vue | 2 +- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index 071b0de1..239e16a4 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -540,11 +540,8 @@ export default { // // viewGeoLocation: function(obj) { - //TODO: url escape parameters!! - //TODO: query by address /* -{ - pointname: m.vm.obj.name, +{ latitude: m.vm.obj.latitude, longitude: m.vm.obj.longitude, address: m.vm.obj.address || m.vm.obj.postAddress, @@ -570,46 +567,68 @@ export default { let mapUrl = window.$gz.store.state.userOptions.mapUrlTemplate; + //No pre-set? + if (!mapUrl || mapUrl == "") { + mapUrl = + "https://www.google.com/maps/search/?api=1&query={ayaddress}<|>https://www.google.com/maps/search/?api=1&query={aylatitude},{aylongitude}"; + } + let geoMapUrl = null; let addressMapUrl = null; - if (!mapUrl || mapUrl == "") { - //no preset map url, default to google, favor geo coordinates - if (obj.latitude && obj.longitude) { - geoMapUrl = - "https://www.google.com/maps/search/?api=1&query={aylatitude},{aylongitude}"; - } else { - //default to address search - addressMapUrl = - "https://www.google.com/maps/search/?api=1&query={ayaddress}"; - } - } else { - //we have a pre-set map url, parse it and split it and extract them - //favor first one if multiple supported map types - mapUrls = [mapUrl]; - if (mapUrl.includes("<|>")) { - mapUrls = mapUrl.split("<|>"); - } - - mapUrls.array.forEach(z => { - if (!geoMapUrl && z.includes("{aylatitude}")) { - geoMapUrl = z; - } - if (!addressMapUrl && z.includes("{ayaddress}")) { - addressMapUrl = z; - } - }); + //Parse the map url + let mapUrls = [mapUrl]; + if (mapUrl.includes("<|>")) { + mapUrls = mapUrl.split("<|>"); } + mapUrls.forEach(z => { + if (!geoMapUrl && z.includes("{aylatitude}")) { + geoMapUrl = z; + } + if (!addressMapUrl && z.includes("{ayaddress}")) { + addressMapUrl = z; + } + }); + //decide which map to use here, favor geocode if (hasGeo && geoMapUrl) { //geo view + mapUrl = geoMapUrl; mapUrl = mapUrl.split("{aylatitude}").join(obj.latitude); mapUrl = mapUrl.split("{aylongitude}").join(obj.longitude); - if (obj.pointname) { - mapUrl = mapUrl.split("{aypointname}").join(obj.pointname); - } } else if (hasAddress && addressMapUrl) { + mapUrl = addressMapUrl; + //compile address fields together + //order street to country seems to be standard + //note, if google need plus symbol delimiter, if bing, need comma delimiter + //but both might accept one big string space delimited and url encoded so test that on all first + let delimiter = " "; + let q = ""; + if (obj.address) { + q += obj.address + delimiter; + } + if (obj.city) { + q += obj.city + delimiter; + } + + if (obj.region) { + q += obj.region + delimiter; + } + + if (obj.country) { + q += obj.country + delimiter; + } + + if (obj.postCode) { + q += obj.postCode + delimiter; + } + if (q.length > 1) { + q = q.substring(0, q.length - 1); + } + //url encode the query + q = encodeURIComponent(q); + mapUrl = mapUrl.split("{ayaddress}").join(q); } else { throw new Error( "View map: error - no matching mapurl / address / geo coordinates set for display, nothing to view" diff --git a/ayanova/src/views/cust-customer.vue b/ayanova/src/views/cust-customer.vue index f46e1510..ea26a202 100644 --- a/ayanova/src/views/cust-customer.vue +++ b/ayanova/src/views/cust-customer.vue @@ -935,7 +935,6 @@ async function clickHandler(menuItem) { break; case "geoview": window.$gz.util.viewGeoLocation({ - pointname: m.vm.obj.name, latitude: m.vm.obj.latitude, longitude: m.vm.obj.longitude, address: m.vm.obj.address || m.vm.obj.postAddress, diff --git a/ayanova/src/views/home-user-settings.vue b/ayanova/src/views/home-user-settings.vue index 9ca9ed76..8ceffe98 100644 --- a/ayanova/src/views/home-user-settings.vue +++ b/ayanova/src/views/home-user-settings.vue @@ -177,7 +177,7 @@ export default { { name: "Bing", value: - "https://bing.com/maps/default.aspx?where1={ayaddress}<|>https://bing.com/maps/default.aspx?cp={aylatitude}~{aylongitude}&lvl=17&style=r&sp=point.{aylatitude}_{aylongitude}_{aypointname}" + "https://bing.com/maps/default.aspx?where1={ayaddress}<|>https://bing.com/maps/default.aspx?cp={aylatitude}~{aylongitude}&lvl=17&style=r&sp=point.{aylatitude}_{aylongitude}" }, { name: "Google",