MOBILE-3213 data: Fix latlong geo links

main
Dani Palou 2019-12-18 10:50:10 +01:00
parent 82c0385fe5
commit 4601df6fc4
1 changed files with 14 additions and 7 deletions

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms'; import { FormBuilder } from '@angular/forms';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Platform } from 'ionic-angular'; import { Platform } from 'ionic-angular';
import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation'; import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation';
import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component';
@ -30,8 +31,11 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
north: number; north: number;
east: number; east: number;
constructor(protected fb: FormBuilder, private platform: Platform, private geolocation: Geolocation, constructor(protected fb: FormBuilder,
private domUtils: CoreDomUtilsProvider) { protected platform: Platform,
protected geolocation: Geolocation,
protected domUtils: CoreDomUtilsProvider,
protected sanitizer: DomSanitizer) {
super(fb); super(fb);
} }
@ -58,16 +62,19 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
* @param east Degrees East. * @param east Degrees East.
* @return Link to maps depending on platform. * @return Link to maps depending on platform.
*/ */
getLatLongLink(north: number, east: number): string { getLatLongLink(north: number, east: number): SafeUrl {
if (north !== null || east !== null) { if (north !== null || east !== null) {
const northFixed = north ? north.toFixed(4) : '0.0000', const northFixed = north ? north.toFixed(4) : '0.0000';
eastFixed = east ? east.toFixed(4) : '0.0000'; const eastFixed = east ? east.toFixed(4) : '0.0000';
let url;
if (this.platform.is('ios')) { if (this.platform.is('ios')) {
return 'http://maps.apple.com/?ll=' + northFixed + ',' + eastFixed + '&near=' + northFixed + ',' + eastFixed; url = 'http://maps.apple.com/?ll=' + northFixed + ',' + eastFixed + '&near=' + northFixed + ',' + eastFixed;
} else {
url = 'geo:' + northFixed + ',' + eastFixed;
} }
return 'geo:' + northFixed + ',' + eastFixed; return this.sanitizer.bypassSecurityTrustUrl(url);
} }
} }