传单扩展 GeoJSON 组件给出问题

时间:2021-05-13 10:27:26

标签: reactjs typescript leaflet react-leaflet

我将从传单扩展 GeoJSON 组件以创建一个自定义组件我使用传单 1.6.0 和打字稿并按照传单文档(https://leafletjs.com/reference-1.6.0.html#class)给出的步骤但在创建新组件时遇到问题自定义组件对象“预期 0 个参数,但得到 1.ts(2554)”。我的自定义组件实现如下。

import React, { useContext } from 'react';
import { useLeaflet, GeoJSON } from "react-leaflet";
import L from 'leaflet';
import uuid from "react-uuid";

import { BoundaryMarkContext } from '../MapsPage';
import { getStyle} from '../../style';

type Props = {
    featureCollection: any;
};

const CustomGeoJson = (props: Props) => {
    var keyForFeatureCollection = uuid();
    const boundaryMarkChangeDetails = useContext(BoundaryMarkContext);

    const onEachFeature = (feature, layer) => {
        layer.on('click', function (e) {
            boundaryMarkChangeDetails.handleBoundaryMarkClick(e)
        });
    }

    const boundaryMarkPointToLayer = (feature, latlng) => {

      };

    const GeoJsonExtend =  L.GeoJSON.extend({
        options: {
            onEachFeature: onEachFeature,
            pointToLayer: boundaryMarkPointToLayer,
            style: getStyle
        },

        initialize: function(data, key) {
            this.data = data;
            this.key = key;
        }
    });

    return new GeoJsonExtend({ data: props.featureCollection, key: keyForFeatureCollection });
    
};

export default CustomGeoJson;

0 个答案:

没有答案