|
| 1 | +import * as L from "leaflet"; |
| 2 | +import * as PIXI from "pixi.js"; |
| 3 | + |
| 4 | +declare module "leaflet" { |
| 5 | + interface PixiOverlayOptions { |
| 6 | + /** |
| 7 | + * How much to extend the clip area around the map view (relative to its size) |
| 8 | + * e.g. 0.1 would be 10% of map view in each direction |
| 9 | + * @default 0.1 |
| 10 | + */ |
| 11 | + padding?: number; |
| 12 | + /** |
| 13 | + * Force use of a 2d-canvas |
| 14 | + * @default false |
| 15 | + */ |
| 16 | + forceCanvas?: boolean; |
| 17 | + /** |
| 18 | + * Help to prevent flicker when refreshing display on some devices (e.g. iOS devices) |
| 19 | + * It is ignored if rendering is done with 2d-canvas |
| 20 | + * @default false |
| 21 | + */ |
| 22 | + doubleBuffering?: boolean; |
| 23 | + /** |
| 24 | + * Resolution of the renderer canvas |
| 25 | + * @default L.Browser.retina ? 2 : 1 |
| 26 | + */ |
| 27 | + resolution?: number; |
| 28 | + /** |
| 29 | + * Return the layer projection zoom level |
| 30 | + * @default projectionZoom |
| 31 | + */ |
| 32 | + projectionZoom?: (map: L.Map) => number; |
| 33 | + /** |
| 34 | + * Destroy PIXI EventSystem |
| 35 | + * @default false |
| 36 | + */ |
| 37 | + destroyInteractionManager?: boolean; |
| 38 | + /** |
| 39 | + * Customize PIXI EventSystem autoPreventDefault property |
| 40 | + * This option is ignored if destroyInteractionManager is set |
| 41 | + * @default true |
| 42 | + */ |
| 43 | + autoPreventDefault?: boolean; |
| 44 | + /** |
| 45 | + * Enables drawing buffer preservation |
| 46 | + * @default false |
| 47 | + */ |
| 48 | + preserveDrawingBuffer?: boolean; |
| 49 | + /** |
| 50 | + * Clear the canvas before the new render pass |
| 51 | + * @default true |
| 52 | + */ |
| 53 | + clearBeforeRender?: boolean; |
| 54 | + /** |
| 55 | + * Filter move events that should trigger a layer redraw |
| 56 | + * @default () => false |
| 57 | + */ |
| 58 | + shouldRedrawOnMove?: (e: L.LeafletEvent) => boolean; |
| 59 | + /** |
| 60 | + * The pane where the overlay will be added |
| 61 | + * @default 'overlayPane' |
| 62 | + */ |
| 63 | + pane?: string; |
| 64 | + } |
| 65 | + |
| 66 | + type LatLngToLayerPointFn = (latLng: L.LatLngExpression, zoom?: number) => L.Point; |
| 67 | + type LayerPointToLatLngFn = (point: L.PointExpression, zoom?: number) => L.LatLng; |
| 68 | + |
| 69 | + interface PixiOverlayUtils { |
| 70 | + /** |
| 71 | + * Convert a LatLng to layer point |
| 72 | + * @param latLng The geographical point to convert |
| 73 | + * @param zoom Optional zoom level (defaults to initial zoom) |
| 74 | + */ |
| 75 | + latLngToLayerPoint: LatLngToLayerPointFn; |
| 76 | + /** |
| 77 | + * Convert a layer point to LatLng |
| 78 | + * @param point The point to convert |
| 79 | + * @param zoom Optional zoom level (defaults to initial zoom) |
| 80 | + */ |
| 81 | + layerPointToLatLng: LayerPointToLatLngFn; |
| 82 | + /** |
| 83 | + * Get the scale factor between current zoom and initial zoom |
| 84 | + * @param zoom Optional zoom level to compare with initial zoom |
| 85 | + */ |
| 86 | + getScale(zoom?: number): number; |
| 87 | + /** |
| 88 | + * Get the PIXI renderer instance |
| 89 | + */ |
| 90 | + getRenderer(): PIXI.Renderer; |
| 91 | + /** |
| 92 | + * Get the PIXI container |
| 93 | + */ |
| 94 | + getContainer(): PIXI.Container; |
| 95 | + /** |
| 96 | + * Get the Leaflet map instance |
| 97 | + */ |
| 98 | + getMap(): L.Map; |
| 99 | + } |
| 100 | + |
| 101 | + class PixiOverlay extends L.Layer { |
| 102 | + constructor( |
| 103 | + drawCallback: (utils: PixiOverlayUtils, event?: L.LeafletEvent) => void, |
| 104 | + pixiContainer: PIXI.Container, |
| 105 | + options?: PixiOverlayOptions, |
| 106 | + ); |
| 107 | + |
| 108 | + /** |
| 109 | + * Manually trigger a redraw of the overlay |
| 110 | + * @param data Optional data to pass to the draw callback |
| 111 | + */ |
| 112 | + redraw(data?: unknown): this; |
| 113 | + /** |
| 114 | + * Properly clean up the overlay before removing it |
| 115 | + */ |
| 116 | + destroy(): void; |
| 117 | + } |
| 118 | + |
| 119 | + function pixiOverlay( |
| 120 | + drawCallback: (utils: PixiOverlayUtils, event?: L.LeafletEvent) => void, |
| 121 | + pixiContainer: PIXI.Container, |
| 122 | + options?: PixiOverlayOptions, |
| 123 | + ): PixiOverlay; |
| 124 | +} |
0 commit comments