|
@@ -1,30 +1,67 @@
|
|
|
<template>
|
|
|
- <div id="near">
|
|
|
- <div id="amap-main">
|
|
|
-
|
|
|
- </div>
|
|
|
+ <div class="amap-page-container">
|
|
|
+ <el-amap-search-box class="search-box" :search-option="searchOption"
|
|
|
+ :on-search-result="onSearchResult"></el-amap-search-box>
|
|
|
+ <el-amap vid="amapDemo">
|
|
|
+ </el-amap>
|
|
|
</div>
|
|
|
</template>
|
|
|
+
|
|
|
+<style>
|
|
|
+ .amap-demo {
|
|
|
+ height: 300px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .search-box {
|
|
|
+ position: absolute;
|
|
|
+ top: 25px;
|
|
|
+ left: 20px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .amap-page-container {
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+</style>
|
|
|
+
|
|
|
<script>
|
|
|
- import {lazyAMapApiLoaderInstance} from 'vue-amap'
|
|
|
- import AMap from 'vue-amap'
|
|
|
- export default {
|
|
|
- name: 'near',
|
|
|
- mounted () {
|
|
|
- lazyAMapApiLoaderInstance.load().then(() => {
|
|
|
- this.map = AMap.Map('container', {
|
|
|
- resizeEnable: true,
|
|
|
- zoom: 11,
|
|
|
- center: [116.397428, 39.90923]
|
|
|
- })
|
|
|
- })
|
|
|
+ module.exports = {
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ markers: [
|
|
|
+ [121.59996, 31.197646],
|
|
|
+ [121.40018, 31.197622],
|
|
|
+ [121.69991, 31.207649]
|
|
|
+ ],
|
|
|
+ searchOption: {
|
|
|
+ city: '上海',
|
|
|
+ citylimit: true
|
|
|
+ },
|
|
|
+ mapCenter: [121.59996, 31.197646]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ addMarker: function () {
|
|
|
+ let lng = 121.5 + Math.round(Math.random() * 1000) / 10000
|
|
|
+ let lat = 31.197646 + Math.round(Math.random() * 500) / 10000
|
|
|
+ this.markers.push([lng, lat])
|
|
|
+ },
|
|
|
+ onSearchResult (pois) {
|
|
|
+ let latSum = 0
|
|
|
+ let lngSum = 0
|
|
|
+ if (pois.length > 0) {
|
|
|
+ pois.forEach(poi => {
|
|
|
+ let {lng, lat} = poi
|
|
|
+ lngSum += lng
|
|
|
+ latSum += lat
|
|
|
+ this.markers.push([poi.lng, poi.lat])
|
|
|
+ })
|
|
|
+ let center = {
|
|
|
+ lng: lngSum / pois.length,
|
|
|
+ lat: latSum / pois.length
|
|
|
+ }
|
|
|
+ this.mapCenter = [center.lng, center.lat]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
-<style lang="less" scoped>
|
|
|
- #near {
|
|
|
- #amap-main {
|
|
|
- height: 300px
|
|
|
- }
|
|
|
- }
|
|
|
-</style>
|