From 8f4c8d6c5b67f963cdb9a08a4f2286bd6d5707d0 Mon Sep 17 00:00:00 2001 From: Ryan Blace Date: Sat, 24 Dec 2016 15:25:09 -0500 Subject: [PATCH] [types/leaflet-draw] Fixes and updated to work with Leaflet 1.x and Leaflet Draw 0.4.6 (#13262) * Updating to work with Leaflet 1.x and Leaflet Draw 4.x * Removing the I in the interfaces to be consistent with Leaflet * Just updating a missing semicolon --- leaflet-draw/index.d.ts | 55 ++++++++++++++++++++---------- leaflet-draw/leaflet-draw-tests.ts | 13 +++---- leaflet-draw/package.json | 4 +-- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/leaflet-draw/index.d.ts b/leaflet-draw/index.d.ts index 269215eef1..3cced930c2 100644 --- a/leaflet-draw/index.d.ts +++ b/leaflet-draw/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for leaflet-draw 0.2.4 +// Type definitions for leaflet-draw 0.4.6 // Project: https://github.com/Leaflet/Leaflet.draw -// Definitions by: Matt Guest +// Definitions by: Matt Guest , Ryan Blace // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -10,17 +10,9 @@ declare namespace L { drawControl?: boolean; } - export interface ControlStatic { - Draw: Control.DrawStatic; - } - namespace Control { - export interface DrawStatic { - new (options?: IDrawConstructorOptions): Draw; - } - - export interface IDrawConstructorOptions { + export interface DrawConstructorOptions { /** * The initial position of the control (one of the map corners). @@ -91,7 +83,7 @@ declare namespace L { * * Default value: null */ - featureGroup: FeatureGroup; + featureGroup: FeatureGroup; /** * Edit handler options. Set to false to disable handler. @@ -108,9 +100,14 @@ declare namespace L { remove?: DrawOptions.DeleteHandlerOptions; } - export interface Draw extends IControl { - + export interface Draw extends Control { + setDrawingOptions(options: DrawOptions): void; } + + export class Draw { + constructor(options?: DrawConstructorOptions); + } + } @@ -252,6 +249,28 @@ declare namespace L { } + namespace Draw { + + namespace Event { + + export const CREATED: string; + export const EDITED: string; + export const DELETED: string; + export const DRAWSTART: string; + export const DRAWSTOP: string; + export const DRAWVERTEX: string; + export const EDITSTART: string; + export const EDITMOVE: string; + export const EDITRESIZE: string; + export const EDITVERTEX: string; + export const EDITSTOP: string; + export const DELETESTART: string; + export const DELETESTOP: string; + + } + + } + namespace DrawEvents { export interface Created { @@ -259,7 +278,7 @@ declare namespace L { /** * Layer that was just created. */ - layer: ILayer; + layer: Layer; /** * The type of layer this is. One of: polyline, polygon, rectangle, circle, marker. @@ -272,7 +291,7 @@ declare namespace L { /** * List of all layers just edited on the map. */ - layers: LayerGroup; + layers: LayerGroup; } /** @@ -283,7 +302,7 @@ declare namespace L { /** * List of all layers just removed from the map. */ - layers: LayerGroup; + layers: LayerGroup; } export interface DrawStart { @@ -302,7 +321,7 @@ declare namespace L { layerType: string; } - export interface EditStart { + export interface EditStart { /** * The type of edit this is. One of: edit */ diff --git a/leaflet-draw/leaflet-draw-tests.ts b/leaflet-draw/leaflet-draw-tests.ts index 885f576d1b..98d3681789 100644 --- a/leaflet-draw/leaflet-draw-tests.ts +++ b/leaflet-draw/leaflet-draw-tests.ts @@ -3,9 +3,9 @@ var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', osmAttrib = '© OpenStreetMap contributors', osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), - map = new L.Map('map', {layers: [osm], center: new L.LatLng(-37.7772, 175.2756), zoom: 15 }); + map = L.map('map', {layers: [osm], center: L.latLng(-37.7772, 175.2756), zoom: 15 }); -var drawnItems = new L.FeatureGroup(); +var drawnItems = L.featureGroup(); map.addLayer(drawnItems); var drawControl = new L.Control.Draw({ @@ -37,9 +37,10 @@ var drawControl = new L.Control.Draw({ }); map.addControl(drawControl); -map.on('draw:created', function (e: L.DrawEvents.Created) { - var type = e.layerType, - layer = e.layer; +map.on('draw:created', function (e: any) { + var drawEvent = (e as L.DrawEvents.Created); + var type = drawEvent.layerType, + layer = drawEvent.layer; drawnItems.addLayer(layer); -}); \ No newline at end of file +}); diff --git a/leaflet-draw/package.json b/leaflet-draw/package.json index 711ba15e43..fa93c2516c 100644 --- a/leaflet-draw/package.json +++ b/leaflet-draw/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "@types/leaflet": "^0.7" + "@types/leaflet": "^1.0" } -} \ No newline at end of file +}