-
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.
Added Vue3 googlemap added Vue3 Openlayers ⭐
- Loading branch information
Showing
3 changed files
with
241 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<template> | ||
|
||
|
||
<!-- <Vue3GoogleMap/> --> | ||
<VueOpenLayer/> | ||
</template> | ||
<script setup> | ||
import ArcGisMap from './components/ArcGisMap.vue' | ||
import LeafLetMap from './components/LeafLetMap.vue' | ||
// import LeafLetMap from './components/LeafLetMap.vue' | ||
import VueOpenLayer from './components/Vue3Openlayers.vue' | ||
import Vue3GoogleMap from './components/Vue3GoogleMap.vue'; | ||
</script> | ||
<style> | ||
</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,86 @@ | ||
<template> | ||
<div> | ||
<GoogleMap id="map" | ||
api-key="AIzaSyBlUfgGLBFqjvv_NBCxxAsD7-HoIfE3l0w" | ||
style="width: 100%; height: 500px" | ||
:center="center" | ||
:zoom="15" | ||
@click="recordPath" | ||
> | ||
<Marker :options="{ position: center }" /> | ||
<Marker v-for="marker in markers" :key="marker.id" :options="{ position: marker.position }" /> | ||
</GoogleMap> | ||
<button @click="startRecording" :disabled="isRecording">START</button> | ||
<button @click="stopRecording" :disabled="!isRecording">STOP</button> | ||
<button @click="addMarker" :disabled="!isRecording">+</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue'; | ||
import { GoogleMap, Marker } from 'vue3-google-map'; | ||
import html2canvas from "html2canvas"; | ||
const center = ref({ lat: 0, lng: 0 }); | ||
const path = ref([]); | ||
const markers = ref([]); | ||
const isRecording = ref(false); | ||
const startRecording = () => { | ||
isRecording.value = true; | ||
navigator.geolocation.getCurrentPosition( | ||
(position) => { | ||
const { latitude, longitude } = position.coords; | ||
const newPoint = { lat: latitude, lng: longitude }; | ||
path.value.push(newPoint); | ||
center.value.lat = latitude; | ||
center.value.lng = longitude; | ||
}, | ||
(error) => { | ||
console.error(error); | ||
}, | ||
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 } | ||
); | ||
}; | ||
const stopRecording = () => { | ||
isRecording.value = false; | ||
captureMap() | ||
path.value = []; | ||
markers.value = []; | ||
}; | ||
const addMarker = (event) => { | ||
navigator.geolocation.getCurrentPosition( | ||
(position) => { | ||
const { latitude, longitude } = position.coords; | ||
const newPoint = { lat: latitude, lng: longitude }; | ||
path.value.push(newPoint); | ||
center.value.lat = latitude; | ||
center.value.lng = longitude; | ||
}, | ||
(error) => { | ||
console.error(error); | ||
}, | ||
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 } | ||
); | ||
const newMarker = { id: markers.value.length + 1, position: { lat: center.value.lat, lng: center.value.lng } }; | ||
markers.value.push(newMarker); | ||
}; | ||
const captureMap = async () => { | ||
const mapContainerElement = document.getElementById("map"); | ||
html2canvas(mapContainerElement).then((canvas) => { | ||
const image = canvas.toDataURL(); | ||
const link = document.createElement('a'); | ||
link.href = image; | ||
link.download = 'map_capture.png'; | ||
link.click(); | ||
}); | ||
}; | ||
onMounted(() => { | ||
startRecording(); | ||
}); | ||
</script> |
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