Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: projects unable to save when KewPointLayer is selected #445

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/javascript/modelling/worker/interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { getMedianCellSize } from "../../projects/modelling/components/cell_area
import { BooleanTileGrid, NumericTileGrid } from "../../projects/modelling/tile_grid"
import { kdTree } from 'kd-tree-javascript'

export type InterpolationType = "NearestNeighbour" | "Bilinear"

export function interpolateGrid(input : NumericTileGrid, mask : BooleanTileGrid, type: "NearestNeighbour" | "Bilinear", maxDist: number) : NumericTileGrid {

export function interpolateGrid(input : NumericTileGrid, mask : BooleanTileGrid, type: InterpolationType, maxDist: number) : NumericTileGrid {

const result = new NumericTileGrid(input.zoom, input.x, input.y, input.width, input.height)

Expand Down
3 changes: 1 addition & 2 deletions app/javascript/projects/layer_palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export const LayerPalette = ({ addLayer, hide, dbModels, getTeamDatasets, teamNa
name: "Wakehurst Soil",
identifier: "kew:wakehurst_soil_rp3857",
fill: "hsv",
metric: KewPointOptions.find(option => option.value === "ph")!,
metricOpts: KewPointOptions,
metric: KewPointOptions.indexOf(KewPointOptions.find(option => option.value === "ph")!),
visible: true,
opacity: 1,
seasonYear: seasonYearOptions[0]
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/projects/reify_layer/kew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ const getStyle = (layer: KewLayer, zoom: number | undefined) => (
}
)

const getPointStyle = (map: Map, layer: KewPointLayer, min: number | null, max: number | null, colMap: any[]) => (
const getPointStyle = (map: Map, layer: KewPointLayer, min: number | null, max: number | null, colMap: any[], opt: KewOption) => (
(feature) => {

const props = feature.getProperties()
const metric = props[layer.metric.value] || -99999
const metric = props[opt.value] || -99999
const realWorldSize = 4;
const resolution = map.getView().getResolution()!
const pixelSize = realWorldSize / resolution;
Expand Down Expand Up @@ -232,7 +232,9 @@ export function reifyKewPointLayer(layer: KewPointLayer, existingLayer: BaseLaye

const vectorSource = getSource(layer.identifier)

const { min, max } = layer.metric.max ? {min: 0, max: layer.metric.max} : getMinMaxMetric(vectorSource, layer.metric.value)
const metric = KewPointOptions[layer.metric]

const { min, max } = metric.max ? {min: 0, max: metric.max} : getMinMaxMetric(vectorSource, metric.value)

const colMap = getColorStops(layer.fill, 100).reverse()

Expand All @@ -241,7 +243,7 @@ export function reifyKewPointLayer(layer: KewPointLayer, existingLayer: BaseLaye

const v = new VectorLayer({
source: vectorSource,
style: getPointStyle(map, layer, min, max, colMap)
style: getPointStyle(map, layer, min, max, colMap, metric)
})

const popupContainer = document.getElementById("popup")
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/projects/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ const KewPointLayerSettings = ({ layer, mutate }: KewPointLayerSettingsProps) =>
<>
<div className="d-flex align-items-center mt-3">
Property
<select className="custom-select ml-3" value={layer.metric.value} onChange={e => mutate({ metric: KewPointOptions.filter(f => f.value === e.target.value)[0] })}>
<select className="custom-select ml-3" value={KewPointOptions[layer.metric].value} onChange={e => mutate({ metric: KewPointOptions.indexOf(KewPointOptions.filter(f => f.value === e.target.value)[0]) })}>
{
layer.metricOpts.map(opt =>
KewPointOptions.map(opt =>
<option key={opt.value} value={opt.value}>
{opt.label}
</option>
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/projects/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export interface KewLayer extends BaseLayer {
export interface KewPointLayer extends BaseLayer {
type: "KewPointLayer"
identifier: string
metric: KewOption
metricOpts: KewOption[]
metric: number
min?: number
max?: number
fill: fillType
Expand Down
Loading