Fixed Icon type hierarchy

This commit is contained in:
Alejandro Sánchez 2017-02-17 08:24:43 -06:00
parent 3177c01620
commit 9b14df292e
2 changed files with 30 additions and 12 deletions

35
leaflet/index.d.ts vendored
View File

@ -1405,8 +1405,8 @@ declare namespace L {
*/
export function map(element: string | HTMLElement, options?: MapOptions): Map;
export interface IconOptions extends LayerOptions {
iconUrl: string;
interface BaseIconOptions extends LayerOptions {
iconUrl?: string;
iconRetinaUrl?: string;
iconSize?: PointExpression;
iconAnchor?: PointExpression;
@ -1418,25 +1418,38 @@ declare namespace L {
className?: string;
}
class InternalIcon extends Layer {
constructor(options: IconOptions);
createIcon(oldIcon?: HTMLElement): HTMLElement;
export interface IconOptions extends BaseIconOptions {
iconUrl: string;
}
export class Icon extends InternalIcon {
// This class does not exist in reality, it's just a way to provide
// options of more specific types in the sub classes
class BaseIcon extends Layer {
createIcon(oldIcon?: HTMLElement): HTMLElement;
createShadow(oldIcon?: HTMLElement): HTMLElement;
options: BaseIconOptions;
}
export class Icon extends BaseIcon {
constructor(options: IconOptions);
options: IconOptions;
}
export namespace Icon {
export class Default extends InternalIcon {
imagePath: string;
export interface DefaultIconOptions extends BaseIconOptions {
imagePath?: string;
}
export class Default extends BaseIcon {
static imagePath?: string;
constructor(options?: DefaultIconOptions);
options: DefaultIconOptions;
}
}
export function icon(options: IconOptions): Icon;
export interface DivIconOptions extends LayerOptions {
export interface DivIconOptions extends BaseIconOptions {
html?: string;
bgPos?: PointExpression;
iconSize?: PointExpression;
@ -1445,7 +1458,7 @@ declare namespace L {
className?: string;
}
export class DivIcon extends InternalIcon {
export class DivIcon extends BaseIcon {
constructor(options?: DivIconOptions);
options: DivIconOptions;
}
@ -1463,8 +1476,6 @@ declare namespace L {
opacity?: number;
riseOnHover?: boolean;
riseOffset?: number;
options?: DivIconOptions;
}
export class Marker extends Layer {

View File

@ -404,22 +404,29 @@ class MyMarker extends L.Marker {
super([12, 13]);
}
}
class MyLayer extends L.Layer {
constructor() {
super();
}
}
class MyIcon extends L.Icon {
constructor() {
super({iconUrl: 'icon.png'});
}
}
class MyDivIcon extends L.DivIcon {
constructor() {
super();
}
}
const divIcon = L.divIcon({html: ''});
let defaultIcon = new L.Icon.Default();
defaultIcon = new L.Icon.Default({imagePath: 'apath'});
let myControlClass = L.Control.extend({});
let myControl = new myControlClass();