-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from earthrise-media/layer-order
- Loading branch information
Showing
8 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
vacs-map-app/src/components/MapContainerColorPopulation.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<BaseMap> | ||
<template v-slot="{ map, mapReady }"> | ||
<RasterSource | ||
:id="rasterSourceId" | ||
tiles-url="https://plotine-vacs.s3.us-east-2.amazonaws.com/population-tiles/{z}/{x}/{y}.png" | ||
:map="map" | ||
:map-ready="mapReady" | ||
/> | ||
<PopulationLayer id="population" :map="map" :map-ready="mapReady" :source-id="rasterSourceId" /> | ||
<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 PopulationLayer from './PopulationLayer.vue' | ||
const sourceId = 'cropGrid' | ||
const rasterSourceId = 'populationSource' | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<template> | ||
<RasterLayer :id="id" :map="map" :map-ready="mapReady" :source-id="sourceId" :paint="paint" /> | ||
</template> | ||
|
||
<script setup> | ||
import * as d3 from 'd3' | ||
import { toRefs, watch } from 'vue' | ||
import RasterLayer from './RasterLayer.vue' | ||
const props = defineProps({ | ||
id: { | ||
type: String, | ||
default: '' | ||
}, | ||
map: { | ||
type: Object, | ||
default: null | ||
}, | ||
mapReady: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
sourceId: { | ||
type: String, | ||
default: '' | ||
} | ||
}) | ||
const { id, map, mapReady, sourceId } = toRefs(props) | ||
const minRasterValue = 0 | ||
const maxRasterValue = 20 | ||
const getRasterColor = () => { | ||
const getColor = (value) => { | ||
// Pick an interpolate function here: | ||
// https://d3js.org/d3-scale-chromatic/sequential | ||
// | ||
// Like this: | ||
// | ||
// const interpolator = d3.interpolateSinebow; | ||
// const interpolator = d3.interpolateCubehelixDefault | ||
; | ||
// Or define your own: | ||
const interpolator = d3.interpolateHsl("transparent", "palegoldenrod"); | ||
// const interpolator = d3.interpolateInferno | ||
return interpolator(value) | ||
} | ||
const steps = d3 | ||
.range(0, 5, 1) | ||
.map((i) => [minRasterValue + maxRasterValue * (i * 0.25), getColor(i * 0.25)]) | ||
.flat() | ||
return ['interpolate', ['linear'], ['raster-value'], ...steps] | ||
} | ||
const paint = { | ||
'raster-color': getRasterColor(), | ||
'raster-opacity': 0.45, | ||
'raster-color-mix': [255, 0, 0, 0], | ||
'raster-color-range': [0, maxRasterValue] | ||
} | ||
</script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters