From 39db0554e6d1f280c4907f8d74444cac17f8d79a Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 2 Dec 2016 09:24:36 +1300 Subject: [PATCH 1/2] Add missing L.ImageOverlay methods and missing L.Draggable class --- leaflet/index.d.ts | 40 ++++++++++++++++++++++++++++++++-------- leaflet/leaflet-tests.ts | 6 ++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index 1adf9f0b0b..b045ed3fc2 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -33,13 +33,13 @@ declare namespace L { static testProp(props: String[]): String|boolean/*=false*/; static setTransform(el: HTMLElement, offset: Point, scale?: Number):void; static setPosition(el: HTMLElement, position: Point):void; - static getPosition(el: HTMLElement): Point - static disableTextSelection(): void - static enableTextSelection(): void - static disableImageDrag(): void - static enableImageDrag(): void - static preventOutline(el: HTMLElement): void - static restoreOutline(): void + static getPosition(el: HTMLElement): Point; + static disableTextSelection(): void; + static enableTextSelection(): void; + static disableImageDrag(): void; + static enableImageDrag(): void; + static preventOutline(el: HTMLElement): void; + static restoreOutline(): void; } export interface CRS { @@ -247,7 +247,7 @@ declare namespace L { * with an object (e.g. the user clicks on the map, causing the map to fire * 'click' event). */ - export interface Evented extends Class { + export abstract class Evented extends Class { /** * Adds a listener function (fn) to a particular event type of the object. * You can optionally specify the context of the listener (object the this @@ -383,6 +383,21 @@ declare namespace L { hasEventListeners(type: string): boolean; } + /** + * A class for making DOM elements draggable (including touch support). + * Used internally for map and marker dragging. Only works for elements + * that were positioned with [`L.DomUtil.setPosition`](#domutil-setposition). + */ + export class Draggable extends Evented { + constructor(element: HTMLElement, dragStartTarget?: HTMLElement, preventOutline?: boolean); + + enable(): void; + + disable(): void; + + finishDrag(): void; + } + interface LayerOptions { pane?: string; } @@ -523,6 +538,15 @@ declare namespace L { bringToFront(): this; bringToBack(): this; setUrl(url: string): this; + + /** Update the bounds that this ImageOverlay covers */ + setBounds(bounds: LatLngBounds): this; + + /** Get the bounds that this ImageOverlay covers */ + getBounds(): LatLngBounds; + + /** Get the img element that represents the ImageOverlay on the map */ + getElement(): HTMLImageElement; } export function imageOverlay(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions): ImageOverlay; diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index 34a5fa245f..2c43b4f9d6 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -326,3 +326,9 @@ map = map .remove() .whenReady(() => {}) .whenReady(() => {}, {}); + +var elementToDrag = document.createElement('div'); +var draggable = new L.Draggable(elementToDrag); +draggable.enable(); +draggable.disable(); +draggable.on('drag', () => {}); \ No newline at end of file From 9de51dd2165bdcb0a7c669040edb96f1e367284e Mon Sep 17 00:00:00 2001 From: danzel Date: Sun, 4 Dec 2016 17:10:15 +1300 Subject: [PATCH 2/2] Fix based on feedback --- leaflet/index.d.ts | 4 ++-- leaflet/leaflet-tests.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index b045ed3fc2..83e94b9d4d 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -545,8 +545,8 @@ declare namespace L { /** Get the bounds that this ImageOverlay covers */ getBounds(): LatLngBounds; - /** Get the img element that represents the ImageOverlay on the map */ - getElement(): HTMLImageElement; + /** Get the img element that represents the ImageOverlay on the map */ + getElement(): HTMLImageElement; } export function imageOverlay(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions): ImageOverlay; diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index 2c43b4f9d6..47776a75ac 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -327,8 +327,8 @@ map = map .whenReady(() => {}) .whenReady(() => {}, {}); -var elementToDrag = document.createElement('div'); -var draggable = new L.Draggable(elementToDrag); +let elementToDrag = document.createElement('div'); +let draggable = new L.Draggable(elementToDrag); draggable.enable(); draggable.disable(); draggable.on('drag', () => {}); \ No newline at end of file