Browse Source

添加天地图

木星 4 months ago
parent
commit
595448119d
3 changed files with 167 additions and 83 deletions
  1. 1 0
      .gitignore
  2. 2 0
      public/index.html
  3. 164 83
      src/views/info/areaInfo/index.vue

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
1
+node_modules/

+ 2 - 0
public/index.html

@@ -8,6 +8,8 @@
8 8
     <link rel="icon" href="<%= BASE_URL %>favicon.svg">
9 9
     <title></title>
10 10
     <script type="text/javascript" src="<%= BASE_URL %>config.js"></script>
11
+    <script src="http://api.tianditu.gov.cn/api?v=4.0&tk=060749cf8167e6993c4dbaf8bc9ef0e2" type="text/javascript"></script>
12
+    <!-- <script src="http://api.tianditu.gov.cn/api?v=4.0&tk=09c064e0ed01777bed7829a6a5514c72" type="text/javascript"></script> -->
11 13
     <!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
12 14
 	  <style>
13 15
     html,

+ 164 - 83
src/views/info/areaInfo/index.vue

@@ -1,26 +1,18 @@
1 1
 <template>
2 2
   <div class="app-container">
3
-    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
3
+    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"
4
+      @submit.native.prevent>
4 5
       <el-form-item label="类别" prop="typeId">
5 6
         <template>
6 7
           <el-select v-model="queryParams.typeId" filterable placeholder="请选择">
7
-            <el-option
8
-              v-for="item in AreaType"
9
-              :key="item.typeId"
10
-              :label="item.typeName"
11
-              :value="item.typeId">
8
+            <el-option v-for="item in AreaType" :key="item.typeId" :label="item.typeName" :value="item.typeId">
12 9
             </el-option>
13 10
           </el-select>
14 11
         </template>
15 12
       </el-form-item>
16 13
       <el-form-item label="名字" prop="areaName">
17
-        <el-input
18
-          v-model="queryParams.areaName"
19
-          placeholder="请输入名字"
20
-          clearable
21
-          size="small"
22
-          @keyup.enter.native="handleQuery"
23
-        />
14
+        <el-input v-model="queryParams.areaName" placeholder="请输入名字" clearable size="small"
15
+          @keyup.enter.native="handleQuery" />
24 16
       </el-form-item>
25 17
       <el-form-item>
26 18
         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
@@ -30,47 +22,20 @@
30 22
 
31 23
     <el-row :gutter="10" class="mb8">
32 24
       <el-col :span="1.5">
33
-        <el-button
34
-          type="primary"
35
-          plain
36
-          icon="el-icon-plus"
37
-          size="mini"
38
-          @click="handleAdd"
39
-          v-hasPermi="['info:areaInfo:add']"
40
-        >新增</el-button>
25
+        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
26
+          v-hasPermi="['info:areaInfo:add']">新增</el-button>
41 27
       </el-col>
42 28
       <el-col :span="1.5">
43
-        <el-button
44
-          type="success"
45
-          plain
46
-          icon="el-icon-edit"
47
-          size="mini"
48
-          :disabled="single"
49
-          @click="handleUpdate"
50
-          v-hasPermi="['info:areaInfo:edit']"
51
-        >修改</el-button>
29
+        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
30
+          v-hasPermi="['info:areaInfo:edit']">修改</el-button>
52 31
       </el-col>
53 32
       <el-col :span="1.5">
54
-        <el-button
55
-          type="danger"
56
-          plain
57
-          icon="el-icon-delete"
58
-          size="mini"
59
-          :disabled="multiple"
60
-          @click="handleDelete"
61
-          v-hasPermi="['info:areaInfo:remove']"
62
-        >删除</el-button>
33
+        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
34
+          v-hasPermi="['info:areaInfo:remove']">删除</el-button>
63 35
       </el-col>
64 36
       <el-col :span="1.5">
65
-        <el-button
66
-          type="warning"
67
-          plain
68
-          icon="el-icon-download"
69
-          size="mini"
70
-          :loading="exportLoading"
71
-          @click="handleExport"
72
-          v-hasPermi="['info:areaInfo:export']"
73
-        >导出</el-button>
37
+        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
38
+          @click="handleExport" v-hasPermi="['info:areaInfo:export']">导出</el-button>
74 39
       </el-col>
75 40
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
76 41
     </el-row>
@@ -82,38 +47,23 @@
82 47
       <el-table-column label="名字" align="center" prop="areaName" />
83 48
       <el-table-column label="颜色" prop="colour">
84 49
         <template slot-scope="scope">
85
-          <div :style="{ backgroundColor: scope.row.colour, width: '40px', height: '30px', borderRadius: '50%'}"></div>
50
+          <div :style="{ backgroundColor: scope.row.colour, width: '40px', height: '30px', borderRadius: '50%' }"></div>
86 51
         </template>
87 52
       </el-table-column>
88 53
       <el-table-column label="面积" align="center" prop="acreage" />
89
-      <el-table-column label="坐标" align="center" prop="location" />
54
+      <!-- <el-table-column label="坐标" align="center" prop="location" /> -->
90 55
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="140">
91 56
         <template slot-scope="scope">
92
-          <el-button
93
-            size="mini"
94
-            type="text"
95
-            icon="el-icon-edit"
96
-            @click="handleUpdate(scope.row)"
97
-            v-hasPermi="['info:areaInfo:edit']"
98
-          >修改</el-button>
99
-          <el-button
100
-            size="mini"
101
-            type="text"
102
-            icon="el-icon-delete"
103
-            @click="handleDelete(scope.row)"
104
-            v-hasPermi="['info:areaInfo:remove']"
105
-          >删除</el-button>
57
+          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
58
+            v-hasPermi="['info:areaInfo:edit']">修改</el-button>
59
+          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
60
+            v-hasPermi="['info:areaInfo:remove']">删除</el-button>
106 61
         </template>
107 62
       </el-table-column>
108 63
     </el-table>
109 64
 
110
-    <pagination
111
-      v-show="total>0"
112
-      :total="total"
113
-      :page.sync="queryParams.pageNum"
114
-      :limit.sync="queryParams.pageSize"
115
-      @pagination="getList"
116
-    />
65
+    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
66
+      @pagination="getList" />
117 67
 
118 68
     <!-- 添加或修改区域对象对话框 -->
119 69
     <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
@@ -121,11 +71,7 @@
121 71
         <el-form-item label="类别" prop="typeId">
122 72
           <template>
123 73
             <el-select v-model="form.typeId" filterable placeholder="请选择">
124
-              <el-option
125
-                v-for="item in AreaType"
126
-                :key="item.typeId"
127
-                :label="item.typeName"
128
-                :value="item.typeId">
74
+              <el-option v-for="item in AreaType" :key="item.typeId" :label="item.typeName" :value="item.typeId">
129 75
               </el-option>
130 76
             </el-select>
131 77
           </template>
@@ -134,17 +80,20 @@
134 80
           <el-input v-model="form.areaName" placeholder="请输入名字" />
135 81
         </el-form-item>
136 82
         <el-form-item label="备注" prop="memo">
137
-          <wang-editor v-model="form.memo" :min-height="140"/>
83
+          <wang-editor v-model="form.memo" :min-height="140" />
138 84
         </el-form-item>
139 85
         <el-form-item label="颜色">
140 86
           <el-color-picker v-model="form.colour"></el-color-picker>
141 87
         </el-form-item>
142 88
         <el-form-item label="面积" prop="acreage">
143
-          <el-input-number v-model="form.acreage" controls-position="right"   :min="0" placeholder="请输入面积" />
89
+          <el-input-number v-model="form.acreage" controls-position="right" :min="0" placeholder="请输入面积" />
144 90
         </el-form-item>
145 91
 
146 92
         <el-form-item label="坐标" prop="location">
147
-          <el-input v-model="form.location" placeholder="请输入坐标" />
93
+          <el-input @focus="openditu" v-model="form.location">
94
+            {{ form.location }}
95
+          </el-input>
96
+
148 97
         </el-form-item>
149 98
       </el-form>
150 99
       <div slot="footer" class="dialog-footer">
@@ -152,7 +101,26 @@
152 101
         <el-button @click="cancel">取 消</el-button>
153 102
       </div>
154 103
     </el-dialog>
104
+
105
+
106
+
107
+    <el-dialog title="地图" :visible.sync="dialogVisible" width="80%">
108
+      <div id='mainMap'>
109
+        <div id="mapDiv" style="width:100%; height:700px">
110
+        </div>
111
+      </div>
112
+      <input type="button" value="清除" @click='clearmian()' />
113
+      <input type="button" value="多边形工具" @click='openPolygonTool()' />
114
+
115
+      <span slot="footer" class="dialog-footer">
116
+        <el-button @click="dialogVisible = false">取 消</el-button>
117
+        <el-button type="primary" @click='tijiao'>确定</el-button>
118
+      </span>
119
+    </el-dialog>
120
+
121
+
155 122
   </div>
123
+
156 124
 </template>
157 125
 
158 126
 <script>
