Skip to content

Commit

Permalink
Remove geoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
spider-hand committed Jun 13, 2023
1 parent bdcc811 commit 41168b2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 78 deletions.
1 change: 0 additions & 1 deletion public/geoJSON/JPN.json

This file was deleted.

43 changes: 4 additions & 39 deletions src/components/Game/StreetView.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<template>
<div
ref="streetviewRef"
:class="$style['street-view']"
/>
<div ref="streetviewRef" :class="$style['street-view']" />
</template>

<script lang="ts">
/*global google*/
import { defineComponent, onMounted, watch, ref, PropType } from "vue";
import { Feature, feature, MultiPolygon } from "@turf/helpers";
import { randomPosition } from "@turf/random";
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
import bbox from "@turf/bbox";
export default defineComponent({
props: {
Expand All @@ -27,10 +19,6 @@ export default defineComponent({
type: Boolean,
required: true,
},
geoJSON: {
type: Object,
required: false,
},
randomLatLng: {
type: Object as PropType<google.maps.LatLng | null>,
default: null,
Expand Down Expand Up @@ -84,12 +72,7 @@ export default defineComponent({
const service = new google.maps.StreetViewService();
service.getPanorama(
{
location:
decidedLatLng !== null
? decidedLatLng
: props.geoJSON !== null
? getRandomLatLngInsideCountry()
: getRandomLatLng(),
location: decidedLatLng !== null ? decidedLatLng : getRandomLatLng(),
preference: google.maps.StreetViewPreference.NEAREST,
radius: 100000,
source: google.maps.StreetViewSource.OUTDOOR,
Expand All @@ -104,16 +87,6 @@ export default defineComponent({
return new google.maps.LatLng(lat, lng);
};
const getRandomLatLngInsideCountry = (): google.maps.LatLng => {
const featureObj = feature(props.geoJSON);
let pos;
do {
pos = randomPosition(bbox(props.geoJSON));
} while (booleanPointInPolygon(pos, featureObj as Feature<MultiPolygon>));
return new google.maps.LatLng(pos[1], pos[0]);
};
const checkStreetView = (
data: google.maps.StreetViewPanoramaData | null,
status: google.maps.StreetViewStatus
Expand Down Expand Up @@ -154,19 +127,11 @@ export default defineComponent({
onMounted(() => {
if (props.selectedMode !== "multiplayer") {
if (props.selectedMap === "WORLD" || props.geoJSON !== null) {
loadStreetView();
} else {
context.emit("fetchGeoJSON", loadStreetView);
}
loadStreetView();
} else {
// Multiplayer mode
if (props.isOwner) {
if (props.selectedMap === "WORLD" || props.geoJSON !== null) {
loadStreetView();
} else {
context.emit("fetchGeoJSON", loadStreetView());
}
loadStreetView();
}
}
});
Expand Down
20 changes: 0 additions & 20 deletions src/store/modules/gameSettingsStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MapTypes, ModeTypes } from "@/types";
import axios from "axios";

export interface GameSettingsState {
selectedMap: MapTypes;
Expand All @@ -11,7 +10,6 @@ export interface GameSettingsState {
isOwner: boolean;
roomNumber: string;
isStartingGame: boolean;
geoJSON: any;
}

const getDefaultState = (): GameSettingsState => ({
Expand All @@ -24,7 +22,6 @@ const getDefaultState = (): GameSettingsState => ({
isOwner: true,
roomNumber: "",
isStartingGame: false,
geoJSON: null,
});

export const gameSettingsStore = {
Expand Down Expand Up @@ -75,9 +72,6 @@ export const gameSettingsStore = {
clickStartButton(state: GameSettingsState) {
state.isStartingGame = true;
},
fetchGeoJSON(state: GameSettingsState, value: any) {
state.geoJSON = value;
},
},
actions: {
resetGameSettingsStateAction({ commit }: any) {
Expand Down Expand Up @@ -110,19 +104,5 @@ export const gameSettingsStore = {
onClickStartButtonAction({ commit }: any) {
commit("clickStartButton");
},
async fetchGeoJSONAction({ commit }: any, payload: any) {
try {
const resp = await axios.get(
`${import.meta.env.BASE_URL}geoJSON/${payload.countryCode}.json`
);
if (resp.status === 200 && resp.data) {
const json = JSON.parse(JSON.stringify(resp.data));
commit("fetchGeoJSON", json);
}
return resp;
} catch (err) {
console.log(err);
}
},
},
};
22 changes: 4 additions & 18 deletions src/views/Game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<Overlay
v-show="
store.state.gameSettings.selectedMode === 'multiplayer' &&
(!store.state.inGame.isThisRoundReady ||
store.state.inGame.isWaitingForOtherPlayers ||
state.isEndingMultiplayerGame)
(!store.state.inGame.isThisRoundReady ||
store.state.inGame.isWaitingForOtherPlayers ||
state.isEndingMultiplayerGame)
"
:msg="state.overlayMsg"
/>
Expand Down Expand Up @@ -35,13 +35,11 @@
:selected-map="store.state.gameSettings.selectedMap"
:selected-mode="store.state.gameSettings.selectedMode"
:is-owner="store.state.gameSettings.isOwner"
:geo-j-s-o-n="store.state.gameSettings.geoJSON"
:random-lat-lng="store.state.inGame.randomLatLng"
:round="store.state.inGame.round"
@updateRandomLatLng="updateRandomLatLng"
@savePanorama="savePanorama"
@saveStreetView="saveStreetView"
@fetchGeoJSON="fetchGeoJSON"
/>
<ScoreBoard
:selected-map="store.getters.selectedMapText"
Expand All @@ -53,7 +51,7 @@
<RoomNumberDialog
v-if="
store.state.gameSettings.selectedMode === 'multiplayer' &&
store.state.gameSettings.isOwner
store.state.gameSettings.isOwner
"
:room-number="store.state.gameSettings.roomNumber"
:is-game-ready="state.isGameReady"
Expand Down Expand Up @@ -204,17 +202,6 @@ export default defineComponent({
return `${min}:${sec}`;
});
const fetchGeoJSON = async (callback: () => void): Promise<void> => {
try {
await store.dispatch("fetchGeoJSONAction", {
countryCode: store.state.gameSettings.selectedMap,
});
callback();
} catch (err) {
console.log(`fetchGeoJSON error: ${err}`);
}
};
const updateRandomLatLng = (latLng: google.maps.LatLng): void => {
store.dispatch("saveRandomLatLngAction", {
randomLatLng: latLng,
Expand Down Expand Up @@ -595,7 +582,6 @@ export default defineComponent({
isGuessButtonDisabled,
countdown,
DEVICE_TYPES,
fetchGeoJSON,
updateRandomLatLng,
updateSelectedLatLng,
savePanorama,
Expand Down

0 comments on commit 41168b2

Please sign in to comment.