From a8980d69d148684d6b1ea6e8106bf3647a922ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20=C5=A0ebek?= Date: Mon, 15 May 2017 16:15:40 +0200 Subject: [PATCH] feat(leaflet.awesome-markers): support both v0 and v1 leaflet --- types/leaflet.awesome-markers/index.d.ts | 25 ++----- .../leaflet.awesome-markers-tests.ts | 2 +- types/leaflet.awesome-markers/tsconfig.json | 7 +- types/leaflet.awesome-markers/v0/index.d.ts | 68 +++++++++++++++++++ .../v0/leaflet.awesome-markers-tests.ts | 18 +++++ .../leaflet.awesome-markers/v0/tsconfig.json | 31 +++++++++ 6 files changed, 123 insertions(+), 28 deletions(-) create mode 100644 types/leaflet.awesome-markers/v0/index.d.ts create mode 100644 types/leaflet.awesome-markers/v0/leaflet.awesome-markers-tests.ts create mode 100644 types/leaflet.awesome-markers/v0/tsconfig.json diff --git a/types/leaflet.awesome-markers/index.d.ts b/types/leaflet.awesome-markers/index.d.ts index 48c58b8f60..ece7b26076 100644 --- a/types/leaflet.awesome-markers/index.d.ts +++ b/types/leaflet.awesome-markers/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Leaflet.awesome-markers plugin v2.0 // Project: https://github.com/sigma-geosistemas/Leaflet.awesome-markers#properties -// Definitions by: Egor Komarov +// Definitions by: Marcel Sebek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import * as Leaflet from "leaflet"; @@ -11,27 +11,12 @@ declare global { namespace L { function icon(options: AwesomeMarkers.IconOptions): AwesomeMarkers.Icon; - interface IconStatic extends Leaflet.IconStatic { - /** - * Creates an icon instance with the given options. - */ - new (options: IconOptions): Icon; - - Default: { - /** - * Creates a default icon instance with the given options. - */ - new (options?: IconOptions): Icon.Default; - - imagePath: string; - }; - } - - interface Icon extends Leaflet.Icon { + class Icon extends Leaflet.BaseIcon { + constructor(options?: AwesomeMarkers.IconOptions); options: AwesomeMarkers.IconOptions; } - interface IconOptions extends Leaflet.IconOptions { + interface IconOptions extends Leaflet.BaseIconOptions { /** * Name of the icon. See glyphicons or font-awesome. */ @@ -62,7 +47,5 @@ declare global { namespace L { */ extraClasses?: string; } - - var Icon: AwesomeMarkers.IconStatic; } } } diff --git a/types/leaflet.awesome-markers/leaflet.awesome-markers-tests.ts b/types/leaflet.awesome-markers/leaflet.awesome-markers-tests.ts index 7fe7a82753..1183cad3f3 100644 --- a/types/leaflet.awesome-markers/leaflet.awesome-markers-tests.ts +++ b/types/leaflet.awesome-markers/leaflet.awesome-markers-tests.ts @@ -15,4 +15,4 @@ var blueMarker = new L.AwesomeMarkers.Icon({ L.marker([51.941196, 4.512291], { icon: redMarker }).addTo(map); L.marker([51.941196, 4.512291], { icon: blueMarker }).addTo(map); -L.AwesomeMarkers.Icon.prototype.options.prefix = 'ion'; \ No newline at end of file +L.AwesomeMarkers.Icon.prototype.options.prefix = 'fa'; diff --git a/types/leaflet.awesome-markers/tsconfig.json b/types/leaflet.awesome-markers/tsconfig.json index 74df02c260..d4e34220c0 100644 --- a/types/leaflet.awesome-markers/tsconfig.json +++ b/types/leaflet.awesome-markers/tsconfig.json @@ -13,11 +13,6 @@ "../" ], "types": [], - "paths": { - "leaflet": [ - "leaflet/v0" - ] - }, "noEmit": true, "forceConsistentCasingInFileNames": true }, @@ -25,4 +20,4 @@ "index.d.ts", "leaflet.awesome-markers-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/leaflet.awesome-markers/v0/index.d.ts b/types/leaflet.awesome-markers/v0/index.d.ts new file mode 100644 index 0000000000..b695d3918b --- /dev/null +++ b/types/leaflet.awesome-markers/v0/index.d.ts @@ -0,0 +1,68 @@ +// Type definitions for Leaflet.awesome-markers plugin v2.0 with Leaflet 0.x +// Project: https://github.com/sigma-geosistemas/Leaflet.awesome-markers#properties +// Definitions by: Egor Komarov , Marcel Sebek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as Leaflet from "leaflet"; + +declare global { namespace L { + module AwesomeMarkers { + var version: string; + + function icon(options: AwesomeMarkers.IconOptions): AwesomeMarkers.Icon; + + interface IconStatic extends Leaflet.IconStatic { + /** + * Creates an icon instance with the given options. + */ + new (options: IconOptions): Icon; + + Default: { + /** + * Creates a default icon instance with the given options. + */ + new (options?: IconOptions): Icon.Default; + + imagePath: string; + }; + } + + interface Icon extends Leaflet.Icon { + options: AwesomeMarkers.IconOptions; + } + + interface IconOptions extends Leaflet.IconOptions { + /** + * Name of the icon. See glyphicons or font-awesome. + */ + icon?: string; + + /** + * Select de icon library. 'fa' for font-awesome or 'glyphicon' for bootstrap 3. + */ + prefix?: 'fa' | 'glyphicon'; + + /** + * Color of the marker + */ + markerColor?: 'red' | 'darkred' | 'orange' | 'green' | 'darkgreen' | 'blue' | 'purple' | 'darkpurple' | 'cadetblue'; + + /** + * Color of the icon. 'white', 'black' or css code (hex, rgba etc). + */ + iconColor?: 'white' | 'black' | string; + + /** + * Make the icon spin. true or false. Font-awesome required + */ + spin?: boolean; + + /** + * Additional classes in the created tag + */ + extraClasses?: string; + } + + var Icon: AwesomeMarkers.IconStatic; + } +} } diff --git a/types/leaflet.awesome-markers/v0/leaflet.awesome-markers-tests.ts b/types/leaflet.awesome-markers/v0/leaflet.awesome-markers-tests.ts new file mode 100644 index 0000000000..7fe7a82753 --- /dev/null +++ b/types/leaflet.awesome-markers/v0/leaflet.awesome-markers-tests.ts @@ -0,0 +1,18 @@ + + +var map: L.Map; + +var redMarker = L.AwesomeMarkers.icon({ + icon: 'coffee', + markerColor: 'red' +}); + +var blueMarker = new L.AwesomeMarkers.Icon({ + icon: 'star', + markerColor: 'blue' +}); + +L.marker([51.941196, 4.512291], { icon: redMarker }).addTo(map); +L.marker([51.941196, 4.512291], { icon: blueMarker }).addTo(map); + +L.AwesomeMarkers.Icon.prototype.options.prefix = 'ion'; \ No newline at end of file diff --git a/types/leaflet.awesome-markers/v0/tsconfig.json b/types/leaflet.awesome-markers/v0/tsconfig.json new file mode 100644 index 0000000000..95c7b0b62f --- /dev/null +++ b/types/leaflet.awesome-markers/v0/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "paths": { + "leaflet": [ + "leaflet/v0" + ], + "leaflet.awesome-markers": [ + "leaflet.awesome-markers/v0" + ] + }, + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "leaflet.awesome-markers-tests.ts" + ] +}