• 【高德】改变地图的背景色为自定义样式


     也就是说,地图的背景色是透明的,然后放地图的盒子有背景色,或者放图片

    第一步:创建自定义地图 

    模板的话就自己随便选择一个就行 

      

     

     第二步:修改样式

    如果对于省界线需要改变颜色的,也可以进行更改 

     

     第三步:代码

    public》index.html(记得该你的key)

    1. src="https://webapi.amap.com/maps?v=1.4.15&key=你的key&plugin=Map3D,AMap.DistrictLayer,AMap.Scale,AMap.ToolBar">
    2. <script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/data/china-pp.js">script>

    页面(记得改你的key和秘钥)

    1. <template>
    2. <div id="dashboard" class="dashboard-container">
    3. <div class="dian">
    4. <div id="ditu" class="dituBox">div>
    5. div>
    6. div>
    7. template>
    8. <script type="text/javascript">
    9. window._AMapSecurityConfig = {
    10. securityJsCode: "95dcc8d3a56f8e0f6804bfdf8f8aaa21",
    11. };
    12. script>
    13. <script>
    14. import { mapGetters } from "vuex";
    15. import MapLoader from "@/filters/AMap";
    16. let map;
    17. export default {
    18. name: "Dashboard",
    19. computed: {
    20. ...mapGetters(["name"]),
    21. },
    22. data () {
    23. return {
    24. };
    25. },
    26. created () {
    27. MapLoader().then(() => {
    28. this.initmap("中华人民共和国"); //海量点
    29. });
    30. },
    31. methods: {
    32. initmap (city) {
    33. //密钥
    34. window._AMapSecurityConfig = {
    35. securityJsCode: "4dbb42c683243ff4538d3e9689abf102",
    36. };
    37. var disCountry = new AMap.DistrictLayer.Country({
    38. // zIndex: 10,
    39. // SOC: "CHN",
    40. // depth: 1,
    41. styles: {
    42. // "nation - stroke": "#fff",
    43. // "coastline - stroke": "#fff",
    44. // "province - stroke": "#fff",
    45. "fill": function (props) {
    46. // return 'rgba(255, 255, 255, 0.9)'
    47. return 'rgba(0,0,0, 0)' //修改地图的颜色为透明色
    48. }
    49. }
    50. })
    51. // 创建地图
    52. map = new AMap.Map("ditu", {
    53. layers: [disCountry],
    54. zoom: 4,
    55. zooms: [4, 10],
    56. center: [104.884436, 33.915085],
    57. resizeEnable: true,
    58. showIndoorMap: false,
    59. mapStyle: "amap://styles/183d28f9e6ad5076bc7c4924ac9c606f",
    60. features: ["point", "road", "bg"], //地图要素
    61. viewMode: "2D",
    62. pitch: 45,
    63. zoomEnable: true,
    64. });
    65. // map.addControl(new AMap.Scale());
    66. // map.addControl(new AMap.ToolBar({ liteStyle: true }));
    67. // map.on('complete', function () {
    68. // var layer = new AMap.LabelsLayer({
    69. // // 开启标注避让,默认为开启,v1.4.15 新增属性
    70. // collision: false,
    71. // // 开启标注淡入动画,默认为开启,v1.4.15 新增属性
    72. // animation: true,
    73. // });
    74. // for (var i = 0; i < LabelsData.length; i++) {
    75. // var labelsMarker = new AMap.LabelMarker(LabelsData[i]);
    76. // layer.add(labelsMarker);
    77. // }
    78. // map.add(layer);
    79. // })
    80. },
    81. }
    82. }
    83. script>
    84. <style lang="scss" scoped>
    85. .dian {
    86. // background-image: url('../../assets/404_images/404.png');
    87. background-color: aquamarine;
    88. .dituBox {
    89. width: 80%;
    90. height: 1000px;
    91. background-color: transparent !important;
    92. }
    93. }
    94. style>

    封装MapLoader 方法(记得改你的key)

    1. // AMap.js
    2. // 高德map https://webapi.amap.com/maps?v=1.4.11&key=你的高德地图的key
    3. export default function MapLoader () {
    4. return new Promise((resolve, reject) => {
    5. if (window.AMap) {
    6. resolve(window.AMap)
    7. } else {
    8. var script = document.createElement('script')
    9. script.type = 'text/javascript'
    10. script.async = true
    11. script.src = 'https://webapi.amap.com/maps?v=2.0&callback=initAMap&key=你的key'
    12. script.onerror = reject
    13. document.head.appendChild(script)
    14. }
    15. window.initAMap = () => {
    16. resolve(window.AMap)
    17. }
    18. })
    19. }

  • 相关阅读:
    C++ - 一些特殊类的设计
    Visual Stdio 2019 win10 64bit下 无法找到 资源编译器DLL,请确认路径是否正确,和无法下载 win10SDK_10.0
    0基础学习PyFlink——模拟Hadoop流程
    z-library应急办法
    Swin Transformer:最佳论文,准确率和性能双佳的视觉Transformer | ICCV 2021
    NodeJs 面试题 2022.6
    大话CAS
    深度学习的模型剪枝
    集成经验模态(EEMD)原理详解与python实现
    C++ | 类继承
  • 原文地址:https://blog.csdn.net/Qxn530/article/details/127850487