Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pvargas committed Dec 13, 2023
1 parent a557133 commit ac0f87c
Showing 1 changed file with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
} from '../../../../react-component/location/location-color-selector'
import { InteractionsContext } from '../interactions.provider'
import { Model } from 'backbone'
import { Position } from '@blueprintjs/core'

const DrawingMenu = menu.DrawingMenu
const makeEmptyGeometry = geometry.makeEmptyGeometry
Expand Down Expand Up @@ -169,31 +168,50 @@ const createGeoModel = (geo: GeometryJSON) => {
return {}
}
}
const createDefaultPolygon = (
buffer: number,
bufferUnit: string,
color: string
): any => {
return {
type: 'Feature',
properties: {
id: '',
color: color,
shape: 'Polygon',
buffer: buffer,
bufferUnit: bufferUnit,
},
geometry: {
type: 'Polygon',
coordinates: [[]],
},
bbox: [0, 0, 0, 0],
}
}

const modelToPolygon = (model: any): GeometryJSON | null => {
let coords = model.get('polygon')
const coords = model.get('polygon')
const polygonBufferWidth = Number(model.get('polygonBufferWidth'))
const buffer = Number.isNaN(polygonBufferWidth) ? 0 : polygonBufferWidth
const bufferUnit = model.get('polygonBufferUnits') || undefined

if (
coords === undefined ||
validateGeo('polygon', JSON.stringify(coords))?.error
) {
coords = [
[0, 0],
[0, 0],
[0, 0],
[0, 0],
]
return createDefaultPolygon(buffer, bufferUnit, DRAWING_COLOR)
}

const isMultiPolygon = ShapeUtils.isArray3D(coords)
const polygon = isMultiPolygon ? coords : [coords]
const buffer = Number(model.get('polygonBufferWidth'))
const bufferUnit = model.get('polygonBufferUnits')
return makeGeometry(
v4(),
Turf.polygon(polygon).geometry,
DRAWING_COLOR,
'Polygon',
Number.isNaN(buffer) ? 0 : buffer,
bufferUnit || undefined
bufferUnit
)
}

Expand Down Expand Up @@ -302,12 +320,11 @@ let drawingLocation: GeometryJSON | null = makeEmptyGeometry(
DEFAULT_SHAPE
)

const preserveAttributes = (
const preserveBuffer = (
drawingModel: any,
drawingLocation: any,
drawingShape: string
) => {
// preserve buffer
const updatedDrawingLocation = drawingLocation
if (drawingShape === 'Line') {
const lineWidth = drawingModel.get('lineWidth')
Expand Down Expand Up @@ -413,15 +430,15 @@ export const OpenlayersDrawings = ({
drawingModel.set('drawing', false)

// preserve buffer set by user
const updatedDrawingLocation = preserveAttributes(
const updatedDrawingLocation = preserveBuffer(
drawingModel,
drawingLocation,
drawingShape
)

drawingModel.set(convertToModel(updatedDrawingLocation, drawingShape))
setIsDrawing(false)
setDrawingGeometry(drawingLocation)
setDrawingGeometry(updatedDrawingLocation)
drawingLocation = null
}

Expand Down

0 comments on commit ac0f87c

Please sign in to comment.