Showing
3 changed files
with
693 additions
and
1 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2023-05-29 11:10:19 | 2 | * @Date: 2023-05-29 11:10:19 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-03-21 17:19:14 | 4 | + * @LastEditTime: 2024-09-14 14:23:54 |
| 5 | * @FilePath: /map-demo/src/route.js | 5 | * @FilePath: /map-demo/src/route.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -41,4 +41,11 @@ export default [ | ... | @@ -41,4 +41,11 @@ export default [ |
| 41 | title: '工具地图', | 41 | title: '工具地图', |
| 42 | }, | 42 | }, |
| 43 | }, | 43 | }, |
| 44 | + { | ||
| 45 | + path: '/bieyuan/map', | ||
| 46 | + component: () => import('@/views/bieyuan/map.vue'), | ||
| 47 | + meta: { | ||
| 48 | + title: '地图', | ||
| 49 | + }, | ||
| 50 | + } | ||
| 44 | ]; | 51 | ]; | ... | ... |
src/views/bieyuan/map.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2023-05-19 14:54:27 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2024-09-14 17:35:43 | ||
| 5 | + * @FilePath: /map-demo/src/views/bieyuan/map.vue | ||
| 6 | + * @Description: 公众地图主体页面 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div ref="root" style="height: 100vh; position: relative; overflow: hidden;"> | ||
| 10 | + <div id="container"></div> | ||
| 11 | + </div> | ||
| 12 | +</template> | ||
| 13 | + | ||
| 14 | +<script> | ||
| 15 | +// import { mapState } from 'vuex' | ||
| 16 | +import coord from '@/common/map_data' | ||
| 17 | +import my_router from '@/common/my_router' | ||
| 18 | +import _ from 'lodash'; | ||
| 19 | +import $ from 'jquery'; | ||
| 20 | +import { useRect } from '@vant/use'; | ||
| 21 | +import { mapAPI } from '@/api/map.js' | ||
| 22 | +import wx from 'weixin-js-sdk' | ||
| 23 | + | ||
| 24 | +const GPS = { | ||
| 25 | + PI: 3.14159265358979324, | ||
| 26 | + x_pi: 3.14159265358979324 * 3000.0 / 180.0, | ||
| 27 | + delta: function (lat, lon) { | ||
| 28 | + var a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。 | ||
| 29 | + var ee = 0.00669342162296594323; // ee: 椭球的偏心率。 | ||
| 30 | + var dLat = this.transformLat(lon - 105.0, lat - 35.0); | ||
| 31 | + var dLon = this.transformLon(lon - 105.0, lat - 35.0); | ||
| 32 | + var radLat = lat / 180.0 * this.PI; | ||
| 33 | + var magic = Math.sin(radLat); | ||
| 34 | + magic = 1 - ee * magic * magic; | ||
| 35 | + var sqrtMagic = Math.sqrt(magic); | ||
| 36 | + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI); | ||
| 37 | + dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI); | ||
| 38 | + return { | ||
| 39 | + 'lat': dLat, | ||
| 40 | + 'lon': dLon | ||
| 41 | + }; | ||
| 42 | + }, | ||
| 43 | + //WGS-84 to GCJ-02 | ||
| 44 | + gcj_encrypt: function (wgsLat, wgsLon) { | ||
| 45 | + if (this.outOfChina(wgsLat, wgsLon)) | ||
| 46 | + return { | ||
| 47 | + 'lat': wgsLat, | ||
| 48 | + 'lon': wgsLon | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + var d = this.delta(wgsLat, wgsLon); | ||
| 52 | + return { | ||
| 53 | + 'lat': wgsLat + d.lat, | ||
| 54 | + 'lon': wgsLon + d.lon | ||
| 55 | + }; | ||
| 56 | + }, | ||
| 57 | + outOfChina: function (lat, lon) { | ||
| 58 | + if (lon < 72.004 || lon > 137.8347) | ||
| 59 | + return true; | ||
| 60 | + if (lat < 0.8293 || lat > 55.8271) | ||
| 61 | + return true; | ||
| 62 | + return false; | ||
| 63 | + }, | ||
| 64 | + transformLat: function (x, y) { | ||
| 65 | + var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); | ||
| 66 | + ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0; | ||
| 67 | + ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0; | ||
| 68 | + ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0; | ||
| 69 | + return ret; | ||
| 70 | + }, | ||
| 71 | + transformLon: function (x, y) { | ||
| 72 | + var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); | ||
| 73 | + ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0; | ||
| 74 | + ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0; | ||
| 75 | + ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0; | ||
| 76 | + return ret; | ||
| 77 | + } | ||
| 78 | +}; | ||
| 79 | + | ||
| 80 | +export default { | ||
| 81 | + components: { }, | ||
| 82 | + data() { | ||
| 83 | + return { | ||
| 84 | + map: '', | ||
| 85 | + geolocation: '', | ||
| 86 | + current_lng: '', | ||
| 87 | + current_lat: '', | ||
| 88 | + dialog_show: false, | ||
| 89 | + dialog_text: '', | ||
| 90 | + location_marker: '', | ||
| 91 | + itemInfo: {}, | ||
| 92 | + navBarList: [], | ||
| 93 | + navList: [], | ||
| 94 | + navKey: '', | ||
| 95 | + markerSum: [], // marker合集 | ||
| 96 | + mapTiles: [], | ||
| 97 | + data_center: [], // 接口获取-地图中心点 | ||
| 98 | + data_zoom: '', // 接口获取-地图默认缩放 | ||
| 99 | + data_zooms: '', // 接口获取-地图默认缩放范围 | ||
| 100 | + data_rotation: 0, // 接口获取-地图旋转角度 | ||
| 101 | + data_paths: {}, // 接口获取-地图导航路径 | ||
| 102 | + data_path_list: [], // 接口获取-地图导航路径 | ||
| 103 | + } | ||
| 104 | + }, | ||
| 105 | + async mounted() { | ||
| 106 | + const code = this.$route.query.id; | ||
| 107 | + const { data } = await mapAPI({ i: code }); | ||
| 108 | + this.navBarList = data.list; // 底部导航条 | ||
| 109 | + this.mapTiles = data.level; // 获取图层 | ||
| 110 | + this.navKey = data.list[0]['id']; // 默认选中 第一个 id | ||
| 111 | + this.navList = data.list.filter(item => item.id === this.navKey)[0]['list']; // 返回默认选中项的实体信息 | ||
| 112 | + this.data_center = data.map.center.map(item => Number(item)); // 地图中心点 | ||
| 113 | + this.data_zoom = data.map.zoom; // 地图默认缩放 | ||
| 114 | + this.data_rotation = data.map.rotation; // 地图旋转角度 | ||
| 115 | + this.data_zooms = data.map.zooms.map(item => Number(item)); // 地图默认缩放范围 | ||
| 116 | + this.data_paths = data.map.path ? data.map.path : {}; // 地图默认导航路径 | ||
| 117 | + if (data.map.path) { | ||
| 118 | + for (const key in data.map.path) { | ||
| 119 | + const element = data.map.path[key]; | ||
| 120 | + this.data_path_list.push({ | ||
| 121 | + name: key, | ||
| 122 | + path: element, | ||
| 123 | + status: true | ||
| 124 | + }) | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + // 初始化地图 | ||
| 128 | + this.initMap(); | ||
| 129 | + // this.setMapBoundary(); | ||
| 130 | + // 使用之前获取当前地址,判断当前是否能够获取经纬度 | ||
| 131 | + wx.getLocation({ | ||
| 132 | + type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' | ||
| 133 | + success: (res) => { | ||
| 134 | + var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 | ||
| 135 | + var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | ||
| 136 | + var speed = res.speed; // 速度,以米/每秒计 | ||
| 137 | + var accuracy = res.accuracy; // 位置精度 | ||
| 138 | + this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon; | ||
| 139 | + this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat; | ||
| 140 | + }, | ||
| 141 | + }); | ||
| 142 | + // 设置贴片地图 | ||
| 143 | + this.setTitleLayer(); | ||
| 144 | + }, | ||
| 145 | + watch: { | ||
| 146 | + }, | ||
| 147 | + methods: { | ||
| 148 | + initMap() { | ||
| 149 | + // 初始化地图 | ||
| 150 | + this.map = new AMap.Map('container', { | ||
| 151 | + viewMode: '2D', // 设置地图模式 | ||
| 152 | + turboMode: false, | ||
| 153 | + showIndoorMap: false, | ||
| 154 | + defaultCursor: 'pointer', // 地图默认鼠标样式 | ||
| 155 | + showBuildingBlock: false, // 是否展示地图 3D 楼块 | ||
| 156 | + zooms: this.data_zooms, // 地图显示的缩放级别范围, 默认为 [2, 20] ,取值范围 [2 ~ 30] | ||
| 157 | + showLabel: true, // 是否展示地图文字和 POI 信息 | ||
| 158 | + zoom: this.data_zoom, // 设置地图显示的缩放级别 | ||
| 159 | + pitch: 0, // 俯仰角度,默认 0,最大值根据地图当前 zoom 级别不断增大,2D地图下无效 。 | ||
| 160 | + rotation: this.data_rotation, // 地图顺时针旋转角度,取值范围 [0-360] ,默认值:0 | ||
| 161 | + center: this.data_center, // 设置地图中心点坐标 | ||
| 162 | + forceVector: false, | ||
| 163 | + // rotateEnable: true, | ||
| 164 | + layers: [ | ||
| 165 | + // new AMap.TileLayer.RoadNet(), | ||
| 166 | + ], | ||
| 167 | + features: ['bg', 'road'], // 设置地图上显示的元素种类 | ||
| 168 | + animateEnable: false, // 地图平移过程中是否使用动画 | ||
| 169 | + resizeEnable: true, | ||
| 170 | + }); | ||
| 171 | + // 添加地图点击事件 | ||
| 172 | + this.map.on("click", this.showInfoClick); | ||
| 173 | + // 加载景点图层 | ||
| 174 | + this.loadMaker(this.navKey); | ||
| 175 | + // | ||
| 176 | + this.map.setRotation(this.data_rotation, true); | ||
| 177 | + }, | ||
| 178 | + loadMaker(id) { | ||
| 179 | + var zoomStyleMapping = { 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0 }; | ||
| 180 | + const entity_info = this.navBarList.filter(item => item.id === id)[0]['list']; | ||
| 181 | + this.markerSum = []; | ||
| 182 | + _.each(entity_info, (x, i) => { | ||
| 183 | + let marker_icon = ''; | ||
| 184 | + if (entity_info[i].window_type === 'warn' && entity_info[i].details.length === 1) { // 如果是预警类型并且内部预警项目只有一个取details第一个icon | ||
| 185 | + marker_icon = entity_info[i].details[0]['icon']; | ||
| 186 | + } else { | ||
| 187 | + marker_icon = entity_info[i].icon; | ||
| 188 | + } | ||
| 189 | + if (entity_info[i]?.writing_mode === 'vertical') { // 标题文字垂直 | ||
| 190 | + var textMarker = new AMap.Text({ | ||
| 191 | + zooms: [18, 20], // 点标记显示的层级范围,超过范围不显示。 | ||
| 192 | + text: entity_info[i].name, //标记显示的文本内容 | ||
| 193 | + anchor: "center", //设置文本标记锚点位置 | ||
| 194 | + // draggable: true, //是否可拖拽 | ||
| 195 | + // cursor: "pointer", //指定鼠标悬停时的鼠标样式。 | ||
| 196 | + // angle: 10, //点标记的旋转角度 | ||
| 197 | + style: { | ||
| 198 | + //设置文本样式,Object 同 css 样式表 | ||
| 199 | + "padding": ".5rem .2rem .5rem .2rem", | ||
| 200 | + // "margin-bottom": "1rem", | ||
| 201 | + // "border-radius": ".25rem", | ||
| 202 | + "background-color": "#965f13", | ||
| 203 | + // "width": "1rem", | ||
| 204 | + // "border-width": 0, | ||
| 205 | + // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)", | ||
| 206 | + // "text-align": "center", | ||
| 207 | + "font-size": "0.8rem", | ||
| 208 | + "color": "white", | ||
| 209 | + "writing-mode": "vertical-rl", | ||
| 210 | + "text-orientation": "mixed", | ||
| 211 | + "display": "flex", | ||
| 212 | + "justify-content": "center", | ||
| 213 | + "align-items": "center", | ||
| 214 | + }, | ||
| 215 | + position: entity_info[i].position, //点标记在地图上显示的位置 | ||
| 216 | + }); | ||
| 217 | + if (clickListener1) { | ||
| 218 | + textMarker.off('click', clickListener) | ||
| 219 | + } | ||
| 220 | + // 绑定景点的点击事件 - 文字出现才能触发 | ||
| 221 | + var clickListener1 = textMarker.on('click', (e) => { | ||
| 222 | + // console.warn(e); | ||
| 223 | + this.itemInfo = entity_info[i]; | ||
| 224 | + // 不同弹框类型 | ||
| 225 | + // if (entity_info[i].window_type === 'normal') { | ||
| 226 | + // this.showInfoPopup = true; | ||
| 227 | + // } else if (entity_info[i].window_type === 'lite') { | ||
| 228 | + // this.showInfoLitePopup = true; | ||
| 229 | + // } else if (entity_info[i].window_type === 'warn') { | ||
| 230 | + // this.showInfoWarnPopup = true; | ||
| 231 | + // } | ||
| 232 | + // 修改文本的样式 | ||
| 233 | + textMarker.setStyle({ | ||
| 234 | + 'font-size': '20px', // 修改字体大小 | ||
| 235 | + 'color': '#ff0000', // 修改字体颜色 | ||
| 236 | + 'background-color': '#0000ff', // 修改背景颜色 | ||
| 237 | + 'border': '1px solid #fff', // 增加边框 | ||
| 238 | + 'padding': '10px', // 调整内边距 | ||
| 239 | + 'border-radius': '10px' // 调整圆角 | ||
| 240 | + }); | ||
| 241 | + | ||
| 242 | + // 修改文本内容 | ||
| 243 | + textMarker.setText('样式已修改'); | ||
| 244 | + }) | ||
| 245 | + textMarker.setMap(this.map); //将文本标记设置到地图上 | ||
| 246 | + this.markerSum.push(textMarker); | ||
| 247 | + } | ||
| 248 | + }) | ||
| 249 | + this.map.add(this.markerSum); | ||
| 250 | + }, | ||
| 251 | + isPointInRing() { // 是否在景区范围 | ||
| 252 | + let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [ | ||
| 253 | + [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005] | ||
| 254 | + ]); | ||
| 255 | + return isPointInRing | ||
| 256 | + }, | ||
| 257 | + setLocation() { // 开启定位服务 | ||
| 258 | + // 获取失败 | ||
| 259 | + if (!this.current_lng || !this.current_lat) { | ||
| 260 | + this.dialog_show = true; | ||
| 261 | + this.dialog_text = '获取经纬度失败'; | ||
| 262 | + } | ||
| 263 | + this.getLocation(); | ||
| 264 | + // // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置 | ||
| 265 | + // if (!this.current_lng || !this.current_lat) { | ||
| 266 | + // this.getLocation() | ||
| 267 | + // } else { | ||
| 268 | + // // 判断是否在范围内 | ||
| 269 | + // if (!this.isPointInRing()) { | ||
| 270 | + // this.dialog_show = true; | ||
| 271 | + // this.dialog_text = '您不在景区范围内'; | ||
| 272 | + // } else { | ||
| 273 | + // // this.current_lng = '120.587643' | ||
| 274 | + // // this.current_lat = '31.314853' | ||
| 275 | + // // 使用纠正偏移后的地址,打一个定位标记 | ||
| 276 | + // this.location_marker = new AMap.LabelMarker({ | ||
| 277 | + // icon: { | ||
| 278 | + // image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A.png', | ||
| 279 | + // anchor: 'bottom-center', | ||
| 280 | + // size: [36, 36], | ||
| 281 | + // }, | ||
| 282 | + // position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | ||
| 283 | + // }); | ||
| 284 | + // this.map.add(this.location_marker); | ||
| 285 | + // // 定位到当前位置中心 | ||
| 286 | + // this.map.setZoomAndCenter(this.zoom, [this.current_lng, this.current_lat]); | ||
| 287 | + // } | ||
| 288 | + // } | ||
| 289 | + }, | ||
| 290 | + getLocation() { // 获取经纬度 | ||
| 291 | + // PC端无法获取定位 | ||
| 292 | + // 微信获取地址 | ||
| 293 | + wx.getLocation({ | ||
| 294 | + type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' | ||
| 295 | + success: (res) => { | ||
| 296 | + var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 | ||
| 297 | + var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | ||
| 298 | + var speed = res.speed; // 速度,以米/每秒计 | ||
| 299 | + var accuracy = res.accuracy; // 位置精度 | ||
| 300 | + this.current_lng = GPS.gcj_encrypt(latitude, longitude).lon; | ||
| 301 | + this.current_lat = GPS.gcj_encrypt(latitude, longitude).lat; | ||
| 302 | + // 判断是否在范围内 | ||
| 303 | + if (!this.isPointInRing()) { | ||
| 304 | + this.dialog_show = true; | ||
| 305 | + this.dialog_text = '您不在景区范围内'; | ||
| 306 | + } else { | ||
| 307 | + // 使用纠正偏移后的地址,打一个定位标记 | ||
| 308 | + this.location_marker = new AMap.LabelMarker({ | ||
| 309 | + icon: { | ||
| 310 | + image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A.png', | ||
| 311 | + anchor: 'bottom-center', | ||
| 312 | + size: [36, 36], | ||
| 313 | + }, | ||
| 314 | + position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | ||
| 315 | + }); | ||
| 316 | + this.map.add(this.location_marker); | ||
| 317 | + // 定位到当前位置中心 | ||
| 318 | + this.map.setZoomAndCenter(this.zoom, [this.current_lng, this.current_lat]); | ||
| 319 | + } | ||
| 320 | + }, | ||
| 321 | + complete: () => { | ||
| 322 | + // 获取失败 | ||
| 323 | + if (!this.current_lng || !this.current_lat) { | ||
| 324 | + this.dialog_show = true; | ||
| 325 | + this.dialog_text = '获取经纬度失败'; | ||
| 326 | + } | ||
| 327 | + }, | ||
| 328 | + }); | ||
| 329 | + }, | ||
| 330 | + setZoom(type) { // 设置放大缩小地图 | ||
| 331 | + const zoom = this.map.getZoom(); | ||
| 332 | + if (type === 'plus') { | ||
| 333 | + this.map.setZoom(zoom + 1) | ||
| 334 | + } | ||
| 335 | + if (type === 'minus') { | ||
| 336 | + this.map.setZoom(zoom - 1) | ||
| 337 | + } | ||
| 338 | + }, | ||
| 339 | + computedMapSource(x, y, z) { // 根据图层信息生成图层实际地址 | ||
| 340 | + for (const id in this.mapTiles) { | ||
| 341 | + if (z == id) { | ||
| 342 | + const scope = this.mapTiles[id]; | ||
| 343 | + return scope[`${x}-${y}`] | ||
| 344 | + } | ||
| 345 | + } | ||
| 346 | + }, | ||
| 347 | + setTitleLayer() { // 生成瓦片图 | ||
| 348 | + // 获取瓦片图渲染范围 | ||
| 349 | + function getFirstProperty(obj) { | ||
| 350 | + for (var prop in obj) { | ||
| 351 | + return prop; | ||
| 352 | + } | ||
| 353 | + } | ||
| 354 | + function getLastProperty(obj) { | ||
| 355 | + var props = []; | ||
| 356 | + for (var prop in obj) { | ||
| 357 | + props.push(prop); | ||
| 358 | + } | ||
| 359 | + return props[props.length - 1]; | ||
| 360 | + } | ||
| 361 | + let obj_scope = {}; | ||
| 362 | + for (const key in this.mapTiles) { | ||
| 363 | + const element = this.mapTiles[key]; | ||
| 364 | + let first = getFirstProperty(element).split('-'); | ||
| 365 | + let last = getLastProperty(element).split('-'); | ||
| 366 | + obj_scope[key] = { | ||
| 367 | + x: [first[0], last[0]], | ||
| 368 | + y: [first[1], last[1]] | ||
| 369 | + } | ||
| 370 | + } | ||
| 371 | + const _this = this; | ||
| 372 | + var layer = new AMap.TileLayer.Flexible({ | ||
| 373 | + cacheSize: 50, | ||
| 374 | + opacity: 1, | ||
| 375 | + zIndex: 100, | ||
| 376 | + createTile: function (x, y, z, success, fail) { | ||
| 377 | + // 控制地图等级显示图片范围-过滤不显示的图层渲染 | ||
| 378 | + for (const id in obj_scope) { | ||
| 379 | + if (z == id) { | ||
| 380 | + const scope = obj_scope[id]; | ||
| 381 | + if (x < scope.x[0] || x > scope.x[1]) { | ||
| 382 | + fail() | ||
| 383 | + return; | ||
| 384 | + } | ||
| 385 | + if (y < scope.y[0] || y > scope.y[1]) { | ||
| 386 | + fail() | ||
| 387 | + return; | ||
| 388 | + } | ||
| 389 | + } | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + var img = document.createElement('img'); | ||
| 393 | + img.onload = function () { | ||
| 394 | + success(img) | ||
| 395 | + }; | ||
| 396 | + img.crossOrigin = "anonymous";// 必须添加,同时图片要有跨域头 | ||
| 397 | + img.onerror = function () { | ||
| 398 | + fail() | ||
| 399 | + }; | ||
| 400 | + | ||
| 401 | + // img.src = `images/tiles/${z}/${x}_${y}.png`; | ||
| 402 | + img.src = _this.computedMapSource(x, y, z); | ||
| 403 | + }, | ||
| 404 | + }); | ||
| 405 | + | ||
| 406 | + this.map.addLayer(layer); | ||
| 407 | + | ||
| 408 | + // Canvas作为切片 | ||
| 409 | + var layer1 = new AMap.TileLayer.Flexible({ | ||
| 410 | + // tileSize: 128, | ||
| 411 | + cacheSize: 300, | ||
| 412 | + zIndex: 200, | ||
| 413 | + createTile: function (x, y, z, success, fail) { | ||
| 414 | + var c = document.createElement('canvas'); | ||
| 415 | + c.width = c.height = 256; | ||
| 416 | + | ||
| 417 | + var cxt = c.getContext("2d"); | ||
| 418 | + cxt.font = "15px Verdana"; | ||
| 419 | + cxt.fillStyle = "#ff0000"; | ||
| 420 | + cxt.strokeStyle = "#FF0000"; | ||
| 421 | + cxt.strokeRect(0, 0, 256, 256); | ||
| 422 | + cxt.fillText('(' + [x, y, z].join(',') + ')', 10, 30); | ||
| 423 | + | ||
| 424 | + // 通知API切片创建完成 | ||
| 425 | + success(c); | ||
| 426 | + } | ||
| 427 | + }); | ||
| 428 | + | ||
| 429 | + // layer1.setMap(this.map); | ||
| 430 | + | ||
| 431 | + // TODO: 暂时屏蔽等待数据设置字段 | ||
| 432 | + // 只显示相应区域,移动会回到选定范围 | ||
| 433 | + const id = this.$route.query.id; | ||
| 434 | + if (id === '1759271') { // 定制开发 | ||
| 435 | + this.lockMapBounds() | ||
| 436 | + } | ||
| 437 | + | ||
| 438 | + }, | ||
| 439 | + // 限制地图范围 | ||
| 440 | + lockMapBounds() { | ||
| 441 | + // var bounds = this.map.getBounds(); | ||
| 442 | + var myBounds = new AMap.Bounds( | ||
| 443 | + [117.045587,26.838764], | ||
| 444 | + [117.051081,26.8345723] | ||
| 445 | + ); | ||
| 446 | + | ||
| 447 | + this.map.setLimitBounds(myBounds); | ||
| 448 | + | ||
| 449 | + let list =[ | ||
| 450 | + [117.045598,26.838764], | ||
| 451 | + [117.051075,26.838779], | ||
| 452 | + [117.051075,26.835107], | ||
| 453 | + [117.045598,26.835107] | ||
| 454 | + ] | ||
| 455 | + | ||
| 456 | + // 隐藏边界以外的区域 | ||
| 457 | + let outer = [ | ||
| 458 | + new AMap.LngLat(-360, 90, true), | ||
| 459 | + new AMap.LngLat(-360, -90, true), | ||
| 460 | + new AMap.LngLat(360, -90, true), | ||
| 461 | + new AMap.LngLat(360, 90, true), | ||
| 462 | + ] // 遮盖填充反向 | ||
| 463 | + | ||
| 464 | + let pathArray = [ | ||
| 465 | + outer, | ||
| 466 | + list | ||
| 467 | + ] | ||
| 468 | + | ||
| 469 | + var polygon = new AMap.Polygon({ | ||
| 470 | + pathL: pathArray, | ||
| 471 | + strokeColor: "#fff", | ||
| 472 | + strokeWeight: 2, | ||
| 473 | + fillColor: "#fff", | ||
| 474 | + fillOpacity: 1, | ||
| 475 | + }) | ||
| 476 | + | ||
| 477 | + polygon.setPath(pathArray) | ||
| 478 | + this.map.add(polygon) | ||
| 479 | + | ||
| 480 | + }, | ||
| 481 | + showInfoClick(e) { | ||
| 482 | + // console.log(e); | ||
| 483 | + var zoom = this.map.getZoom(); //获取当前地图级别 | ||
| 484 | + // var text = | ||
| 485 | + // "您在 [" + | ||
| 486 | + // e.lnglat.getLng() + | ||
| 487 | + // "," + | ||
| 488 | + // e.lnglat.getLat() + | ||
| 489 | + // "] 的位置单击了地图!当前层级" + | ||
| 490 | + // zoom; | ||
| 491 | + var text = | ||
| 492 | + "[" + | ||
| 493 | + e.lnglat.getLng() + | ||
| 494 | + "," + | ||
| 495 | + e.lnglat.getLat() + | ||
| 496 | + "]," | ||
| 497 | + console.log(text); | ||
| 498 | + }, | ||
| 499 | + } | ||
| 500 | +} | ||
| 501 | +</script> | ||
| 502 | + | ||
| 503 | +<style lang="less"> | ||
| 504 | +#container { | ||
| 505 | + position: absolute; | ||
| 506 | + top: 0; | ||
| 507 | + left: 0; | ||
| 508 | + right: 0; | ||
| 509 | + bottom: 0; | ||
| 510 | + width: 100%; | ||
| 511 | + height: 100%; | ||
| 512 | +} | ||
| 513 | + | ||
| 514 | +// 遮挡地图logo | ||
| 515 | +.amap-logo { | ||
| 516 | + display: none!important; | ||
| 517 | + visibility: hidden!important; | ||
| 518 | +} | ||
| 519 | + | ||
| 520 | +.amap-copyright { | ||
| 521 | + display: none!important; | ||
| 522 | + visibility: hidden!important; | ||
| 523 | +} | ||
| 524 | + | ||
| 525 | +/* 标记文字样式 */ | ||
| 526 | +.amap-marker-label { | ||
| 527 | + padding: 0.25rem 0.5rem; | ||
| 528 | + width: auto; | ||
| 529 | + border: none; | ||
| 530 | + border-radius: 2px; | ||
| 531 | + background: rgba(86, 65, 23, 0.8); | ||
| 532 | + color: white; | ||
| 533 | +} | ||
| 534 | + | ||
| 535 | +.amap-marker { | ||
| 536 | + .amap-icon { | ||
| 537 | + margin-top: 0.25rem; | ||
| 538 | + } | ||
| 539 | +} | ||
| 540 | + | ||
| 541 | +.input-card { | ||
| 542 | + display: flex; | ||
| 543 | + flex-direction: column; | ||
| 544 | + min-width: 0; | ||
| 545 | + word-wrap: break-word; | ||
| 546 | + background-color: #fff; | ||
| 547 | + background-clip: border-box; | ||
| 548 | + border-radius: .25rem; | ||
| 549 | + width: 20rem; | ||
| 550 | + border-width: 0; | ||
| 551 | + border-radius: 0.4rem; | ||
| 552 | + box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5); | ||
| 553 | + position: fixed; | ||
| 554 | + top: 4rem; | ||
| 555 | + right: 1rem; | ||
| 556 | + -ms-flex: 1 1 auto; | ||
| 557 | + flex: 1 1 auto; | ||
| 558 | + padding: 0.75rem 1.25rem; | ||
| 559 | +} | ||
| 560 | + | ||
| 561 | +.tool-bar-wrapper { | ||
| 562 | + position: absolute; | ||
| 563 | + left: 20px; | ||
| 564 | + bottom: 8rem; | ||
| 565 | + width: 20px; | ||
| 566 | +} | ||
| 567 | + | ||
| 568 | +.nav-bar-wrapper { | ||
| 569 | + position: fixed; | ||
| 570 | + bottom: 0; | ||
| 571 | + left: 0; | ||
| 572 | + height: 5.5rem; | ||
| 573 | + width: 100%; | ||
| 574 | + background-color: white; | ||
| 575 | + text-align: center; | ||
| 576 | + box-shadow: 0 -1px 0 rgba(80, 80, 80, 0.1); | ||
| 577 | + z-index: 999; | ||
| 578 | + // padding: 0.5rem 0; | ||
| 579 | + padding-bottom: 0.5rem; | ||
| 580 | + | ||
| 581 | + .nav-bar-content { | ||
| 582 | + display: flex; | ||
| 583 | + overflow-x: scroll; | ||
| 584 | + overflow-y: hidden; | ||
| 585 | + -webkit-overflow-scrolling: touch; | ||
| 586 | + position: relative; | ||
| 587 | + } | ||
| 588 | + | ||
| 589 | + .item { | ||
| 590 | + padding-top: 0.5rem; | ||
| 591 | + color: #888; | ||
| 592 | + width: 21.5%; | ||
| 593 | + flex-shrink: 0; | ||
| 594 | + padding-top: 1rem; | ||
| 595 | + } | ||
| 596 | + | ||
| 597 | + .checked { | ||
| 598 | + color: #965f13; | ||
| 599 | + } | ||
| 600 | +} | ||
| 601 | + | ||
| 602 | +.safe-route-wrapper { | ||
| 603 | + position: absolute; | ||
| 604 | + bottom: 2rem; | ||
| 605 | + right: 1rem; | ||
| 606 | + background-color: white; | ||
| 607 | +} | ||
| 608 | + | ||
| 609 | +.operate-bar-wrapper { | ||
| 610 | + position: fixed; | ||
| 611 | + left: 20px; | ||
| 612 | + bottom: 6rem; | ||
| 613 | + width: 20px; | ||
| 614 | + height: auto; | ||
| 615 | + z-index: 100; | ||
| 616 | + | ||
| 617 | + .box-wrapper { | ||
| 618 | + display: flex; | ||
| 619 | + flex-direction: column; | ||
| 620 | + align-items: center; | ||
| 621 | + justify-content: center; | ||
| 622 | + | ||
| 623 | + .item { | ||
| 624 | + position: relative; | ||
| 625 | + text-align: center; | ||
| 626 | + font-size: 0.85rem; | ||
| 627 | + width: 2rem; | ||
| 628 | + height: 2rem; | ||
| 629 | + background-color: white; | ||
| 630 | + margin-bottom: 1rem; | ||
| 631 | + border-radius: 50%; | ||
| 632 | + padding: 2.5px; | ||
| 633 | + line-height: 2rem; | ||
| 634 | + } | ||
| 635 | + } | ||
| 636 | +} | ||
| 637 | + | ||
| 638 | +.popup-wrapper { | ||
| 639 | + margin-top: 1rem; | ||
| 640 | + | ||
| 641 | + .title { | ||
| 642 | + font-size: 1.25rem; | ||
| 643 | + margin-bottom: 0.85rem; | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + .content { | ||
| 647 | + line-height: 1.75; | ||
| 648 | + font-size: 0.95rem; | ||
| 649 | + } | ||
| 650 | +} | ||
| 651 | + | ||
| 652 | + | ||
| 653 | +.hideScrollBar::-webkit-scrollbar { | ||
| 654 | + display: none; | ||
| 655 | +} | ||
| 656 | + | ||
| 657 | +.hideScrollBar { | ||
| 658 | + -ms-overflow-style: none; | ||
| 659 | + overflow: -moz-scrollbars-none; | ||
| 660 | +} | ||
| 661 | + | ||
| 662 | +.van-dialog__confirm, | ||
| 663 | +.van-dialog__confirm:active { | ||
| 664 | + color: #AB8F57; | ||
| 665 | +} | ||
| 666 | + | ||
| 667 | +.walk-nav-text { | ||
| 668 | + position: fixed; | ||
| 669 | + bottom: 6rem; | ||
| 670 | + left: 50%; | ||
| 671 | + transform: translate(-50%, -50%); | ||
| 672 | + z-index: 999; | ||
| 673 | + background: rgba(86, 65, 23, 0.8); | ||
| 674 | + color: white; | ||
| 675 | + border-radius: 10px; | ||
| 676 | + padding: 5px 12px; | ||
| 677 | + font-size: 0.8rem; | ||
| 678 | +} | ||
| 679 | +</style> |
| ... | @@ -153,6 +153,12 @@ export default ({ command, mode }) => { | ... | @@ -153,6 +153,12 @@ export default ({ command, mode }) => { |
| 153 | // mono1: path.resolve(__dirname, 'src/packages/mono1/index.html'), | 153 | // mono1: path.resolve(__dirname, 'src/packages/mono1/index.html'), |
| 154 | // mono2: path.resolve(__dirname, 'src/packages/mono2/index.html'), | 154 | // mono2: path.resolve(__dirname, 'src/packages/mono2/index.html'), |
| 155 | }, | 155 | }, |
| 156 | + manualChunks (id) { | ||
| 157 | + if (id.includes('node_modules')) { | ||
| 158 | + return id.toString().split('node_modules/')[1].split('/')[0].toString(); | ||
| 159 | + // return 'vendor'; | ||
| 160 | + } | ||
| 161 | + } | ||
| 156 | }, | 162 | }, |
| 157 | }, | 163 | }, |
| 158 | optimizeDeps: { | 164 | optimizeDeps: { | ... | ... |
-
Please register or login to post a comment