I need to be able to draw a multi-linestring in OpenLayers 5 (this is easy enough) with customizable line ends.
For instance if I'm creating a ruler tool I want the ends of the multi-linestring to be a "T" to show precisely where the line starts and ends. The "ticks" on the end of the line need to be part of the geometry of the line.
I've constructed my line like this...
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);
}
}