Skip to content

Commit

Permalink
Pwa (#641)
Browse files Browse the repository at this point in the history
* wip

* docs(properties): add maxLayerZoomExtent property to map (#633)

* doc layerExtent

* doc layerExtent

* chore(polyfills): Error catching by textdecoder() was undefined on IE (#638)

* chore(polyfills): Error catching by textdecoder() was undefined on IE

* lint

* wip

* wip

Co-authored-by: Maxime Lamer <[email protected]>
  • Loading branch information
pelord and LAMM26 authored Jun 14, 2021
1 parent f84b944 commit 8617d26
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
10 changes: 9 additions & 1 deletion docs/properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Exemples
"center": [-73, 50.5],
"zoom": 6,
"geolocate": false,
"maxZoomOnExtent":15
"maxZoomOnExtent":15,
"maxLayerZoomExtent": [-10000000, 5000000, 6000000, 9500000]
}
}
}
Expand Down Expand Up @@ -83,6 +84,13 @@ Propriétés de l'objet "view" de map
- Number
- Indique le niveau de zoom qu'aura l'application lors d'un clic sur un résultat de recherche qui n'est pas une couche.
-
* - maxLayerZoomExtent
- Array []
- .. line-block::
Indique l'étendue maximale considérée comme étant valide pour un cadrage
lors du calcul de l'étendue d'une ou plusieurs couches. Les coordonnées
minimales et maximales doivent être compatibles avec la projection donnée.
-
-


Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 4201 --proxy-config proxy.conf.json",
"start-pwa": "ng build --prod && http-server -p 4201 -c-1 dist/igo2",
"build": "ng build",
"lint": "ng lint",
"e2e": "ng e2e --port 4300",
Expand Down Expand Up @@ -65,6 +66,7 @@
"bowser": "^2.9.0",
"classlist.js": "^1.1.20150312",
"core-js": "^3.6.5",
"fast-text-encoding": "^1.0.3",
"file-saver": "^2.0.2",
"hammerjs": "^2.0.8",
"html2canvas": "^1.0.0-rc.5",
Expand Down
11 changes: 11 additions & 0 deletions src/app/pages/portal/portal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ export class PortalComponent implements OnInit, OnDestroy {
});
this.map.ol.once('rendercomplete', () => {
this.readQueryParams();
if (this.storageService.get('pwaInstalled') === 'accepted') {
this.messageService.info('Ouvrir l\'app dans le bouton a droite de l\'url', 'Application déja installée')
}

// event non reconnu ni declanche...
// window.addEventListener('appinstalled', () => {
// Hide the app-provided install promotion
// Clear the deferredPrompt so it can be garbage collected
// Optionally, send analytics event to indicate successful install
// console.log('PWA was installed');
// });
});

this.onSettingsChange$.subscribe(() => {
Expand Down
15 changes: 11 additions & 4 deletions src/app/services/pwa.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Injectable } from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { once } from 'process';
import { AnalyticsService, StorageScope, StorageService } from '@igo2/core';

@Injectable({
providedIn: 'root'
})
export class PwaService {
promptEvent: any;
constructor(
private platform: Platform
private platform: Platform,
private analyticsService: AnalyticsService,
private storageService: StorageService
) { }

public initPwaPrompt() {

public async initPwaPrompt() {
if (!this.platform.IOS) {
window.addEventListener('beforeinstallprompt', (event: any) => {
event.preventDefault();
Expand All @@ -25,7 +28,11 @@ export class PwaService {
window.addEventListener('click', () => { this.showPrompt(); }, { once: true });
}

private showPrompt() {
private async showPrompt() {
this.promptEvent.prompt();
const outcome = await this.promptEvent.userChoice;
this.analyticsService.trackEvent('app', 'installPwa', outcome.outcome);
this.storageService.set('pwaInstalled', outcome.outcome, StorageScope.LOCAL)
this.promptEvent = undefined;
}
}
3 changes: 3 additions & 0 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import 'core-js/es/array/flat-map';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.

/** IE do not support TextDecoder() */
import 'fast-text-encoding';

/** IE10 and IE11 requires the following for string normalization */
import 'unorm/lib/unorm.js';

Expand Down

0 comments on commit 8617d26

Please sign in to comment.