Skip to content

Commit

Permalink
Multigeometry support
Browse files Browse the repository at this point in the history
  • Loading branch information
jokd committed Oct 25, 2023
1 parent 833a16d commit 6ec0f11
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/style/drawstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,31 @@ const selectionStyle = new Style({
if (type === 'Polygon') {
coords = feature.getGeometry().getCoordinates()[0];
pointGeometry = new MultiPoint(coords);
} else if (type === 'MultiPolygon') {
coords = feature.getGeometry().getCoordinates();
const coordArr = [];
coords.forEach(parts => {
parts.forEach(part => {
coordArr.push(...part);
});
});
pointGeometry = new MultiPoint(coordArr);
} else if (type === 'LineString') {
coords = feature.getGeometry().getCoordinates();
pointGeometry = new MultiPoint(coords);
} else if (type === 'MultiLineString') {
coords = feature.getGeometry().getCoordinates();
const coordArr = [];
coords.forEach(part => {
coordArr.push(...part);
});
pointGeometry = new MultiPoint(coordArr);
} else if (type === 'Point') {
coords = feature.getGeometry().getCoordinates();
pointGeometry = new Point(coords);
} else if (type === 'MultiPoint') {
coords = feature.getGeometry().getCoordinates();
pointGeometry = new MultiPoint(coords);
}
return pointGeometry;
}
Expand Down
57 changes: 54 additions & 3 deletions src/style/stylewindow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LineString, Point } from 'ol/geom';
import { LineString, Point, Polygon } from 'ol/geom';
import Select from 'ol/interaction/Select';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
Expand Down Expand Up @@ -263,7 +263,6 @@ const Stylewindow = function Stylewindow(optOptions = {}) {
const font = `${newStyleObj.textSize}px ${newStyleObj.textFont}`;
switch (geometryType) {
case 'LineString':
case 'MultiLineString':
style[0] = new Style({
stroke
});
Expand All @@ -280,8 +279,32 @@ const Stylewindow = function Stylewindow(optOptions = {}) {
style = style.concat(labelStyle);
}
break;
case 'MultiLineString':
style[0] = new Style({
stroke
});
if (newStyleObj.showMeasureSegments) {
const featureCoords = feature.getGeometry().getCoordinates();
featureCoords.forEach(part => {
const line = new LineString(part);
const segmentLabelStyle = drawStyles.getSegmentLabelStyle(line, projection, styleScale);
style = style.concat(segmentLabelStyle);
});
}
if (newStyleObj.showMeasure) {
const featureCoords = feature.getGeometry().getCoordinates();
featureCoords.forEach(part => {
const line = new LineString(part);
const label = drawStyles.formatLength(line, projection);
const point = new Point(line.getLastCoordinate());
const labelStyle = drawStyles.getLabelStyle(styleScale);
labelStyle.setGeometry(point);
labelStyle.getText().setText(label);
style = style.concat(labelStyle);
});
}
break;
case 'Polygon':
case 'MultiPolygon':
style[0] = new Style({
fill,
stroke
Expand All @@ -300,6 +323,34 @@ const Stylewindow = function Stylewindow(optOptions = {}) {
style = style.concat(labelStyle);
}
break;
case 'MultiPolygon':
style[0] = new Style({
fill,
stroke
});
if (newStyleObj.showMeasureSegments) {
const featureCoords = feature.getGeometry().getCoordinates();
featureCoords.forEach(parts => {
parts.forEach(part => {
const line = new LineString(part);
const segmentLabelStyle = drawStyles.getSegmentLabelStyle(line, projection, styleScale);
style = style.concat(segmentLabelStyle);
});
});
}
if (newStyleObj.showMeasure) {
const featureCoords = feature.getGeometry().getCoordinates();
featureCoords.forEach(parts => {
const polygon = new Polygon(parts);
const label = drawStyles.formatArea(polygon, true, projection);
const point = polygon.getInteriorPoint();
const labelStyle = drawStyles.getLabelStyle(styleScale);
labelStyle.setGeometry(point);
labelStyle.getText().setText(label);
style = style.concat(labelStyle);
});
}
break;
case 'Point':
case 'MultiPoint':
style[0] = drawStyles.createRegularShape(newStyleObj.pointType, newStyleObj.pointSize, fill, stroke);
Expand Down

0 comments on commit 6ec0f11

Please sign in to comment.