• mapboxgl 绘制3d polygon


    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <title>Add a polygon to a map using a GeoJSON sourcetitle>
    6. <meta
    7. name="viewport"
    8. content="initial-scale=1,maximum-scale=1,user-scalable=no"
    9. />
    10. <link
    11. href="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css"
    12. rel="stylesheet"
    13. />
    14. <script src="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js">script>
    15. <script src="./data/js/china.js">script>
    16. <style>
    17. body {
    18. margin: 0;
    19. padding: 0;
    20. }
    21. #map {
    22. position: absolute;
    23. top: 0;
    24. bottom: 0;
    25. width: 100%;
    26. }
    27. style>
    28. head>
    29. <body>
    30. <div id="map">div>
    31. <script>
    32. mapboxgl.accessToken =
    33. "pk.eyJ1IjoibHh0aWFudGlhbiIsImEiOiJjaXd2ZjlkYnQwMTZvMnRtYWZnM2lpbHFvIn0.ef3rFZTr9psmLWahrqap2A";
    34. const map = new mapboxgl.Map({
    35. container: "map", // container ID
    36. style: "mapbox://styles/mapbox/streets-v12", // style URL
    37. center: [105.39, 39.6], // starting position
    38. zoom: 3, // starting zoom
    39. });
    40. resolveChinaJson();
    41. map.on("load", () => {
    42. map.addSource("maine", {
    43. type: "geojson",
    44. data: chinaJson,
    45. });
    46. map.addLayer({
    47. id: "maine",
    48. type: "fill-extrusion",
    49. source: "maine", // reference the data source
    50. layout: {},
    51. paint: {
    52. "fill-extrusion-vertical-gradient": true,
    53. "fill-extrusion-color": ["get", "color"],
    54. // "fill-extrusion-color": '#79D0F0',
    55. "fill-extrusion-height": ["get", "count"],
    56. "fill-extrusion-base": 0,
    57. "fill-extrusion-opacity": 1.0,
    58. },
    59. });
    60. // Add a black outline around the polygon.
    61. // map.addLayer({
    62. // 'id': 'outline',
    63. // 'type': 'line',
    64. // 'source': 'maine',
    65. // 'layout': {},
    66. // 'paint': {
    67. // 'line-color': '#000',
    68. // 'line-width': 3
    69. // }
    70. // });
    71. });
    72. // 获取json数据
    73. function resolveChinaJson () {
    74. const countMap = {
    75. '650000': 300, // 新疆车辆数
    76. '150000': 100, // 内蒙
    77. '370000': 50, // 山东
    78. };
    79. chinaJson.features.forEach(feature => {
    80. feature.properties.color = getRandomColor();
    81. if(countMap[feature.properties.adcode]){
    82. feature.properties.count = 10000 + countMap[feature.properties.adcode] * 1000;
    83. }else{
    84. feature.properties.count = 10000;
    85. }
    86. });
    87. }
    88. // 生成随机颜色
    89. function getRandomColor() {
    90. var letters = "0123456789ABCDEF";
    91. var color = "#";
    92. for (var i = 0; i < 6; i++) {
    93. color += letters[Math.floor(Math.random() * 16)];
    94. }
    95. return color;
    96. }
    97. script>
    98. body>
    99. html>

    效果:

  • 相关阅读:
    开启CentOS/Debian自带的TCP BBR加速
    IPv6进阶:IPv6 过渡技术之 6to4 自动隧道
    excel文档损坏打不开的原因是什么?
    如何选择UMLChina服务
    LabVIEW大量数据的内存管理
    NebulaGraph 的云产品交付实践
    Java 创建事件Event、事件监听EventListener、事件发布publishEvent
    【系统架构设计师考试大纲】
    【C++】继承 ⑧ ( 继承 + 组合 模式的类对象 构造函数 和 析构函数 调用规则 )
    css relative 和absolute布局
  • 原文地址:https://blog.csdn.net/qq_34870529/article/details/132952840