Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Typescript example? #34

Open
SidMorad opened this issue Jul 25, 2017 · 3 comments
Open

Typescript example? #34

SidMorad opened this issue Jul 25, 2017 · 3 comments

Comments

@SidMorad
Copy link

SidMorad commented Jul 25, 2017

I am trying to config this plugin in my Ionic project. I see following error:

Error: Uncaught (in promise): ReferenceError: PouchDB is not defined

My PouchDB configuration is based on this demo: nolanlawson/pouchdb-ionic-2-typescript-demo which is quite simple.

So I did import PouchDb in my page like this:
import PouchDB from 'pouchdb';

then I have leaflet and other plugin imports:

import 'leaflet';
import 'leaflet-routing-machine';
import 'leaflet-overpass-layer';
import 'leaflet-control-geocoder';

followed by this plugin import:
import 'leaflet.tilelayer.pouchdbcached';

and finally tile layer initialisation:

    let tileLayer = L.tileLayer(TILE_API_BASE_URL + '/{z}/{x}/{y}.png', {
      maxZoom: 18,
      useCache: true
    }).addTo(this.map);

Does anyone here did use this plugin in a Typescript project? I will appreciate any hint for this in advance. thanks.

@SidMorad
Copy link
Author

I manually add import PouchDB from 'pouchdb'; as first line to node_modules/leaflet.tilelayer.pouchdbcached/L.TileLayer.PouchDBCached.js and above error solved, and things are working as expected.

So until you guys fix this properly, we can use above as workaround. thanks.

@filipkroca
Copy link

I added
import PouchDB from 'pouchdb'; window.PouchDB = PouchDB;

inside my file with map container.

@dolansete
Copy link

I use Angular with Ionic and I had to add:
import PouchDB from 'pouchdb'; (window as any).PouchDB = PouchDB;
To the file with the map container, and:
(window as any).global = window;
to polyfills.ts

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants