Skip to content

Commit

Permalink
Merge pull request #168 from Disfactory/release/2.7.0
Browse files Browse the repository at this point in the history
Release 2.7.0
  • Loading branch information
Yukaii authored May 17, 2023
2 parents 5528d23 + 10ad111 commit 46c2e92
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 39 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VUE_APP_BASE_URL=https://staging.disfactory.tw/api
VUE_APP_IMGUR_FALLBACK_URL=https://api.disfactory.tw/imgur
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
run: |
npm ci
echo "VUE_APP_BASE_URL=https://staging.disfactory.tw/api" > .env
echo "VUE_APP_IMGUR_FALLBACK_URL=https://staging.disfactory.tw/imgur" >> .env
npm run build
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@3.7.1
Expand Down Expand Up @@ -95,6 +96,7 @@ jobs:
run: |
npm ci
echo "VUE_APP_BASE_URL=https://api.disfactory.tw/api" > .env.production
echo "VUE_APP_IMGUR_FALLBACK_URL=https://api.disfactory.tw/imgur" >> .env.production
npm run build
echo "disfactory.tw" > dist/CNAME
- name: Deploy to GitHub Pages
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Disfactory Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
149 changes: 114 additions & 35 deletions src/components/DisplaySettingBottomSheet.vue
Original file line number Diff line number Diff line change
@@ -1,39 +1,94 @@
<template>
<v-bottom-sheet v-model="isOpen">
<template v-slot:activator="{ on, attrs }">
<v-btn
color="primary"
class="mx-2 mb-5 white--text"
v-bind="attrs"
v-on="on"
>
顯示設定
</v-btn>
</template>
<v-list>
<v-subheader>地圖顯示設定</v-subheader>
<v-list-item>
<h2 class="primary--text text-button">農地範圍 •</h2>
<span>
<v-menu
v-if="$vuetify.breakpoint.mdAndUp"
content-class="display-setting-popover"
v-model="isOpen"
:close-on-content-click="false"
:nudge-width="200"
offset-y
>
<template v-slot:activator="{ on, attrs }">
<v-btn
text
x-small
class="primary--text"
:class="!isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'"
@click="isLUIMapVisable = false"
>隱藏</v-btn>
color="primary"
class="mx-2 mb-5 white--text"
v-bind="attrs"
v-on="on"
>
顯示設定
</v-btn>
</template>
<v-card>
<v-list>
<v-list-item>
<h2 class="primary--text text-button">農地範圍 •</h2>
<v-btn
text
x-small
class="primary--text"
:class="
!isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'
"
@click="isLUIMapVisable = false"
>隱藏</v-btn
>
<v-btn
text
x-small
class="primary--text"
:class="
isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'
"
@click="isLUIMapVisable = true"
>顯示</v-btn
>
</v-list-item>
<v-list-item>
<switch-map-mode-button :isInSheet="true" />
</v-list-item>
</v-list>
</v-card>
</v-menu>

<!-- Mobile -->
<v-bottom-sheet v-else v-model="isOpen">
<template v-slot:activator="{ on, attrs }">
<v-btn
text
x-small
class="primary--text"
:class="isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'"
@click="isLUIMapVisable = true"
>顯示</v-btn>
</v-list-item>
<v-list-item>
<switch-map-mode-button :isInSheet="true" />
</v-list-item>
</v-list>
</v-bottom-sheet>
color="primary"
class="mx-2 mb-5 white--text"
v-bind="attrs"
v-on="on"
>
顯示設定
</v-btn>
</template>
<v-list>
<v-subheader>地圖顯示設定</v-subheader>
<v-list-item>
<h2 class="primary--text text-button">農地範圍 •</h2>
<v-btn
text
x-small
class="primary--text"
:class="!isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'"
@click="isLUIMapVisable = false"
>隱藏</v-btn
>
<v-btn
text
x-small
class="primary--text"
:class="isLUIMapVisable ? 'font-weight-bold' : 'font-weight-light'"
@click="isLUIMapVisable = true"
>顯示</v-btn
>
</v-list-item>
<v-list-item>
<switch-map-mode-button :isInSheet="true" />
</v-list-item>
</v-list>
</v-bottom-sheet>
</span>
</template>

<script lang="ts">
Expand All @@ -50,7 +105,10 @@ export default createComponent({
},
setup () {
const isOpen = ref(false)
const mapController = inject(MainMapControllerSymbol, ref<MapFactoryController>())
const mapController = inject(
MainMapControllerSymbol,
ref<MapFactoryController>()
)
const isLUIMapVisable$ = ref(false)
const isLUIMapVisable = computed({
Expand All @@ -59,7 +117,7 @@ export default createComponent({
return isLUIMapVisable$.value
},
set: (value) => {
set: value => {
mapController.value?.mapInstance.setLUILayerVisible(value)
isLUIMapVisable$.value = value
}
Expand All @@ -72,3 +130,24 @@ export default createComponent({
}
})
</script>

<style lang="scss" scoped>
.display-setting-popover {
margin-top: 20px;
contain: initial;
overflow: visible;
}
.display-setting-popover::before {
position: absolute;
content: "";
top: 0;
left: 30px;
transform: translateY(-100%);
width: 10px;
height: 13px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 13px solid #fff;
z-index: 1;
}
</style>
6 changes: 5 additions & 1 deletion src/components/FactoryDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</div>
</v-slide-item>
<v-slide-item v-for="(image, index) in images" class="mr-4" :key="image.id" :class="{ 'ml-4': index === 0 }" @click.native="setLightboxIndex(index)">
<img :src="image.url" class="factory-slide-image" />
<ImgurFallbackImage :src="image.url" className="factory-slide-image" />
</v-slide-item>
</v-slide-group>

Expand Down Expand Up @@ -145,9 +145,13 @@ import { getFactoryReportRecords } from '@/api'
import { useAppState } from '../lib/appState'
import { FactoryImage, getDisplayStatusText, ReportRecord } from '../types'
import ImgurFallbackImage from './ImgurFallbackImage.vue'
export default createComponent({
name: 'FactoryDetailPage',
components: {
ImgurFallbackImage
},
setup () {
const [appState, { pageTransition, expandFactoryDetail, collapseFactoryDetail, toggleFactoryDetail }] = useAppState()
Expand Down
58 changes: 58 additions & 0 deletions src/components/ImgurFallbackImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<img :src="imageUrl" :alt="alt" :class="className" @error="onError" />
</template>

<script lang="ts">
import { createComponent, computed, ref, onUpdated, watch } from '@vue/composition-api'
const IMGUR_REGEX = /i\.imgur\.com\/([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)(\?.*)?$/
const imgurFallbackBaseUrl = process.env.NODE_ENV === 'production' ? process.env.VUE_APP_IMGUR_FALLBACK_URL : '/server/imgur'
export default createComponent({
name: 'ImgurFallbackImage',
props: {
src: {
type: String,
required: true
},
alt: {
type: String,
default: ''
},
className: {
type: String,
default: ''
}
},
setup (props, context) {
const matches = IMGUR_REGEX.exec(props.src)
const imgurInfo = computed(() => {
return matches ? {
id: matches[1],
ext: matches[2]
} : null
})
const fallbackUrl = computed(() => {
if (imgurInfo.value) {
return `${imgurFallbackBaseUrl}/${imgurInfo.value.id}.${imgurInfo.value.ext}`
} else {
return props.src
}
})
const imageUrl = ref(fallbackUrl.value)
const onError = () => {
imageUrl.value = props.src
}
return {
imageUrl,
onError
}
}
})
</script>
15 changes: 12 additions & 3 deletions src/lib/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MVT from 'ol/format/MVT'
import VectorTileRenderType from 'ol/layer/VectorTileRenderType'
import stylefunction from 'ol-mapbox-style/dist/stylefunction'
import { baseStyle } from './layerStyle'
import FactoryPointCache from './utils/factoryPointCache'

const getFactoryStatusImage = (status: FactoryDisplayStatusType) => `/images/marker-${status}.svg`
export const getStatusBorderColor = (status: FactoryDisplayStatusType) => {
Expand Down Expand Up @@ -140,10 +141,11 @@ export class MapFactoryController {
style: (feature, resolution) => {
const zoom = this.mapInstance.map.getView().getZoom()!

const clusterDistance = clusterSource.getDistance()
if (zoom > 16) {
if (clusterSource.getDistance() !== 0) clusterSource.setDistance(0)
if (clusterDistance !== 0) clusterSource.setDistance(0)
} else {
if (clusterSource.getDistance() !== CLUSTER_DISTANCE) clusterSource.setDistance(CLUSTER_DISTANCE)
if (clusterDistance !== CLUSTER_DISTANCE) clusterSource.setDistance(CLUSTER_DISTANCE)
}

const features = feature.get('features')
Expand Down Expand Up @@ -218,7 +220,7 @@ export class MapFactoryController {
}
})

const features = factoriesToAdd.map(createFactoryFeature)
const features = factoriesToAdd.map(createFactoryFeature).filter(Boolean) as Feature[]
interface FeatureFactoryStatusMap {
[key: string]: Feature[]
}
Expand Down Expand Up @@ -260,6 +262,11 @@ export class MapFactoryController {
}

private createFactoryFeature (factory: FactoryData) {
const existingFeature = FactoryPointCache.getFactoryCache(factory)
if (existingFeature) {
return null
}

const feature = new Feature({
geometry: new Point(transform([factory.lng, factory.lat], 'EPSG:4326', 'EPSG:3857'))
})
Expand All @@ -272,6 +279,8 @@ export class MapFactoryController {

this.factoryMap.set(factory.id, factory)

FactoryPointCache.setFactoryCache(factory, feature)

return feature
}

Expand Down
19 changes: 19 additions & 0 deletions src/lib/utils/factoryPointCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FactoryData } from '@/types'
import Feature from 'ol/Feature'

const featurePointCachedByCoord = new Map<string, Feature>()
export class FactoryPointCache {
static getFactoryCacheKey (factory: FactoryData) {
return `${factory.lat},${factory.lng}`
}

static getFactoryCache (factory: FactoryData) {
return featurePointCachedByCoord.get(this.getFactoryCacheKey(factory))
}

static setFactoryCache (factory: FactoryData, feature: Feature) {
featurePointCachedByCoord.set(this.getFactoryCacheKey(factory), feature)
}
}

export default FactoryPointCache

0 comments on commit 46c2e92

Please sign in to comment.