您可以通过从 direct_select 模式创建自定义模式来实现:
import * as MapboxDraw from '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw';
import createSupplementaryPoints from '@mapbox/mapbox-gl-draw/src/lib/create_supplementary_points';
import Constants from '@mapbox/mapbox-gl-draw/src/constants';
const DirectSelectWithoutMiddleVertexMode = MapboxDraw.modes.direct_select;
DirectSelectWithoutMiddleVertexMode.toDisplayFeatures = function (state, geojson, push) {
if (state.featureId === geojson.properties.id) {
geojson.properties.active = Constants.activeStates.ACTIVE;
push(geojson);
createSupplementaryPoints(geojson, {
map: this.map,
midpoints: false,
selectedPaths: state.selectedCoordPaths
}).forEach(push);
} else {
geojson.properties.active = Constants.activeStates.INACTIVE;
push(geojson);
}
this.fireActionable(state);
};
export default DirectSelectWithoutMiddleVertexMode;
唯一要做的就是将midpoints
属性设置为false
避免创建中点。
之后,使用自定义模式覆盖绘图选项中的 direct_select 模式:
import DirectSelectWithoutMiddleVertexMode from './DirectSelectWithoutMiddleVertexMode';
const drawOptions = {
modes: Object.assign({
direct_select: DirectSelectWithoutMiddleVertexMode
}, MapboxDraw.modes)
};
const draw = new MapboxDraw(drawOptions);