• vue+高德地图实现区域掩模


    1. <script>
    2. // import { load } from '@amap/jsapi-loader';
    3. // import AMap from 'AMap';
    4. import AMapLoader from '@amap/amap-jsapi-loader';
    5. window._AMapSecurityConfig = {
    6. securityJsCode: "7072e0569cf13eeba7e7dafaa0xxxxxxx",
    7. }
    8. export default {
    9. data() {
    10. return {
    11. map: null,
    12. zoom: 11,
    13. center:[109.839996,19.03557]
    14. // dialogVisible: false,
    15. // details: "",
    16. // pic: "",
    17. };
    18. },
    19. methods: {
    20. initAMap() {
    21. AMapLoader.load({
    22. key: "9da8c54719a33c3352axxxxxxxx", // 申请好的Web端开发者Key,首次调用 load 时必填
    23. version: "1.4.15", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
    24. plugins: ["AMap.Scale", "AMap.ToolBar", "AMap.ControlBar", 'AMap.Geocoder', 'AMap.Marker',
    25. 'AMap.CitySearch', 'AMap.Geolocation', 'AMap.AutoComplete', 'AMap.InfoWindow', 'AMap.DistrictSearch', 'AMap.Object3DLayer'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
    26. }).then((AMap) => {
    27. // 获取到作为地图容器的DOM元素,创建地图实例
    28. this.map = new AMap.Map("container", { //设置地图容器id
    29. resizeEnable: true,
    30. zoom: this.zoom, // 地图显示的缩放级别
    31. viewMode: "3D", // 使用3D视图
    32. zoomEnable: true, // 地图是否可缩放,默认值为true
    33. dragEnable: true, // 地图是否可通过鼠标拖拽平移,默认为true
    34. doubleClickZoom: true, // 地图是否可通过双击鼠标放大地图,默认为true
    35. center: this.center, // 初始化中心点坐标 西安
    36. // mapStyle: "amap://styles/darkblue", // 设置颜色底层
    37. })
    38. var opts = {
    39. subdistrict: 0,
    40. extensions: 'all',
    41. level: 'city'
    42. }
    43. // 利用行政区查询获取边界构建mask路径
    44. // 也可以直接通过经纬度构建mask路径
    45. var district = new AMap.DistrictSearch(opts)
    46. district.search('海南省', function (status, result) {
    47. // console.log("获取到城市信息", status, result);
    48. var bounds = result.districtList[0].boundaries;
    49. // console.log("数据", bounds);
    50. var mask = []
    51. for (var i = 0; i < bounds.length; i += 1) {
    52. mask.push([bounds[i]])
    53. }
    54. var map = new AMap.Map('container', {
    55. mask: mask,
    56. center: [109.839996,19.03557],
    57. disableSocket: true,
    58. viewMode: '3D',
    59. showLabel: false,
    60. labelzIndex: 130,
    61. pitch: 40,
    62. zoom: 8,
    63. layers: [
    64. new AMap.TileLayer.RoadNet({
    65. //rejectMapMask:true
    66. }),
    67. new AMap.TileLayer.Satellite()
    68. ]
    69. });
    70. // var maskerIn = new AMap.Marker({
    71. // position: [116.501415, 39.926055],
    72. // map: map
    73. // })
    74. // var maskerOut = new AMap.Marker({//区域外的不会显示
    75. // position: [117.001415, 39.926055],
    76. // map: map
    77. // })
    78. //添加高度面
    79. var object3Dlayer = new AMap.Object3DLayer({ zIndex: 1 });
    80. map.add(object3Dlayer)
    81. var height = -8000;
    82. var color = '#0088ffcc';//rgba
    83. var wall = new AMap.Object3D.Wall({
    84. path: bounds,
    85. height: height,
    86. color: color
    87. });
    88. wall.transparent = true
    89. object3Dlayer.add(wall)
    90. //添加描边
    91. for (var i = 0; i < bounds.length; i += 1) {
    92. new AMap.Polyline({
    93. path: bounds[i],
    94. strokeColor: '#99ffff',
    95. strokeWeight: 4,
    96. map: map
    97. })
    98. }
    99. });
    100. }).catch(e => {
    101. console.log(e)
    102. })
    103. }
    104. },
    105. mounted() {
    106. this.initAMap()
    107. }
    108. }
    109. script>
    110. <style scoped>
    111. .all {
    112. width: 100%;
    113. height: 100%;
    114. border: 2px solid red;
    115. padding: 15% 0;
    116. margin-top: -10%;
    117. }
    118. #container {
    119. width: 100%;
    120. height: 100%;
    121. background-color: transparent !important;
    122. }
    123. style>

     

  • 相关阅读:
    Python学习日记-第三十八天-生成器
    好用的跨平台同步笔记工具,手机和电脑可同步的笔记工具
    云原生|kubernetes|kubernetes集群使用私有镜像仓库拉取镜像(harbor或者官方的registry私有镜像仓库)
    Lora训练的参数和性能
    37. 干货系列从零用Rust编写负载均衡及代理,负载均衡中try_files实现
    UEFI与 Legacy BIOS两种启动模式详解
    连接数据库报错2003-Can‘t connect to MySQL server on ‘localhost‘(10061)
    《省级国土空间规划编制技术规程》国家标准(GB/T 43214-2023)原文下载
    电脑自动关机是什么原因?解决方案全解析!
    什么是M365 Manager Plus?
  • 原文地址:https://blog.csdn.net/qq_43770056/article/details/139482276