I'm trying to implement the typings (typings.d.ts) on a Leaflet Plugin. The aim is to make the plugin available on my Angular TypeScript project.
I understand the logic of typings but I don't succeed to implement it, my TSLinter continue to generate errors.
The plugin is working properly but the TS Errors as annoying.
- Property 'movingMarker' does not exist on type 'typeof Marker'.
- Property 'addStation' does not exist on type 'Marker'.
https://github.com/ewoken/Leaflet.MovingMarker
My code block that is using the library :
import 'src/assets/js/leaflet-movingMarker';
...
this.messageIcon = create_icon('message', 40, '#f5af19', 'This is a message');
this.messageMarker = L.Marker.movingMarker([ // << error : Property 'movingMarker' does not exist on type 'typeof Marker'.
L.latLng([this.a.Lat, this.a.Lng]),
L.latLng([this.b.Lat, this.b.Lng])
1000 * 2,
);
this.messageMarker.addStation(1, 1000); // << error : Property 'addStation' does not exist on type 'Marker<any>'.
this.messageMarker.addStation(2, 1000); // error
this.messageMarker.start(); // error
this.messageMarker.options.icon = this.messageIcon;
My typings.d.ts file :
import * as L from 'leaflet';
declare module 'leaflet' {
interface MarkerOptions {
autostart?: boolean;
loop?: boolean;
}
interface Marker {
movingMarker(latlngs: L.LatLng[], durations: Number[], options?: Object): Marker;
addStation(pointIndex: number, duration: number): this;
start(): this;
isRunning(): this;
isEnded(): this;
isStarted(): this;
isPaused(): this;
resume(): this;
}
}
I think, it is this plugin's part which is the most problematic :
L.Marker.movingMarker = function (latlngs, duration, options) {
return new L.Marker.MovingMarker(latlngs, duration, options);
};