【发布时间】:2021-05-28 05:34:45
【问题描述】:
我需要能够在 OpenLayers 5 中绘制多线串(这很容易),并带有可自定义的线端。
例如,如果我正在创建一个标尺工具,我希望多线串的末端是一个“T”,以准确显示线条的开始和结束位置。线条末端的“记号”必须是线条几何形状的一部分。
我已经这样构建了我的生产线......
const draw: olDraw = new olDraw({
source: MapValues.drawSource,
type: 'LineString',
style: new olStyle({
fill: new olFill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new olStroke({
color: '#ffcc33',
width: 2
}),
image: new CircleStyle({
radius: 7,
fill: new olFill({
color: '#ffcc33'
})
})
})
})
draw.on('drawstart', (e: olDrawEvent) => {
const tool = this;
let dStartMeasureTT = this.measureTooltip;
// set sketch
this.sketch = e.feature;
var tooltipCoord = e.coordinate;
tool.listener = this.sketch.getGeometry().on('change', function (evt) {
var geom = evt.target;
var output;
output = tool.formatLength(geom);
tooltipCoord = geom.getLastCoordinate();
tool.measureTooltipElement.innerHTML = output;
tool.measureTooltip.setPosition(tooltipCoord);
});
});
draw.on('drawend', (e: olDrawEvent) => {
const format: olGeoJson = new olGeoJson();
this.shapeString = format.writeGeometry(e.feature.getGeometry(),
{ dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857', rightHanded: false });
this.featureGeometry = transform(e.feature.getGeometry().getCoordinates(), 'EPSG:3857', 'EPSG:4326');
// Pull up Create object modal
const initialState = {
message: '',
title: 'Ruler Label',
iconSize: 'xx-large',
iconType: 'error',
fontSize: 'x-large',
inCharLimit: 50,
inObjName: this.measureTooltipElement.innerHTML
};
this.bsModalRef = this.modalService.show(CreateobjectComponent, Object.assign({ class: 'modal-sm
modal-dialog-centered', initialState }, this.config));
this.bsModalRef.content.closeBtnName = 'OK';
this.bsModalRef.content.modalProcess.subscribe((objName) => {
if (objName) {
this.saveRulerToDb(objName);
this.createMeasureTooltip();
}
});
});
map.addInteraction(draw);
}
}
【问题讨论】:
-
使用类似于openlayers.org/en/latest/examples/line-arrows.html的样式函数,除了只在行首和行尾放置图标(或常规形状),而不是单独的段