New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript #2
Comments
Hi, First I wrote a little declaration file for the plugin: import 'leaflet';
declare module 'leaflet' {
export class MarkersCanvas extends Layer {
addTo(map:Map|LayerGroup):this;
addMarker(marker:Marker):void;
addMarkers(markers:Array<Marker>):void;
getBounds():LatLngBounds;
redraw():void;
clear():void;
removeMarker(marker:Marker):void;
}
function markersCanvas(): MarkersCanvas;
} If you haven't created a local @types directory before you need to add it to your tsconfig.json: {
"compilerOptions": {
......
"typeRoots": [ "./projectpath/@types", "./node_modules/@types"]
},
.....
"exclude": [ "./projectpath/@types", "./node_modules/@types"]
} Now, in your main source code, you can "import" the plugin like so (half pseudo code): import * as L from "leaflet";
require("../libs/canvas-element-layer");
class NewMap {
private _map: L.Map;
private _markersCanvas: L.MarkersCanvas;
constructor(map: L.Map) {
this._map = map;
this._markersCanvas = new L.MarkersCanvas();
// you can also use: this._markersCanvas = L.markersCanvas();
this._markersCanvas.addTo(this._map);
}
} I hope this helps :-) |
Another thing you can do is: And then: import MarkersCanvas from 'path/where/is/the/library/leaflet-markers-canvas.js)';
var markersCanvas = new MarkersCanvas();
markersCanvas.addTo(map);
//Create your marker
var marker = L.marker(
[58.5578 + Math.random() * 1.8, 29.0087 + Math.random() * 3.6],
{ icon }
);
//Add your marker to the MarkersCanvas
markersCanvas.addMarker(marker) |
not entirely sure how to use this in typescript when importing stuff from leaflet like this
i tried:
would be good to make this properly for typescript
you can ofc do this, but this is like a giant mess
and even in that case im getting:
The text was updated successfully, but these errors were encountered: