diff --git a/src/style/drawstyles.js b/src/style/drawstyles.js index 7e3ef4e1c..1c7c736b6 100644 --- a/src/style/drawstyles.js +++ b/src/style/drawstyles.js @@ -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; } diff --git a/src/style/stylewindow.js b/src/style/stylewindow.js index 222c63701..8878a6371 100644 --- a/src/style/stylewindow.js +++ b/src/style/stylewindow.js @@ -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'; @@ -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 }); @@ -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 @@ -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);