为Leaflet TileLayer扩展Angular 2中的现有类

时间:2016-12-06 23:43:56

标签: angular typescript leaflet

我正在尝试以角度2 https://kuamoto.wordpress.com/2016/02/26/myth-1-cant-make-offline-apps/comment-page-1/#comment-17

调整本教程

我发现了这个相关的问题: Leaflet: Can't extend TileLayer with typescript 2.0 & angular 2 我不知道我是否有正确的index.d.ts文件(我在下面提供)

当我尝试扩展tileLayer时出现以下错误:Property' extend'类型&type; tileLayer'上不存在

var lyr = L.tileLayer.extend({
    mbTilesDB: null,

    initialize: function(url, options, db) {
        console.log("sql plugin: " + db);
        this.mbTilesDB = db;
    },
    getTileUrl: function(tilePoint, zoom, tile) {
        [...]
    },
    _loadTile: function(tile, tilePoint, zoom) {
        tile._layer = this;
        tile.onload = this._tileOnLoad;
        tile.onerror = this._tileOnError;
        this.getTileUrl(tilePoint, zoom, tile);
    }
});

这是我导入Leaflet的方式:

import * as L from 'leaflet';

这是与TileLayer相关的index.d.ts文件的摘录:

export interface TileLayerOptions extends GridLayerOptions {
    minZoom?: number;
    maxZoom?: number;
    maxNativeZoom?: number;
    subdomains?: string | Array<string>;
    errorTileUrl?: string;
    zoomOffset?: number;
    tms?: boolean;
    zoomReverse?: boolean;
    detectRetina?: boolean;
    crossOrigin?: boolean;
    [name: string]: any;
}

export interface TileLayer extends GridLayer {
    setUrl(url: string, noRedraw?: boolean): this;
}

export function tileLayer(urlTemplate: string, options?: TileLayerOptions): TileLayer;

export interface WMSOptions extends TileLayerOptions {
    layers: string;
    styles?: string;
    format?: string;
    transparent?: boolean;
    version?: string;
    crs?: CRS;
    uppercase?: boolean;
}

export interface WMS extends TileLayer {
    setParams(params: Object, noRedraw?: boolean): this;
}

export namespace tileLayer {
    export function wms(baseUrl: string, options: WMSOptions): WMS;
}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

根据以下错误报告https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11693中的内容,看起来扩展函数在typescript绑定中完全实现。本文推荐的方法是使用以下语法:

{{1}}

这使得项目为我编译。

相关问题