gabriel-russo / Leaflet.BetterFileLayer

The definitive plugin to load your spatialized files into leaflet.
https://gabriel-russo.github.io/Leaflet.BetterFileLayer/example/
Other
18 stars 0 forks source link

Need to make this work in TypeScript for an Ionic + Angular + Leaflet application #4

Open RupertBarrow opened 3 months ago

RupertBarrow commented 3 months ago

I have a Ionic + Angular + Leaflet application written in TypeScript and would like to use BetterFileLayer in it. I am missing a .d.ts file (and and other package.json details) to make it usable in TypeScript.

Could you please provide this ?

gabriel-russo commented 3 months ago

Ok, i will work on that.

RupertBarrow commented 3 months ago

I'm actually using ngx-leaflet, to be precise : https://github.com/bluehalo/ngx-leaflet

RupertBarrow commented 3 months ago

I've tried this which is a good start for me :

import * as L from 'leaflet';

import './src/leaflet.betterfilelayer';

declare module 'leaflet' { namespace Control { interface BetterFileLoader { addTo(LMap: L.Map): BetterFileLoader; } interface BetterFileLayer { addTo(LMap: L.Map): BetterFileLoader; } function betterFileLayer(options?: BetterFileLayerOptions): BetterFileLoader; }

namespace Map { function mergeOptions(options?: BetterFileLayerMergeOptions): any; //function addInitHook(initHookFn: () => L.Control.BetterFileLayer): any; }

interface BetterFileLayerImportOptions { delimiter: string; latfield: string; lonfield: string; }

interface BetterFileLayerMergeOptions { betterFileLayerControl: boolean; }

interface BetterFileLayerOptions extends L.ControlOptions { fileSizeLimit?: number; importOptions?: BetterFileLayerImportOptions; text: { title: string; }; formats: string[];

initialize(options?: BetterFileLayerImportOptions): any;

onAdd(): HTMLElement;
onRemove(): HTMLElement;
onEachFeature(): void;

} }

- to import it into my component, I just add : 

// src/app/tab1/tab1.page.ts

import './src/leaflet.betterfilelayer';


NB : I had to change the path to icons because Angular looks for them in `assets/`, and added this : 

// src/app/leaflet-better-filelayer/src/leaflet.betterfilelayer.js

L.Icon.Default.mergeOptions({ iconUrl: "assets/marker-icon.png", shadowUrl: "assets/marker-shadow.png", iconSize: [30.8, 44.1], iconAnchor: [15.4, 44.1], popupAnchor: [0, -44], });