|
|
@@ -1,551 +0,0 @@
|
|
|
-<template>
|
|
|
- <div>
|
|
|
- <el-amap ref="map" vid="amapDemo" :center="center" :zoom="zoom" :events="mapEvents" cursor="default" class="map-view" :style="{height:mapHeight}">
|
|
|
- <el-amap-marker v-if="myPosition" :position="myPosition" content="<div class='my-position'><div>" cursor="default">
|
|
|
- </el-amap-marker>
|
|
|
- <el-amap-polygon v-for="(item,index) in parks" :key="`${item.parkInfo.id}-${index}`" :path="item.path" :extData="item.parkInfo" :events="polygonEvents" :strokeColor="item.color" strokeOpacity="0.8" :fillColor="item.fill ? item.color : ''" fillOpacity="0.3">
|
|
|
- </el-amap-polygon>
|
|
|
- <el-amap-info-window v-if="showInfo" :autoMove="false" :position="selectedPark.position" :isCustom="true" :contentRender="contentRender" :offset="[0,-10]">
|
|
|
- </el-amap-info-window>
|
|
|
- </el-amap>
|
|
|
- <img src="../assets/icon_locate.png" class="btn-locate" @click="locate">
|
|
|
- <!-- <img src="../assets/icon_map_center.png" class="map-center-icon"> -->
|
|
|
-
|
|
|
- <div class="result-search-box" @click="inSearch=true" v-if="selectedResult">
|
|
|
- <img src="../assets/icon_search.png" class="search-icon">
|
|
|
- <span>{{selectedResult}}</span>
|
|
|
- <img src="../assets/icon_clear.png" class="clear-icon" @click.prevent.stop="selectedResult=''">
|
|
|
- </div>
|
|
|
- <div class="fake-search-box" @click="inSearch=true" v-else>
|
|
|
- <img src="../assets/icon_search.png" class="search-icon">
|
|
|
- <span>搜索环评区块</span>
|
|
|
- </div>
|
|
|
- <div class="search-page" ref="search" v-show="inSearch">
|
|
|
- <div class="search-wrapper">
|
|
|
- <div class="search-box">
|
|
|
- <img src="../assets/icon_search.png" class="search-icon" />
|
|
|
- <input v-model="keyword" placeholder="搜索环评区块" type="search" @focus="focus=true" @blur="focus=false" @keyup="keyup">
|
|
|
- <img src="../assets/icon_clear.png" class="clear-icon" v-if="focus&&keyword" @click="keyword='',noResult=false,showHistory=true">
|
|
|
- </div>
|
|
|
- <div class="cancel" @click="cancel">取消</div>
|
|
|
- </div>
|
|
|
- <div class="mask">
|
|
|
- <div class="search-history" v-if="showHistory">
|
|
|
- <img src="../assets/icon_history.png" class="icon-history">
|
|
|
- <span>历史记录</span>
|
|
|
- <img src="../assets/icon_trash.png" class="icon-trash" @click.prevent="clearHistory">
|
|
|
- </div>
|
|
|
- <div class="history-item" v-for="(item, index) in searchParkHistory" :key="index" v-if="showHistory" @click="research(item)">{{item}}</div>
|
|
|
- <div class="item" v-for="item in searchResults" :key="item.id" @click="showResult(item)">{{item.name}}</div>
|
|
|
- <div class="no-result" v-if="noResult">无结果</div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-<script>
|
|
|
-export default {
|
|
|
- mounted() {
|
|
|
- this.mapHeight = `${this.$el.offsetHeight}px`
|
|
|
- document.body.appendChild(this.$refs.search)
|
|
|
- this.$refs.search.style.top = this.$navbar.$el.offsetHeight + 'px'
|
|
|
- window.onresize = () => {
|
|
|
- this.mapHeight = `${this.$el.offsetHeight}px`
|
|
|
- this.$refs.search.style.top = this.$navbar.$el.offsetHeight + 'px'
|
|
|
- }
|
|
|
- },
|
|
|
- activated() {
|
|
|
- this.history = JSON.parse(localStorage.getItem('viewHistory')) || []
|
|
|
- if (localStorage.getItem('searchParkHistory')) {
|
|
|
- this.searchParkHistory = localStorage.getItem('searchParkHistory').split(',')
|
|
|
- }
|
|
|
- this.searchParkHistory = this.searchParkHistory || []
|
|
|
- },
|
|
|
- data() {
|
|
|
- let self = this
|
|
|
- return {
|
|
|
- center: [118.80423000000002, 31.93501],
|
|
|
- zoom: 15,
|
|
|
- mapHeight: '10px',
|
|
|
- mapEvents: {
|
|
|
- init(map) {
|
|
|
- map.setLayers([
|
|
|
- new AMap.TileLayer.Satellite(),
|
|
|
- new AMap.TileLayer.RoadNet()
|
|
|
- ])
|
|
|
- },
|
|
|
- complete() {
|
|
|
- self.getData()
|
|
|
- self.locate()
|
|
|
- },
|
|
|
- moveend() {
|
|
|
- self.getData()
|
|
|
- },
|
|
|
- click() {
|
|
|
- self.showInfo = false
|
|
|
- },
|
|
|
- zoomend() {
|
|
|
- self.zoom = self.$refs.map.$$getInstance().getZoom()
|
|
|
-
|
|
|
- let lng1 = self.$refs.map.$$getInstance().getBounds().southwest.O
|
|
|
- let lat1 = self.$refs.map.$$getInstance().getBounds().southwest.P
|
|
|
- let lng2 = self.$refs.map.$$getInstance().getBounds().northeast.O
|
|
|
- let lat2 = self.$refs.map.$$getInstance().getBounds().northeast.P
|
|
|
-
|
|
|
- console.log('distance', AMap.GeometryUtil.distance([lng1, lat1], [lng2, lat2]));
|
|
|
- console.log('zoom', self.zoom)
|
|
|
- }
|
|
|
- },
|
|
|
- parks: [],
|
|
|
- polygonEvents: {
|
|
|
- click(e) {
|
|
|
- if (!e.target.getPath().length)
|
|
|
- return
|
|
|
- let mapData = JSON.parse(e.target.getExtData().mapJson)
|
|
|
- let latMin = mapData[0].path[0][1], lngMin = mapData[0].path[0][0],
|
|
|
- latMax = mapData[0].path[0][1], lngMax = mapData[0].path[0][0];
|
|
|
- mapData.forEach(i => {
|
|
|
- i.path.forEach(p => {
|
|
|
- if (p[0] > lngMax) lngMax = p[0];
|
|
|
- if (p[0] < lngMin) lngMin = p[0];
|
|
|
- if (p[1] > latMax) latMax = p[1];
|
|
|
- if (p[1] < latMin) latMin = p[1];
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- let zoom = 0;
|
|
|
- let distance = AMap.GeometryUtil.distance([lngMin, latMin], [lngMax, latMax]);
|
|
|
- if (distance < 700) {
|
|
|
- zoom = 19
|
|
|
- } else if (distance < 320) {
|
|
|
- zoom = 18
|
|
|
- } else if (distance < 680) {
|
|
|
- zoom = 17
|
|
|
- } else if (distance < 1360) {
|
|
|
- zoom = 16
|
|
|
- } else if (distance < 2750) {
|
|
|
- zoom = 15
|
|
|
- } else {
|
|
|
- zoom = 14
|
|
|
- }
|
|
|
- self.zoom = zoom;
|
|
|
- self.center = [(lngMin + lngMax) / 2, (latMin + latMax) / 2]
|
|
|
- self.selectedPark = e.target.getExtData()
|
|
|
- self.selectedPark.position = [(lngMin + lngMax) / 2, latMax]
|
|
|
- self.showInfo = true
|
|
|
- }
|
|
|
- },
|
|
|
- showInfo: false,
|
|
|
- selectedPark: {
|
|
|
- },
|
|
|
- history: [],
|
|
|
- focus: false,
|
|
|
- keyword: '',
|
|
|
- inSearch: false,
|
|
|
- searchResults: [],
|
|
|
- myPosition: null,
|
|
|
- locating: false,
|
|
|
- noResult: false,
|
|
|
- searchParkHistory: [],
|
|
|
- showHistory: true,
|
|
|
- selectedResult: ''
|
|
|
- }
|
|
|
- },
|
|
|
- methods: {
|
|
|
- getData() {
|
|
|
- this.$http.get({
|
|
|
- url: '/parkInfo/getParkInfoOnMap',
|
|
|
- data: {
|
|
|
- lng1: this.$refs.map.$$getInstance().getBounds().southwest.O - 0.01,
|
|
|
- lat1: this.$refs.map.$$getInstance().getBounds().southwest.P - 0.01,
|
|
|
- lng2: this.$refs.map.$$getInstance().getBounds().northeast.O + 0.01,
|
|
|
- lat2: this.$refs.map.$$getInstance().getBounds().northeast.P + 0.01
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.success) {
|
|
|
- this.parks = []
|
|
|
- res.data.forEach(park => {
|
|
|
- if (park.mapJson) {
|
|
|
- let polygons = JSON.parse(park.mapJson)
|
|
|
- polygons.forEach(ploygon => {
|
|
|
- ploygon.parkInfo = park
|
|
|
- this.parks.push(ploygon)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- setupNavbar() {
|
|
|
- this.$navbar.style = 'dark'
|
|
|
- this.$navbar.title = '环保“嘉”助手'
|
|
|
- this.$navbar.background = '#15A8AA'
|
|
|
- this.$navbar.showBack = false
|
|
|
- this.$navbar.showRightItem = false
|
|
|
- this.$navbar.hidden = false
|
|
|
- },
|
|
|
- view(item) {
|
|
|
- let index = -1
|
|
|
- for (let i = 0; i < this.history.length; i++) {
|
|
|
- if (this.history[i].id === item.id) {
|
|
|
- index = i
|
|
|
- }
|
|
|
- }
|
|
|
- if (index > -1) {
|
|
|
- this.history.splice(index, 1)
|
|
|
- }
|
|
|
- this.history.unshift(item)
|
|
|
- localStorage.setItem('viewHistory', JSON.stringify(this.history))
|
|
|
- if (window.cordova) {
|
|
|
- cordova.plugins.pdfViewer.open({
|
|
|
- url: item.url,
|
|
|
- title: item.fileName
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- contentRender(h, instance) {
|
|
|
- return (
|
|
|
- <div class="custom-info-widnow">
|
|
|
- <div class="name">{this.selectedPark.name}</div>
|
|
|
- <div class="detail" on-click={() => { this.view(this.selectedPark.fileInfo) }}>查看详情</div>
|
|
|
- </div>
|
|
|
- )
|
|
|
- },
|
|
|
- keyup(e) {
|
|
|
- if (e.keyCode === 13 && this.keyword) {
|
|
|
- this.search(this.keyword)
|
|
|
- }
|
|
|
- },
|
|
|
- cancel() {
|
|
|
- this.inSearch = false
|
|
|
- this.keyword = ''
|
|
|
- this.searchResults = []
|
|
|
- this.noResult = false
|
|
|
- this.showHistory = true
|
|
|
- },
|
|
|
- showResult(item) {
|
|
|
-
|
|
|
- let mapData = JSON.parse(item.mapJson)
|
|
|
- let latMin = mapData[0].path[0][1], lngMin = mapData[0].path[0][0],
|
|
|
- latMax = mapData[0].path[0][1], lngMax = mapData[0].path[0][0];
|
|
|
- mapData.forEach(i => {
|
|
|
- i.path.forEach(p => {
|
|
|
- if (p[0] > lngMax) lngMax = p[0];
|
|
|
- if (p[0] < lngMin) lngMin = p[0];
|
|
|
- if (p[1] > latMax) latMax = p[1];
|
|
|
- if (p[1] < latMin) latMin = p[1];
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- let zoom = 0;
|
|
|
- let distance = AMap.GeometryUtil.distance([lngMin, latMin], [lngMax, latMax]);
|
|
|
- if (distance < 700) {
|
|
|
- zoom = 19
|
|
|
- } else if (distance < 320) {
|
|
|
- zoom = 18
|
|
|
- } else if (distance < 680) {
|
|
|
- zoom = 17
|
|
|
- } else if (distance < 1360) {
|
|
|
- zoom = 16
|
|
|
- } else if (distance < 2750) {
|
|
|
- zoom = 15
|
|
|
- } else {
|
|
|
- zoom = 14
|
|
|
- }
|
|
|
- this.zoom = zoom;
|
|
|
-
|
|
|
- this.center = [item.centerLng, item.centerLat]
|
|
|
- // this.selectedPark = item
|
|
|
- // this.selectedPark.position = [item.centerLng, item.centerLat]
|
|
|
- this.showInfo = false
|
|
|
- this.selectedResult = item.name
|
|
|
- this.cancel()
|
|
|
- },
|
|
|
- locate() {
|
|
|
- if (this.myPosition) {
|
|
|
- this.center = this.myPosition;
|
|
|
- }
|
|
|
- this.locating = true;
|
|
|
- let geolocation = new AMap.Geolocation({
|
|
|
- enableHighAccuracy: true,
|
|
|
- timeout: 10000,
|
|
|
- });
|
|
|
- geolocation.getCurrentPosition();
|
|
|
- AMap.event.addListener(geolocation, 'complete', data => {
|
|
|
- this.locating = false;
|
|
|
- this.center = [data.position.O, data.position.P];
|
|
|
- this.myPosition = [data.position.O, data.position.P];
|
|
|
- });
|
|
|
- AMap.event.addListener(geolocation, 'error', err => {
|
|
|
- this.locating = false;
|
|
|
- console.log(err)
|
|
|
- });
|
|
|
- },
|
|
|
- search(key) {
|
|
|
- if (this.searchParkHistory.indexOf(key) === -1) {
|
|
|
- this.searchParkHistory.unshift(key)
|
|
|
- if (this.searchParkHistory.length > 10) {
|
|
|
- this.searchParkHistory = this.searchParkHistory.slice(0, 10)
|
|
|
- }
|
|
|
- localStorage.setItem('searchParkHistory', this.searchParkHistory)
|
|
|
- }
|
|
|
- this.showHistory = false
|
|
|
- this.searchResults = []
|
|
|
- this.$http.get({
|
|
|
- url: '/parkInfo/search',
|
|
|
- data: {
|
|
|
- name: this.keyword
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.success) {
|
|
|
- if (res.data.length === 0) {
|
|
|
- this.noResult = true
|
|
|
- } else {
|
|
|
- this.noResult = false
|
|
|
- this.searchResults = res.data
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- research(key) {
|
|
|
- this.keyword = key
|
|
|
- this.search(key)
|
|
|
- },
|
|
|
- clearHistory() {
|
|
|
- this.searchParkHistory = []
|
|
|
- localStorage.removeItem('searchParkHistory')
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-</script>
|
|
|
-<style lang="less" scoped>
|
|
|
-@import '../base.less';
|
|
|
-.map-view {
|
|
|
- width: 100%;
|
|
|
- height: 100%;
|
|
|
-}
|
|
|
-.btn-locate {
|
|
|
- position: absolute;
|
|
|
- left: 15px;
|
|
|
- bottom: 15px;
|
|
|
- width: 32px;
|
|
|
- height: 32px;
|
|
|
-}
|
|
|
-.map-center-icon {
|
|
|
- position: absolute;
|
|
|
- left: 0;
|
|
|
- right: 0;
|
|
|
- top: 0;
|
|
|
- bottom: 0;
|
|
|
- margin: auto;
|
|
|
- width: 17px;
|
|
|
- height: 27px;
|
|
|
-}
|
|
|
-.fake-search-box {
|
|
|
- position: absolute;
|
|
|
- top: 10px;
|
|
|
- left: 15px;
|
|
|
- right: 15px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- height: 38px;
|
|
|
- background: #fff;
|
|
|
- border-radius: 19px;
|
|
|
- box-shadow: 0px 2px 4px 0px rgba(147, 147, 147, 0.2);
|
|
|
- justify-content: center;
|
|
|
- color: @placeholder;
|
|
|
- font-size: 13px;
|
|
|
- .search-icon {
|
|
|
- width: 18px;
|
|
|
- height: 18px;
|
|
|
- margin-right: 6px;
|
|
|
- }
|
|
|
-}
|
|
|
-.result-search-box {
|
|
|
- position: absolute;
|
|
|
- top: 10px;
|
|
|
- left: 15px;
|
|
|
- right: 15px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- height: 38px;
|
|
|
- background: #fff;
|
|
|
- border-radius: 19px;
|
|
|
- box-shadow: 0px 2px 4px 0px rgba(147, 147, 147, 0.2);
|
|
|
- color: black;
|
|
|
- font-size: 15px;
|
|
|
- .search-icon {
|
|
|
- width: 18px;
|
|
|
- height: 18px;
|
|
|
- margin-right: 6px;
|
|
|
- margin-left: 10px;
|
|
|
- }
|
|
|
- span {
|
|
|
- flex-grow: 1;
|
|
|
- font-weight: 700;
|
|
|
- }
|
|
|
- .clear-icon {
|
|
|
- width: 30px;
|
|
|
- height: 30px;
|
|
|
- position: absolute;
|
|
|
- right: 4px;
|
|
|
- top: 0;
|
|
|
- bottom: 0;
|
|
|
- margin: auto;
|
|
|
- }
|
|
|
-}
|
|
|
-.search-page {
|
|
|
- position: absolute;
|
|
|
- left: 0;
|
|
|
- top: 0;
|
|
|
- right: 0;
|
|
|
- bottom: 0;
|
|
|
- display: flex;
|
|
|
- flex-direction: column;
|
|
|
-
|
|
|
- .mask {
|
|
|
- flex-grow: 1;
|
|
|
- background: @pageBg;
|
|
|
- overflow: auto;
|
|
|
- padding-top: 10px;
|
|
|
- .search-history {
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- margin: 0 20px 0 15px;
|
|
|
- color: @main;
|
|
|
- .icon-history {
|
|
|
- width: 14px;
|
|
|
- height: 14px;
|
|
|
- }
|
|
|
- span {
|
|
|
- flex-grow: 1;
|
|
|
- font-size: 12px;
|
|
|
- margin-left: 2px;
|
|
|
- font-weight: 700;
|
|
|
- }
|
|
|
- .icon-trash {
|
|
|
- width: 20px;
|
|
|
- height: 20px;
|
|
|
- }
|
|
|
- }
|
|
|
- .history-item {
|
|
|
- color: black;
|
|
|
- font-size: 14px;
|
|
|
- margin: 15px 15px 0 15px;
|
|
|
- .ellipsis();
|
|
|
- }
|
|
|
- .item {
|
|
|
- position: relative;
|
|
|
- color: @text2;
|
|
|
- font-size: 14px;
|
|
|
- height: 35px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- color: black;
|
|
|
- padding: 0 15px;
|
|
|
- }
|
|
|
- .no-result {
|
|
|
- position: relative;
|
|
|
- color: @text2;
|
|
|
- font-size: 14px;
|
|
|
- padding: 15px 15px;
|
|
|
- text-align: center;
|
|
|
- &:before {
|
|
|
- .setTopLine();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- .search-wrapper {
|
|
|
- height: 58px;
|
|
|
- background: white;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- .search-box {
|
|
|
- height: 38px;
|
|
|
- border-radius: 19px;
|
|
|
- margin-left: 15px;
|
|
|
- background: @pageBg;
|
|
|
- position: relative;
|
|
|
- flex-grow: 1;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- z-index: 200;
|
|
|
- .search-icon {
|
|
|
- width: 18px;
|
|
|
- height: 18px;
|
|
|
- margin-left: 10px;
|
|
|
- margin-right: 6px;
|
|
|
- }
|
|
|
- form {
|
|
|
- flex-grow: 1;
|
|
|
- }
|
|
|
- input {
|
|
|
- flex-grow: 1;
|
|
|
- font-size: 13px;
|
|
|
- line-height: 21px;
|
|
|
- font-size: 15px;
|
|
|
- &::-webkit-input-placeholder {
|
|
|
- color: @placeholder;
|
|
|
- font-size: 13px;
|
|
|
- }
|
|
|
- }
|
|
|
- .clear-icon {
|
|
|
- width: 30px;
|
|
|
- height: 30px;
|
|
|
- position: absolute;
|
|
|
- right: 4px;
|
|
|
- top: 0;
|
|
|
- bottom: 0;
|
|
|
- margin: auto;
|
|
|
- }
|
|
|
- }
|
|
|
- .cancel {
|
|
|
- margin-left: 12px;
|
|
|
- width: 44px;
|
|
|
- height: 58px;
|
|
|
- line-height: 58px;
|
|
|
- color: @text2;
|
|
|
- font-size: 14px;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-</style>
|
|
|
-<style lang="less">
|
|
|
-.anchorBL,
|
|
|
-.amap-logo,
|
|
|
-.amap-copyright {
|
|
|
- display: none !important;
|
|
|
-}
|
|
|
-.custom-info-widnow {
|
|
|
- width: 170px;
|
|
|
- max-width: 170px;
|
|
|
- border-radius: 9px;
|
|
|
- box-shadow: 0px 6px 12px 0px rgba(0, 0, 0, 0.18);
|
|
|
- background: #fff;
|
|
|
- display: flex;
|
|
|
- flex-direction: column;
|
|
|
- align-items: center;
|
|
|
- text-align: center;
|
|
|
- .name {
|
|
|
- color: #000;
|
|
|
- font-size: 14px;
|
|
|
- font-weight: 700;
|
|
|
- margin: 10px 15px 0 15px;
|
|
|
- }
|
|
|
- .detail {
|
|
|
- height: 30px;
|
|
|
- line-height: 30px;
|
|
|
- color: #15a8aa;
|
|
|
- font-size: 11px;
|
|
|
- }
|
|
|
-}
|
|
|
-.my-position {
|
|
|
- width: 14px;
|
|
|
- height: 14px;
|
|
|
- background: #ff9500;
|
|
|
- border-radius: 7px;
|
|
|
- box-shadow: 0 2px 2px rgba(0, 0, 0, 0.15);
|
|
|
- position: relative;
|
|
|
- border: 2px solid #fff;
|
|
|
- box-sizing: border-box;
|
|
|
-}
|
|
|
-</style>
|