¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <GlobalWindow title="ç»å¶è¿è¥åºå" :visible.sync="isShowModal" :confirm-working="isWorking" @close="close" |
| | | @confirm="confirm" width="1000px"> |
| | | <div class="map_title">ç»å¶ï¼é¼ æ å·¦é®ç¹å»åç§»å¨å³å¯ç»å¶å¾å½¢ï¼ç»å¶è¿ç¨ä¸æä¸escé®å¯ä¸æè¯¥è¿ç¨</div> |
| | | <div class="map_title">é¼ æ å·¦é®åå»å³å¯ç»æå½åå¤è¾¹å½¢ç»å¶ï¼å¤è¾¹å½¢ä¼èªå¨éåï¼</div> |
| | | <div class="map_wrap"> |
| | | <div class="btns"> |
| | | <el-button plain type="primary" @click="reset">{{ polygons.length > 0 ? 'éæ°ç»å¶' : 'å¼å§ç»å¶' }}</el-button> |
| | | <!-- <el-button plain type="primary" @click="changeMode">ç»æç»å¶</el-button> --> |
| | | <!-- <el-button plain @click="reset">éæ°ç»å¶</el-button> --> |
| | | <!-- <el-button plain type="danger" @click="deleteObj">å é¤</el-button> --> |
| | | </div> |
| | | <div id="container" style="width: 100%; height: 100%"></div> |
| | | </div> |
| | | </GlobalWindow> |
| | | </template> |
| | | |
| | | <script> |
| | | import GlobalWindow from '@/components/common/GlobalWindow' |
| | | import { Message } from 'element-ui' |
| | | var map // å°å¾ |
| | | // var editor // ç¼è¾å¨ |
| | | export default { |
| | | components: { |
| | | GlobalWindow |
| | | }, |
| | | data() { |
| | | return { |
| | | isShowModal: false, |
| | | isWorking: false, |
| | | |
| | | map: null, |
| | | editor: null, |
| | | polygon: null, |
| | | polygons: [], // å卿æç»å¶çå¤è¾¹å½¢ |
| | | selectedPolygon: null, |
| | | } |
| | | }, |
| | | methods: { |
| | | initMap() { |
| | | map = new TMap.Map("container", { |
| | | zoom: 16, // 设置å°å¾ç¼©æ¾çº§å« |
| | | center: new TMap.LatLng(31.722763, 117.385480) // 设置å°å¾ä¸å¿ç¹åæ |
| | | }) |
| | | var tempList = [] |
| | | if (this.polygons.length > 0) { |
| | | tempList = [{ paths: this.polygons.map(item => new TMap.LatLng(item.lat, item.lng)) }] |
| | | } |
| | | this.polygon = new TMap.MultiPolygon({ |
| | | map: map, |
| | | id: 'polygon', |
| | | selectedStyleId: 'highlight', |
| | | styles: { |
| | | highlight: new TMap.PolygonStyle({ |
| | | color: 'rgba(255, 255, 0, 0.6)' |
| | | }) |
| | | }, |
| | | geometries: tempList |
| | | }) |
| | | this.editor = new TMap.tools.GeometryEditor({ |
| | | map, |
| | | overlayList: [{ |
| | | overlay: this.polygon, |
| | | id: 'polygon', |
| | | }], |
| | | actionMode: tempList.length > 0 ? TMap.tools.constants.EDITOR_ACTION.INTERACT : TMap.tools.constants.EDITOR_ACTION.DRAW, // ç¼è¾å¨ç工使¨¡å¼ |
| | | activeOverlayId: 'polygon', // æ¿æ´»å¾å± |
| | | snappable: true, // å¼å¯å¸é |
| | | selectable: true, |
| | | }) |
| | | |
| | | let evtList = ['delete', 'adjust', 'split', 'union'] |
| | | evtList.forEach(evtName => { |
| | | this.editor.on(evtName + '_complete', evtResult => { |
| | | // console.log(evtName, evtResult) |
| | | }) |
| | | }) |
| | | this.editor.on('draw_complete', (geometry) => { |
| | | var id = geometry.id |
| | | if (this.editor.getActiveOverlay().id === 'polygon') { |
| | | var geo = this.polygon.geometries.filter(function (item) { |
| | | return item.id === id |
| | | }) |
| | | this.polygons = geo[0].paths |
| | | // console.log('ç»å¶çå¤è¾¹å½¢åæ ï¼', geo[0].paths) |
| | | } |
| | | this.changeMode() |
| | | }) |
| | | }, |
| | | handleAgain() { |
| | | this.editor.setActionMode(TMap.tools.constants.EDITOR_ACTION.DRAW) |
| | | }, |
| | | reset() { |
| | | // this.editor.enable() |
| | | this.polygons = [] |
| | | this.polygon.setGeometries([]) |
| | | this.polygon.remove('polygon') |
| | | this.editor.setActionMode(TMap.tools.constants.EDITOR_ACTION.DRAW) |
| | | }, |
| | | changeMode() { |
| | | this.editor.setActionMode(TMap.tools.constants.EDITOR_ACTION.INTERACT) |
| | | }, |
| | | deleteObj() { |
| | | this.editor.delete() |
| | | }, |
| | | close() { |
| | | this.reset() |
| | | map.destroy() |
| | | this.isShowModal = false |
| | | }, |
| | | confirm() { |
| | | const list = this.editor.getOverlayList()[0].overlay.geometries |
| | | if (list.length == 0) return Message.warning('请å
ç»å¶è¿è¥åºå') |
| | | this.isShowModal = false |
| | | this.reset() |
| | | this.$emit('change', list[0].paths) |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | .map_title { |
| | | font-size: 14px; |
| | | font-weight: 500; |
| | | margin-bottom: 6px; |
| | | } |
| | | |
| | | .map_wrap { |
| | | width: 100%; |
| | | height: calc(100% - 60px); |
| | | position: relative; |
| | | |
| | | .btns { |
| | | position: absolute; |
| | | left: 50%; |
| | | top: 10px; |
| | | transform: translate(-50%, 0); |
| | | z-index: 99999999999; |
| | | } |
| | | } |
| | | </style> |