Merge pull request #13402 from mohsen1/patch-7

Make Marker and Icon extendable classes and options optional
This commit is contained in:
Daniel Rosenwasser
2016-12-19 00:00:35 -08:00
committed by GitHub
2 changed files with 46 additions and 11 deletions

32
leaflet/index.d.ts vendored
View File

@@ -390,7 +390,8 @@ declare namespace L {
interactive?: boolean;
}
export interface Layer extends Evented {
export class Layer extends Evented {
constructor(options?: LayerOptions);
addTo(map: Map): this;
remove(): this;
removeFrom(map: Map): this;
@@ -502,7 +503,7 @@ declare namespace L {
}
export namespace tileLayer {
export function wms(baseUrl: string, options: WMSOptions): WMS;
export function wms(baseUrl: string, options?: WMSOptions): WMS;
}
export interface ImageOverlayOptions extends LayerOptions {
@@ -1247,12 +1248,12 @@ declare namespace L {
// Methods for modifying map state
setView(center: LatLngExpression, zoom: number, options?: ZoomPanOptions): this;
setZoom(zoom: number, options: ZoomPanOptions): this;
setZoom(zoom: number, options?: ZoomPanOptions): this;
zoomIn(delta?: number, options?: ZoomOptions): this;
zoomOut(delta?: number, options?: ZoomOptions): this;
setZoomAround(latlng: LatLngExpression, zoom: number, options: ZoomOptions): this;
setZoomAround(offset: Point, zoom: number, options: ZoomOptions): this;
fitBounds(bounds: LatLngBoundsExpression, options: FitBoundsOptions): this;
setZoomAround(latlng: LatLngExpression, zoom: number, options?: ZoomOptions): this;
setZoomAround(offset: Point, zoom: number, options?: ZoomOptions): this;
fitBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions): this;
fitWorld(options?: FitBoundsOptions): this;
panTo(latlng: LatLngExpression, options?: PanOptions): this;
panBy(offset: PointExpression): this;
@@ -1345,8 +1346,15 @@ declare namespace L {
imagePath: string;
}
export class Icon {
constructor(options: IconOptions);
}
export namespace Icon {
export const Default: IconDefault;
export class Default extends Icon {
constructor(options?: IconOptions);
imagePath: string;
}
}
export function icon(options: IconOptions): Icon;
@@ -1360,9 +1368,11 @@ declare namespace L {
className?: string;
}
export interface DivIcon extends Icon {}
export class DivIcon extends Icon {
constructor(options?: DivIconOptions);
}
export function divIcon(options: DivIconOptions): DivIcon;
export function divIcon(options?: DivIconOptions): DivIcon;
export interface MarkerOptions extends InteractiveLayerOptions {
icon?: Icon;
@@ -1376,12 +1386,14 @@ declare namespace L {
riseOffset?: number;
}
export interface Marker extends Layer {
export class Marker extends Layer {
constructor(latlng: LatLngExpression, options?: MarkerOptions);
getLatLng(): LatLng;
setLatLng(latlng: LatLngExpression): this;
setZIndexOffset(offset: number): this;
setIcon(icon: Icon): this;
setOpacity(opacity: number): this;
getElement(): Element;
// Properties
dragging: Handler;

View File

@@ -297,6 +297,7 @@ map = map
.setView(latLngLiteral, 12, zoomPanOptions)
.setView(latLngTuple, 12)
.setView(latLngTuple, 12, zoomPanOptions)
.setZoom(11)
.setZoom(12, zoomPanOptions) // investigate if zoomPanOptions are really required
.zoomIn()
.zoomIn(1)
@@ -309,6 +310,7 @@ map = map
.setZoomAround(latLngTuple, 12, zoomOptions)
.setZoomAround(point, 12, zoomOptions)
.setZoomAround(pointTuple, 11, zoomOptions)
.fitBounds(latLngBounds)
.fitBounds(latLngBounds, fitBoundsOptions) // investigate if fit bounds options are really required
.fitBounds(latLngBoundsLiteral, fitBoundsOptions)
.fitWorld()
@@ -354,4 +356,25 @@ let elementToDrag = document.createElement('div');
let draggable = new L.Draggable(elementToDrag);
draggable.enable();
draggable.disable();
draggable.on('drag', () => {});
draggable.on('drag', () => {});
class MyMarker extends L.Marker {
constructor() {
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();
}
}