html Vue.jsでライブラリ使わずに谷歌地图を利用するref:https://qiita.com/terrierscript/items/9a9dda5a5ca5b3293d48
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Vue.jsでライブラリ使わずに谷歌地图を利用するref:https://qiita.com/terrierscript/items/9a9dda5a5ca5b3293d48相关的知识,希望对你有一定的参考价值。
<!-- ChildMarker -->
<template></template>
<script>
export default {
props: {
google: Object,
map: Object,
position: Object
},
data(){
return { marker: null }
},
mounted(){
const { Marker } = this.google.maps
this.marker = new Marker({
position: this.position,
map: this.map,
title: "Child marker!"
})
}
}
</script>
<!-- MyMap -->
<template>
<div>
<h1>Map</h1>
<map-loader
:map-config="mapConfig"
apiKey="YOUR API KEY">
<template slot-scope="scopeProps"> <!-- slot-scope -->
<child-marker
v-for="(marker,i) in markers"
:key="i"
:position="marker"
:google="scopeProps.google"
:map="scopeProps.map"
/>
</template>
</map-loader>
</div>
</template>
<!-- MapLoader.vue -->
<template>
<div>
<div id="map"></div>
<template v-if="!!this.google && !!this.map">
<slot
:google="google"
:map="map"
/>
</template>
</div>
</template>
<script>
:
</script>
<!-- ChildMarker.vue -->
<template></template>
<script>
export default {
inject: ["google", "map"],
props: {
position: Object
},
data(){
return { marker: null}
},
mounted(){
const { Marker } = this.google.maps
this.marker = new Marker({
position: this.position,
map: this.map,
title: "Child marker!"
})
}
}
</script>
<!-- MapProvider.vue -->
<template>
<div>
<slot />
</div>
</template>
<script>
export default {
props: {
google: Object,
map: Object,
},
provide() {
return {
google: this.google,
map: this.map
}
},
}
</script>
<!-- MapLoader.vue -->
<template>
<div>
<div id="map"></div> <!-- point 1 -->
<template v-if="!!this.google && !!this.map"> <!-- point 2 -->
<map-provider
:google="google"
:map="map"
>
<slot/>
</map-provider>
</template>
</div>
</template>
<script>
import GoogleMapsApiLoader from 'google-maps-api-loader'
import MapProvider from './MapProvider'
export default {
props:{
mapConfig: Object,
apiKey: String
},
components: {
MapProvider
},
data(){
return {
google: null,
map: null
}
},
mounted () { // point 3
GoogleMapsApiLoader({
apiKey: this.apiKey
}).then((google) => {
this.google = google
this.initializeMap()
})
},
methods: {
initializeMap (){
const mapContainer = this.$el.querySelector('#map') // point 1
const { Map } = this.google.maps
this.map = new Map(mapContainer, this.mapConfig)
}
}
}
</script>
<style scoped>
#map {
height: 100vh;
width: 100%;
}
</style>
<!-- MyMap.vue -->
<template>
<div>
<h1>Map</h1>
<map-loader
:map-config="mapConfig"
apiKey="YOUR API KEY"
>
<template v-for="marker in markers">
<child-marker :position="marker" />
</template>
</map-loader>
</div>
</template>
<script>
import MapLoader from "./MapLoader.vue"
import ChildMarker from './ChildMarker'
export default {
props: {
markers: Array
},
data(){
return {
mapConfig: {
zoom: 12,
center: this.markers[0]
}
}
},
components: {
MapLoader,
ChildMarker
}
}
</script>
<!-- index.html -->
<div id="app">
<my-map :markers='[
{"lat":35.6432027,"lng":139.6729435},
{"lat":35.5279833,"lng":139.6989209},
{"lat":35.6563623,"lng":139.7215211},
{"lat":35.6167531,"lng":139.5469376},
{"lat":35.6950961,"lng":139.5037899}
]'>
</my-map>
</div>
以上是关于html Vue.jsでライブラリ使わずに谷歌地图を利用するref:https://qiita.com/terrierscript/items/9a9dda5a5ca5b3293d48的主要内容,如果未能解决你的问题,请参考以下文章
markdown Python GIS演算关连ライブラリまとめ
markdown 自作ライブラリをプロジェクトに取り込む
json [php:ClassUploadPhp]画像アップロードライブラリClassUploadPhp note。 #PHP
c_cpp Objective-C唯一のiOSファイルパスライブラリ,YKFileの说明书参考:http://qiita.com/GeneralD/items/b8bd37b1f698ee98fe58
使用 react.js 制作 pixiv 插画图片墙
javascript jQuery的使わずトグルクラス