123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>测距、测面积</title>
- <link rel="stylesheet" href="../../dist/index.css" />
- <script src="../assets/vue@2.7.14.js"></script>
- <script src="../../dist/index.js"></script>
- <style>
- body {
- margin: 0
- }
- #map {
- height: 100vh;
- }
- .control {
- position: absolute;
- top: 20px;
- left: 40px;
- padding: 10px 10px 0;
- background: #fff;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <div id="map"></div>
- <div class="control">
- <button @click="initDefault">初始化测距(开始提示,右键撤销)</button>
- <button @click="initRed">初始化测距(红色,右键结束)</button>
- <button @click="initArea">初始化测面积(右键结束)</button>
- <button @click="toggleTooltip">隐藏/显示结果提示(单个)</button>
- <button @click="toggleAllTooltip">隐藏/显示结果提示(全部)</button>
- <button @click="_ => measure.stop()">停止</button>
- <button @click="start">开始</button>
- <button @click="_ => measure.clear()">全部清除</button>
- <button @click="destroy">销毁</button>
- <p>注意:需要导入样式文件 dist/index.css </p>
- </div>
- </div>
- </body>
- <script>
- new Vue({
- el: '#app',
- data () {
- this.showTooltip = true
- this.showAllTooltip = true
- return {
- viewShedVisible: true
- }
- },
- mounted () {
- this.map = new CTMapOl.extend.InitMap({
- domId: 'map'
- })
- },
- methods: {
- initMeasure (options) {
- if (this.measure) {
- this.measure.destroy()
- }
- // 不要在 data 中定义 measure 变量,无需响应式
- this.measure = new CTMapOl.extend.ToolMeasure(this.map.map, options)
- },
- initDefault () {
- this.initMeasure({ startTip: '单击确定起点' })
- this.start()
- },
- initRed () {
- this.initMeasure({
- color: 'red',
- rightClickAction: 'finish',
- onFinish: result => {
- this.lastMeasure = result.feature
- console.log(result)
- },
- onReduce: result => {
- console.log('删除点后', result)
- },
- onRemove: feature => {
- console.log('删除测量', feature)
- }
- })
- this.start()
- },
- initArea () {
- this.initMeasure({ type: 'area', rightClickAction: 'finish' })
- this.start()
- },
- toggleTooltip () {
- if (!this.lastMeasure) { return }
- this.showTooltip = !this.showTooltip
- this.measure.showTooltip(this.showTooltip, this.lastMeasure)
- },
- toggleAllTooltip () {
- this.showAllTooltip = !this.showAllTooltip
- this.measure.showTooltip(this.showAllTooltip)
- },
- start () {
- if (this.measure) {
- this.measure.start()
- } else {
- alert('必须先初始化')
- }
- },
- destroy () {
- this.measure.destroy()
- this.measure = null
- }
- }
- })
- </script>
- </html>
|