1

我想在 mapbox/mapbox-gl-draw https://github.com/mapbox/mapbox-gl-draw/blob/main/src/modes/draw_line_string.js的 DrawLineString 方法中添加一些自定义功能

我可以使用 Draw.constructor.modes.draw_line_string.toDisplayFeatures 访问此功能

  var Draw = new MapboxDraw({
        controls: {
            // point, line_string: true, polygon, trash, combine_features and uncombine_features
            line_string: true,
            trash: true
        },
        displayControlsDefault: false
    });

    console.log('f',Draw.constructor.modes.draw_line_string.toDisplayFeatures);

有没有什么简单的方法可以在不修改源文件的情况下用我的代码更新这个函数?谢谢

UPD:当我尝试使用这种方法时,我得到了createVertex is undefined,即使我将此函数复制到 main.js 绘图工具的功能也被破坏了

 MapboxDraw.modes.draw_line_string.toDisplayFeatures = function (state, geojson, display) {
        const isActiveLine = geojson.properties.id === state.line.id;
        geojson.properties.active = (isActiveLine) ? true : false;
        if (!isActiveLine) return display(geojson);
        // Only render the line if it has at least one real coordinate
        if (geojson.geometry.coordinates.length < 2) return;
        geojson.properties.meta = 'feature';
        display(createVertex(
            state.line.id,
            geojson.geometry.coordinates[state.direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1],
            `${state.direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1}`,
            false
        ));
        display(geojson);
        //console.log('geojson', geojson);
    };
4

0 回答 0