我想要实现这个描述在 Render mapbox vector tiles inside react-leaflet? 的实现,但是我使用的是 TypeScript。
所以我的文件看起来像这样:
import * as L from "leaflet";
import {} from "mapbox-gl-leaflet";
import * as PropTypes from "prop-types";
import { GridLayer, withLeaflet } from "react-leaflet";
class MapBoxGLLayer extends GridLayer {
createLeafletElement(props) {
return L.mapboxGL(props);
}
}
/*
* Props are the options supported by Mapbox Map object
* Find options here:https://www.mapbox.com/mapbox-gl-js/api/#new-mapboxgl-map-options-
*/
MapBoxGLLayer.propTypes = {
accessToken: PropTypes.string.isRequired,
style: PropTypes.string
};
MapBoxGLLayer.defaultProps = {
style: "mapbox://styles/mapbox/streets-v9"
};
export default withLeaflet(MapBoxGLLayer);
但是我收到以下错误:
在'typeof import("c:/Users/.../node_modules/@types/leaflet/index")'类型上不存在属性'mapboxGL'.ts(2339)
因此leaflet没有mapboxGL的定义(这很有道理,因为mapboxGL不是它的一部分) - 但是我如何创建或引用一个mapboxGL的定义,以便我可以调用L.mapboxGL(props)?