Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'dev-map' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
halsk authored Mar 21, 2020
2 parents 93755b0 + 4142cef commit 2c9894b
Show file tree
Hide file tree
Showing 58 changed files with 2,587 additions and 48 deletions.
2 changes: 1 addition & 1 deletion assets/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@
"都内発生": "都内発生",
"(チャーター機・クルーズ船等)": "(チャーター機・クルーズ船等)",
"(注)検査実施人数には、チャーター機帰国者、クルーズ船乗客等は含まれていない": "(注)検査実施人数には、チャーター機帰国者、クルーズ船乗客等は含まれていない"
}
}
8 changes: 1 addition & 7 deletions components/AgencyBarChart.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<data-view :title="title" :title-id="titleId" :date="date" :url="url">
<data-view :title="title" :title-id="titleId" :date="date">
<template v-slot:infoPanel>
<small :class="$style.DataViewDesc">
<slot name="description" />
Expand Down Expand Up @@ -82,7 +82,6 @@ type Props = {
titleId: string
chartId: string
unit: string
url: string
}
const options: ThisTypedComponentOptionsWithRecordProps<
Expand Down Expand Up @@ -116,11 +115,6 @@ const options: ThisTypedComponentOptionsWithRecordProps<
type: String,
required: false,
default: ''
},
url: {
type: String,
required: false,
default: ''
}
},
data() {
Expand Down
6 changes: 5 additions & 1 deletion components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
:unit="info.unit"
/>
</template>
<template v-slot:footer>
<open-data-link :url="url" />
</template>
</data-view>
</template>

Expand Down Expand Up @@ -83,9 +86,10 @@
import Vue from 'vue'
import DataView from '@/components/DataView.vue'
import DataViewBasicInfoPanel from '@/components/DataViewBasicInfoPanel.vue'
import OpenDataLink from '@/components/OpenDataLink.vue'
export default Vue.extend({
components: { DataView, DataViewBasicInfoPanel },
components: { DataView, DataViewBasicInfoPanel, OpenDataLink },
props: {
title: {
type: String,
Expand Down
36 changes: 13 additions & 23 deletions components/DataView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-card class="DataView">
<v-card class="DataView" :loading="loading">
<div class="DataView-Inner">
<div class="DataView-Header">
<h3
Expand All @@ -24,26 +24,7 @@
</div>
<div class="DataView-Footer">
<div class="Footer-Left">
<div>
<a
v-if="url"
class="OpenDataLink"
:href="url"
target="_blank"
rel="noopener"
>
{{ $t('オープンデータを入手') }}
<v-icon
class="ExternalLinkIcon"
size="15"
:aria-label="this.$t('別タブで開く')"
role="img"
:aria-hidden="false"
>
mdi-open-in-new
</v-icon>
</a>
</div>
<slot name="footer" />
<div>
<a class="Permalink" :href="permalink()">
<time :datetime="formattedDate">
Expand Down Expand Up @@ -139,6 +120,10 @@
<div class="overlay-text">
{{ $t('埋め込みコードをコピーしました') }}
</div>
<v-footer class="DataView-Footer">
<time :datetime="date">{{ $t('{date} 更新', { date }) }}</time>
<slot name="footer" />
</v-footer>
</div>
</v-card>
</template>
Expand All @@ -161,9 +146,15 @@ export default Vue.extend({
type: String,
default: ''
},
loading: {
type: Boolean,
required: false,
default: false
},
url: {
type: String,
default: ''
default: '',
required: false
}
},
data() {
Expand Down Expand Up @@ -369,7 +360,6 @@ export default Vue.extend({
color: $gray-3 !important;
text-align: right;
background-color: $white !important;
.Permalink {
color: $gray-3 !important;
}
Expand Down
186 changes: 186 additions & 0 deletions components/Heatmap.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<template>
<mapbox
:access-token="''"
:map-options="actualMapOptions"
@map-load="loaded"
@map-init="mapInitialized"
/>
</template>

<script>
import Mapbox from 'mapbox-gl-vue'
export default {
components: { Mapbox },
props: {
mapId: {
type: String,
default: ''
},
initialBounds: {
type: Array,
default: () => {
return []
}
},
mapOptions: {
type: Object,
required: false,
default: () => {
return {}
}
}
},
data() {
return {
dateSequence: [],
mapObject: null,
legend: null
}
},
computed: {
actualMapOptions() {
return {
style:
'https://tokyo-metropolitan-gov.github.io/tokyo-vector-tile/style.json',
zoom: 14,
center: [139.69167, 35.689444],
antialias: false,
interactive: false,
...this.mapOptions,
container: this.mapId
}
}
},
methods: {
dataDrivenInitialization(map) {
if (this.dateSequence.length !== 0) {
return
}
const self = this
const features = map.queryRenderedFeatures({ layers: ['heatmap'] })
if (features.length === 0) {
setTimeout(self.dataDrivenInitialization, 1000, map)
return
}
this.dateSequence = Object.keys(features[0].properties).sort()
const lastDate = this.dateSequence[this.dateSequence.length - 1]
let m = 0
features.forEach(feature => {
if (m < feature.properties[lastDate]) {
m = feature.properties[lastDate]
}
})
const ceil = 10000 + Math.floor(m * 0.0001) * 10000
const unit = 0.25 * ceil
this.legend = [unit, 2 * unit, 3 * unit]
map.setPaintProperty('heatmap', 'fill-color', [
'step',
['get', lastDate],
'#1B75BC',
this.legend[0],
'#238B45',
this.legend[1],
'#006D2C',
this.legend[2],
'#00441B'
])
self.$emit('legendUpdated', [
{ color: '#1B75BC', valueFrom: 0, valueTo: this.legend[0] },
{
color: '#238B45',
valueFrom: this.legend[0],
valueTo: this.legend[1]
},
{
color: '#006D2C',
valueFrom: this.legend[1],
valueTo: this.legend[2]
},
{ color: '#00441B', valueFrom: this.legend[2], valueTo: null }
])
self.$emit('input', self.getChartData(map))
map.on('moveend', _e => {
self.$emit('input', self.getChartData(map))
})
self.$emit('loadCompleted')
},
getChartData(map) {
const features = map.queryRenderedFeatures({ layers: ['heatmap'] })
if (this.dateSequence.length === 0) {
if (features.length === 0) {
return [
{ date: '20200201', value: 0 },
{ date: '20200202', value: 0 }
]
}
this.dateSequence = Object.keys(features[0]).sort()
}
const dateValueMap = {}
this.dateSequence.forEach(d => {
dateValueMap[d] = 0
})
features.forEach(feature => {
Object.keys(feature.properties).forEach(k => {
dateValueMap[k] += feature.properties[k]
})
})
return Object.keys(dateValueMap).map(d => {
return {
date: d,
value: dateValueMap[d]
}
})
},
loaded(map) {
// const tileUrl = `https://map-covid19-tokyo.netlify.com/mashed_tiles/{z}/{x}/{y}.pbf`
// const tileUrl = `http://localhost:3000/mashed_tiles/{z}/{x}/{y}.pbf`
const tileUrl =
'https://deploy-preview-2--map-covid19-tokyo.netlify.com/mashed_tiles/{z}/{x}/{y}.pbf'
if (
this.initialBounds.length > 1 &&
this.initialBounds[0].length > 1 &&
this.initialBounds[1].length > 1
) {
map.fitBounds(this.initialBounds, { linear: true })
}
map.addLayer({
id: 'heatmap',
type: 'fill',
source: {
type: 'vector',
tiles: [tileUrl],
minzoom: 11,
maxzoom: 11
},
'source-layer': 'dfi-place-heatmap-population',
paint: {
'fill-color': '#fff',
'fill-opacity': 0.5,
'fill-outline-color': '#ffffff'
}
})
this.dataDrivenInitialization(map)
},
mapInitialized(map) {
this.mapObject = map
},
updatePaintProperty(targetDate) {
if (this.mapObject !== null && this.legend !== null) {
const p = [
'step',
['get', targetDate],
'#1B75BC',
this.legend[0],
'#238B45',
this.legend[1],
'#006D2C',
this.legend[2],
'#00441B'
]
this.mapObject.setPaintProperty('heatmap', 'fill-color', p)
}
}
}
}
</script>
49 changes: 49 additions & 0 deletions components/HeatmapLegend.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div>
<ul class="clearfix">
<li v-for="item in legendData" :key="item.valueFrom">
<span class="LegendBlock" :style="`background-color: ${item.color}`" />
{{ `${item.valueFrom}〜${item.valueTo !== null ? item.valueTo : ''}` }}
</li>
</ul>
</div>
</template>

<style scoped>
.LegendBlock {
width: 16px;
height: 16px;
display: inline-block;
}
li {
list-style: none;
float: left;
font-size: 14px;
padding-right: 4px;
}
li:last-child {
padding-right: 0;
}
ul {
margin: 0;
padding: 0;
}
.clearfix:after {
content: '';
display: block;
clear: both;
}
</style>

<script>
export default {
props: {
legendData: {
type: Array,
default: () => {
return []
}
}
}
}
</script>
Loading

0 comments on commit 2c9894b

Please sign in to comment.