This commit is contained in:
2020-11-13 19:58:09 +00:00
parent 9c7e759167
commit 3029ead3b2
4 changed files with 82 additions and 14 deletions

View File

@@ -540,17 +540,82 @@ export default {
//
//
viewGeoLocation: function(obj) {
if (!obj.latitude || !obj.longitude) {
throw new Error("View map: missing latitude or longitude, can't view");
//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,
city: m.vm.obj.city || m.vm.obj.postCity,
region: m.vm.obj.region || m.vm.obj.postRegion,
country: m.vm.obj.country || m.vm.obj.postCountry,
postCode: m.vm.obj.postCode
}
*/
let hasGeo = obj.latitude || obj.longitude;
let hasAddress =
obj.address ||
obj.city ||
objectHash.region ||
obj.country ||
obj.postCode;
if (!hasGeo && !hasAddress) {
throw new Error(
"View map: missing address and latitude / longitude nothing to view"
);
}
let mapUrl =
window.$gz.store.state.userOptions.mapUrlTemplate ||
"https://www.google.com/maps/search/?api=1&query={aylatitude},{aylongitude}";
mapUrl = mapUrl.split("{aylatitude}").join(obj.latitude);
mapUrl = mapUrl.split("{aylongitude}").join(obj.longitude);
if (obj.pointname) {
mapUrl = mapUrl.split("{aypointname}").join(obj.pointname);
let mapUrl = window.$gz.store.state.userOptions.mapUrlTemplate;
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;
}
});
}
//decide which map to use here, favor geocode
if (hasGeo && geoMapUrl) {
//geo view
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) {
} else {
throw new Error(
"View map: error - no matching mapurl / address / geo coordinates set for display, nothing to view"
);
}
if (window.open(mapUrl, "map") == null) {
throw new Error(
"Problem displaying map in new window. Browser must allow pop-ups to view maps; check your browser setting"