Skip to content

Commit

Permalink
Merge pull request #40 from earthrise-media/style-raster
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsey-taylor authored Nov 22, 2023
2 parents 2fb2c08 + 4bd2d6a commit b5f5922
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 8 deletions.
6 changes: 6 additions & 0 deletions vacs-map-app/src/MapExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import MapContainerColorRadius from '@/components/MapContainerColorRadius.vue';
import MapContainerNotFilled from '@/components/MapContainerNotFilled.vue';
import MapContainerNotFilledTwoLayers from '@/components/MapContainerNotFilledTwoLayers.vue';
import MapContainerColorAfricanUnion from '@/components/MapContainerColorAfricanUnion.vue';
import MapContainerColorSandSoil from '@/components/MapContainerColorSandSoil.vue';
import MapContainerColorSoil from '@/components/MapContainerColorSoil.vue';
import MapContainerColorSand from '@/components/MapContainerColorSand.vue';
import { useMapExploreStore } from '@/stores/mapExplore';
Expand Down Expand Up @@ -60,6 +61,11 @@ const availableMaps = [
name: 'circles + african union regions',
component: MapContainerColorAfricanUnion
},
{
id: 'sand-soil',
name: 'circles + sand + soil carbon',
component: MapContainerColorSandSoil
},
{
id: 'soil',
name: 'circles + soil carbon',
Expand Down
2 changes: 1 addition & 1 deletion vacs-map-app/src/components/MapContainerColorSand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:color-column="selectedColumn"
:color-column-extent="selectedColumnExtent"
:color-column-quintiles="selectedColumnQuintiles"
:color-diverging="false"
:color-diverging="true"
:sourceId="sourceId"
:map="map"
:mapReady="mapReady"
Expand Down
77 changes: 77 additions & 0 deletions vacs-map-app/src/components/MapContainerColorSandSoil.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<BaseMap>
<template v-slot="{ map, mapReady }">
<RasterSource
:id="rasterSourceId"
tiles-url="https://plotine-vacs.s3.us-east-2.amazonaws.com/carbon-tiles/{z}/{x}/{y}.png"
:map="map"
:map-ready="mapReady"
/>
<SoilCarbonLayer
id="soil-carbon"
:map="map"
:map-ready="mapReady"
:source-id="rasterSourceId"
/>
<RasterSource
:id="rasterSourceId2"
tiles-url="https://plotine-vacs.s3.us-east-2.amazonaws.com/sand-tiles/{z}/{x}/{y}.png"
:map="map"
:map-ready="mapReady"
/>
<SandLayer id="sand" :map="map" :map-ready="mapReady" :source-id="rasterSourceId2" />
<GridSource :id="sourceId" :map="map" :mapReady="mapReady" />
<GridOverlay
id="grid-layer-1"
:color-column="selectedColumn"
:color-column-extent="selectedColumnExtent"
:color-column-quintiles="selectedColumnQuintiles"
:color-diverging="true"
:sourceId="sourceId"
:map="map"
:mapReady="mapReady"
/>
</template>
</BaseMap>
</template>

<script setup>
import { computed } from 'vue'
import { storeToRefs } from 'pinia'
import BaseMap from '@/components/BaseMap.vue'
import { useFiltersStore } from '@/stores/filters'
import { useCropYieldsStore } from '@/stores/cropYields'
import GridSource from './GridSource.vue'
import GridOverlay from './GridOverlay.vue'
import RasterSource from './RasterSource.vue'
import SoilCarbonLayer from './SoilCarbonLayer.vue'
import SandLayer from './SandLayer.vue'
const sourceId = 'cropGrid'
const rasterSourceId = 'soilCarbonSource'
const rasterSourceId2 = 'sandSource'
const cropYieldsStore = useCropYieldsStore()
const filtersStore = useFiltersStore()
const { selectedCrop, selectedMetric, selectedModel } = storeToRefs(filtersStore)
const selectedColumn = computed(() => {
if (!selectedMetric.value || !selectedCrop.value || !selectedModel.value) {
return null
}
return [selectedMetric.value, selectedCrop.value, selectedModel.value].join('_')
})
const selectedColumnExtent = computed(() => {
if (!selectedColumn.value) return null
return cropYieldsStore.getExtent(selectedColumn.value)
})
const selectedColumnQuintiles = computed(() => {
if (!selectedColumn.value) return null
return cropYieldsStore.getQuintiles(selectedColumn.value)
})
</script>

<style scoped></style>
2 changes: 1 addition & 1 deletion vacs-map-app/src/components/MapContainerColorSoil.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:color-column="selectedColumn"
:color-column-extent="selectedColumnExtent"
:color-column-quintiles="selectedColumnQuintiles"
:color-diverging="false"
:color-diverging="true"
:sourceId="sourceId"
:map="map"
:mapReady="mapReady"
Expand Down
9 changes: 5 additions & 4 deletions vacs-map-app/src/components/SandLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const props = defineProps({
const { id, map, mapReady, sourceId } = toRefs(props)
const minRasterValue = 0
const minRasterValue = 50
const maxRasterValue = 100
const getRasterColor = () => {
Expand All @@ -41,13 +41,13 @@ const getRasterColor = () => {
//
// Like this:
//
// const interpolator = d3.interpolateBrBG;
// const interpolator = d3.interpolateRainbow;
// const interpolator = d3.interpolatePiYG;
// Or define your own:
// const interpolator = d3.interpolateHsl("purple", "orange");
const interpolator = d3.interpolateHsl("transparent", "orange");
const interpolator = d3.interpolateInferno
// const interpolator = d3.interpolateInferno
return interpolator(value)
}
Expand All @@ -61,6 +61,7 @@ const getRasterColor = () => {
const paint = {
'raster-color': getRasterColor(),
'raster-opacity': 0.25,
'raster-color-mix': [255, 0, 0, 0],
'raster-color-range': [0, maxRasterValue]
}
Expand Down
5 changes: 3 additions & 2 deletions vacs-map-app/src/components/SoilCarbonLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const maxRasterValue = 100
const getRasterColor = () => {
const getColor = (value) => {
// const interpolator = d3.interpolateBrBG;
// const interpolator = d3.interpolateHsl("purple", "orange");
const interpolator = d3.interpolateHsl("hsla(143, 52%, 13%, 0)", "#6DACA4");
// const interpolator = d3.interpolatePiYG;
const interpolator = d3.interpolateInferno
// const interpolator = d3.interpolateCubehelixDefault
return interpolator(value)
}
Expand All @@ -54,6 +54,7 @@ const getRasterColor = () => {
const paint = {
'raster-color': getRasterColor(),
'raster-opacity': 0.35,
'raster-color-mix': [255, 0, 0, 0],
'raster-color-range': [0, maxRasterValue]
}
Expand Down

0 comments on commit b5f5922

Please sign in to comment.