惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
J
Java Code Geeks
博客园_首页
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
Intezer
P
Palo Alto Networks Blog
V
Vulnerabilities – Threatpost
雷峰网
雷峰网
O
OpenAI News
SecWiki News
SecWiki News
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
N
News | PayPal Newsroom
Project Zero
Project Zero
Forbes - Security
Forbes - Security
IT之家
IT之家
A
Arctic Wolf
WordPress大学
WordPress大学
Jina AI
Jina AI
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
博客园 - 聂微东
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
Cloudbric
Cloudbric
G
GRAHAM CLULEY
博客园 - 叶小钗
H
Hacker News: Front Page
腾讯CDC
量子位
Help Net Security
Help Net Security
人人都是产品经理
人人都是产品经理
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
爱范儿
爱范儿
L
Lohrmann on Cybersecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recorded Future
Recorded Future
C
CERT Recently Published Vulnerability Notes

博客园 - 鼓舞飞扬

点表格,某一列出现报错。 qiankun使用关键代码 tinymce富文本编辑器使用 取消上次ajax 在vue项目中取消axios请求(单个和全局) JavaScript中的export、export default、exports和module.exports(export、export default、exports使用详细) 前端经典面试题 白屏优化 全网首发黑马程序员鸿蒙 HarmonyOS NEXT星河版零基础入门到实战,零基础也能快速入门鸿蒙开发教程 vue 图片资源应该如何存放并引入(public、assets)? 自定义树形模糊搜索 mapbox聚合使用自定义图标 Mapbox添加多个不同的点图标 mapbox gl 标注无法显示 报错 Error {message: ‘Unimplemented type: 4‘} mapbox加载图片类型图标 The engine “node“ is incompatible with this module.解决方法 配置镜像 【NPM报错】Node Sass does not yet support your current environment Turf.js简介
mapbox大数据展示
鼓舞飞扬 · 2024-07-29 · via 博客园 - 鼓舞飞扬
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="utf-8">
 5     <title>Mapbox 大数据展示</title>
 6     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
 7     <script src="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js"></script>
 8     <link href="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.css" rel="stylesheet">
 9     <style>
10         body { margin: 0; padding: 0; }
11         #map { position: absolute; top: 0; bottom: 0; width: 100%; }
12     </style>
13 </head>
14 <body>
15 <div id="map"></div>
16 <script>
17     mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN'; // 替换为你的访问令牌
18     var map = new mapboxgl.Map({
19         container: 'map',
20         style: 'mapbox://styles/mapbox/streets-v11',
21         center: [-74.5, 40], // 设置中心点
22         zoom: 9 // 设置缩放级别
23     });
24  
25     // 加载大数据
26     map.on('load', function() {
27         // 添加数据源
28         map.addSource('large-data-source', {
29             type: 'geojson',
30             data: 'https://example.com/path/to/large-data.geojson' // 大数据的 GeoJSON URL
31         });
32  
33         // 添加图层
34         map.addLayer({
35             'id': 'large-data-layer',
36             'type': 'circle',
37             'source': 'large-data-source',
38             'paint': {
39                 'circle-color': '#f00',
40                 'circle-radius': 5
41             }
42         });
43     });
44 </script>
45 </body>
46 </html>

在上述代码中,你需要替换 'YOUR_ACCESS_TOKEN' 为你的 Mapbox 访问令牌,并且将 'https://example.com/path/to/large-data.geojson' 替换为你的大数据 GeoJSON 文件的 URL。

请注意,处理大量数据时,确保 GeoJSON 文件是切片的,或者使用 Mapbox Datasets,这样 Mapbox GL JS 可以优化数据加载和渲染。如果数据量非常大,还可以考虑使用 Mapbox GL JS 的分层数据和视图管理来提高性能。

 1 mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN'; // 替换为你的Mapbox访问令牌
 2 var map = new mapboxgl.Map({
 3   container: 'map',
 4   style: 'mapbox://styles/mapbox/streets-v11',
 5   center: [0, 0], // 初始中心点坐标
 6   zoom: 1 // 初始缩放级别
 7 });
 8  
 9 // 当地图加载完成后