@@ -162,8 +130,16 @@ export default {
162 130
   name: "AreaInfo",
163 131
   data() {
164 132
     return {
133
+      dialogVisible: false,
165 134
       AreaType: [],
166 135
       // 遮罩层
136
+      handler: null,
137
+      map: null,
138
+      polygonTool: null,
139
+      geoJson: {
140
+        type: "Polygon",
141
+        coordinates: [[]],
142
+      },
167 143
       loading: true,
168 144
       // 导出遮罩层
169 145
       exportLoading: false,
@@ -212,6 +188,109 @@ export default {
212 188
     this.getAreaType();
213 189
   },
214 190
   methods: {
191
+
192
+    openPolygonTool() {
193
+      if (this.handler) this.handler.close();
194
+      this.handler = new T.PolygonTool(this.map);
195
+      this.handler.open();
196
+
197
+      this.handler.on("draw", (yu) => {
198
+        // console.log("参数??99", yu.currentLnglats);
199
+        let drawData = yu.currentLnglats.map((item) => {
200
+          return [item.lng, item.lat];
201
+        });
202
+        this.geoJson.coordinates[0] = drawData;
203
+        console.log("区域之后处理数据", this.geoJson.coordinates[0]);
204
+
205
+      });
206
+    },
207
+
208
+    tijiao() {
209
+      console.log('多边形数据:', this.form.location);
210
+
211
+      if (this.geoJson.coordinates[0].length > 0) {
212
+        this.form.location = JSON.stringify(this.geoJson)
213
+      }
214
+
215
+      this.destructionTMap()
216
+      this.dialogVisible = false;
217
+
218
+    },
219
+
220
+    // 销毁天地图
221
+ destructionTMap ()  {
222
+  if (this.map) {
223
+    this.map = null;
224
+    // 直接将节点给删掉
225
+    console.log('1qsad');
226
+    
227
+    const parentEl = document.getElementById('mainMap');
228
+    const cahildrenEl = document.getElementById('mapDiv');
229
+    if(cahildrenEl) parentEl.removeChild(cahildrenEl);
230
+    // 然后再手动将节点加进来
231
+    const newCahildrenEl = document.createElement("div");
232
+    newCahildrenEl.id = 'mapDiv'
233
+    newCahildrenEl.style = 'height: 700px;width: 100%;'
234
+    parentEl.appendChild(newCahildrenEl)
235
+  }
236
+},
237
+
238
+
239
+    clearmian() {
240
+      this.form.location = null
241
+      this.geoJson.coordinates[0] = []
242
+      this.$set(this.form, 'location', null)
243
+      this.map.clearOverLays()
244
+
245
+
246
+    },
247
+
248
+    openditu() {
249
+      console.log('sdasd11');
250
+      this.dialogVisible = true;
251
+
252
+      this.$nextTick(function () {
253
+        var T = window.T;
254
+
255
+        var zoom = 12;
256
+
257
+        this.map = new T.Map('mapDiv');
258
+        this.map.centerAndZoom(new T.LngLat(103.959050, 30.654104), zoom);
259
+
260
+
261
+        var config = {
262
+          showLabel: true,
263
+          color: "red", weight: 2, opacity: 0.5, fillColor: "red", fillOpacity: 0.5
264
+        };
265
+        //创建标注工具对象
266
+        this.polygonTool = new T.PolygonTool(this.map, config);
267
+
268
+
269
+
270
+
271
+
272
+
273
+        console.log('kanknak1', this.form.location);
274
+
275
+
276
+        var points = [];
277
+        JSON.parse(this.form.location).coordinates[0].map((item) => {
278
+          points.push(new T.LngLat(item[0], item[1]));
279
+        })
280
+
281
+        //创建面对象
282
+        var polygon = new T.Polygon(points, {
283
+          color: "red", weight: 2, opacity: 0.5, fillColor: "red", fillOpacity: 0.5
284
+        });
285
+        //向地图上添加面
286
+        this.map.addOverLay(polygon);
287
+
288
+
289
+      });
290
+
291
+
292
+
293
+    },
215 294
     getAreaType() {
216 295
       listAreaType(this.queryAreaTypeParams).then(response => {
217 296
         this.AreaType = response.data.list;
@@ -258,7 +337,7 @@ export default {
258 337
     // 多选框选中数据
259 338
     handleSelectionChange(selection) {
260 339
       this.ids = selection.map(item => item.areaId)
261
-      this.single = selection.length!==1
340
+      this.single = selection.length !== 1
262 341
       this.multiple = !selection.length
263 342
     },
264 343
     /** 新增按钮操作 */
@@ -279,6 +358,8 @@ export default {
279 358
     },
280 359
     /** 提交按钮 */
281 360
     submitForm() {
361
+
362
+      this.form.location = JSON.parse(this.form.location)
282 363
       this.$refs["form"].validate(valid => {
283 364
         if (valid) {
284 365
           if (this.form.areaId != null) {
@@ -300,12 +381,12 @@ export default {
300 381
     /** 删除按钮操作 */
301 382
     handleDelete(row) {
302 383
       const areaIds = row.areaId || this.ids;
303
-      this.$modal.confirm('是否确认删除区域对象编号为"' + areaIds + '"的数据项?').then(function() {
384
+      this.$modal.confirm('是否确认删除区域对象编号为"' + areaIds + '"的数据项?').then(function () {
304 385
         return delAreaInfo(areaIds);
305 386
       }).then(() => {
306 387
         this.getList();
307 388
         this.$modal.msgSuccess("删除成功");
308
-      }).catch(() => {});
389
+      }).catch(() => { });
309 390
     },
310 391
     /** 导出按钮操作 */
311 392
     handleExport() {
@@ -316,7 +397,7 @@ export default {
316 397
       }).then(response => {
317 398
         this.$download.name(response.msg);
318 399
         this.exportLoading = false;
319
-      }).catch(() => {});
400
+      }).catch(() => { });
320 401
     }
321 402
   }
322 403
 };