10 map.on('load', function() {
11   // 从后端接口获取数据
12   fetch('YOUR_BACKEND_ENDPOINT') // 替换为你的后端接口URL
13     .then(response => response.json())
14     .then(data => {
15       // 添加GeoJSON数据源
16       map.addSource('points-source', {
17         'type': 'geojson',
18         'data': data // 假设你的后端返回的是GeoJSON格式的点数据
19       });
20  
21       // 添加图层来展示数据
22       map.addLayer({
23         'id': 'points',
24         'type': 'circle',
25         'source': 'points-source',
26         'paint': {
27           'circle-radius': 5, // 点的半径大小
28           'circle-color': '#007cbf' // 点的颜色
29         }
30       });
31     });
32 });
33 </script>
34 </body>
35 </html>
  1 <!DOCTYPE html>
  2 <html xmlns="http://www.w3.org/1999/xhtml">
  3 
  4 <head>
  5     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6     <title>聚类显示</title>
  7     <script include="jquery,papaparse" src="./static/libs/include-lib-local.js"></script>
  8     <script include="" src="./static/libs/include-mapboxgl-local.js"></script>
  9     <link href="./static/demo/mapboxgl/example/style.css" rel="stylesheet" type="text/css" />
 10     <style>
 11         body {
 12             margin: 0;
 13             padding: 0;
 14         }
 15 
 16         #map {
 17             position: absolute;
 18             top: 0;
 19             bottom: 0;
 20             width: 100%;
 21         }
 22     </style>
 23 </head>
 24 
 25 <body>
 26     <div id="map">
 27         <div id="mouse-position">
 28         </div>
 29     </div>
 30     <script>
 31         var tiandituKey = 'f5347cab4b28410a6e8ba5143e3d5a35';
 32         var map = new mapboxgl.Map({
 33             container: 'map',
 34             crs: 'EPSG:4326',
 35             maxBounds: [[-180, -90], [180, 90]],
 36             style: {
 37                 version: 8,
 38                 sources: {
 39                     'tianditu-3857-image': {
 40                         //来源类型为栅格瓦片
 41                         type: 'raster',
 42                         tiles: [
 43                             //来源请求地址,请求天地图提供的全球矢量地图WMTS服务
 44                             'http://t' +
 45                             Math.round(Math.random() * 7) +
 46                             '.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0' +
 47                             '&LAYER=vec&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles' +
 48                             '&TILECOL={x}&TILEROW={y}&TILEMATRIX={z}' +
 49                             '&tk=' +
 50                             tiandituKey
 51                         ],
 52                         //栅格瓦片的分辨率
 53                         tileSize: 256
 54                     }
 55                 },
 56                 layers: [
 57                     {
 58                         id: 'tianditu-3857-image',
 59                         type: 'raster',
 60                         source: 'tianditu-3857-image',
 61                         minzoom: 0,
 62                         maxzoom: 22
 63                     }
 64                 ],
 65                 glyphs: 'http://develop.smaryun.com:6163/igs/rest/mrms/vtiles/fonts/{fontstack}/{range}.pbf'
 66             },
 67             center: [108.95, 34.25],
 68             zoom: 3
 69         });
 70          79         map.on('load', () => {
 80             $.get('../../static/data/geojson/chinaEarthquake.csv', function (response) {
 81                 var dataObj = Papa.parse(response, {
 82                     skipEmptyLines: true,
 83                     header: true
 84                 });
 85 
 86                 var data = dataObj.data;
 87 
 88                 var geojson = {
 89                     type: 'FeatureCollection',
 90                     features: []
 91                 };
 92 
 93                 for (var i = 0; i < data.length; i++) {
 94                     var item = data[i];
 95                     var date = new Date(item.date);
 96                     var year = date.getFullYear();
 97 
 98                     //2w+地震数据
 99                     if (year > 2000 && year < 2015) {
100                         var feature = {
101                             type: 'feature',
102                             geometry: {
103                                 type: 'Point',
104                                 coordinates: []
105                             },
106                             properties: {
107                                 value: parseFloat(item.level)
108                             }
109                         };
110                         feature.geometry.coordinates = [parseFloat(item.X), parseFloat(item.Y)];
111 
112                         geojson.features.push(feature);
113                     }
114                 }
115                 addCluster(geojson);
116             });
117         });
118 
119         function addCluster(geojson) {
120             // map.add
121             map.addSource('earthquakes', {
122                 type: 'geojson',
123                 data: geojson,
124                 cluster: true,
125                 clusterMaxZoom: 14, // 聚合最大级别
126                 clusterRadius: 50 // 聚合半径
127             });
128 
129             map.addLayer({
130                 id: 'clusters',
131                 type: 'circle',
132                 source: 'earthquakes',
133                 filter: ['has', 'point_count'],
134                 paint: {
135                     'circle-color': ['step', ['get', 'point_count'], '#51bbd6', 100, '#f1f075', 750, '#f28cb1'],
136                     'circle-radius': ['step', ['get', 'point_count'], 20, 100, 30, 750, 40],
137                     'circle-stroke-color': '#FFFFFF',
138                     'circle-stroke-width': 5
139                 }
140             });
141 
142             map.addLayer({
143                 id: 'cluster-count',
144                 type: 'symbol',
145                 source: 'earthquakes',
146                 filter: ['has', 'point_count'],
147                 layout: {
148                     'text-field': '{point_count_abbreviated}',
149                     'text-font': ['宋体', '宋体'],
150                     'text-size': 12
151                 }
152             });
153 
154             map.addLayer({
155                 id: 'unclustered-point',
156                 type: 'circle',
157                 source: 'earthquakes',
158                 filter: ['!', ['has', 'point_count']],
159                 paint: {
160                     'circle-color': '#11b4da',
161                     'circle-radius': 4,
162                     'circle-stroke-width': 1,
163                     'circle-stroke-color': '#fff'
164                 }
165             });
166         }
167     </script>
168 </body>
169 
170 </html>