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

推荐订阅源

Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
腾讯CDC
D
Docker
G
Google Developers Blog
D
DataBreaches.Net
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
The Cloudflare Blog
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
量子位
美团技术团队
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 鼓舞飞扬

点表格,某一列出现报错。 qiankun使用关键代码 tinymce富文本编辑器使用 取消上次ajax 在vue项目中取消axios请求(单个和全局) JavaScript中的export、export default、exports和module.exports(export、export default、exports使用详细) 前端经典面试题 白屏优化 全网首发黑马程序员鸿蒙 HarmonyOS NEXT星河版零基础入门到实战,零基础也能快速入门鸿蒙开发教程 vue 图片资源应该如何存放并引入(public、assets)? 自定义树形模糊搜索 mapbox聚合使用自定义图标 mapbox gl 标注无法显示 报错 Error {message: ‘Unimplemented type: 4‘} mapbox加载图片类型图标 mapbox大数据展示 The engine “node“ is incompatible with this module.解决方法 配置镜像 【NPM报错】Node Sass does not yet support your current environment Turf.js简介
Mapbox添加多个不同的点图标
鼓舞飞扬 · 2024-07-30 · via 博客园 - 鼓舞飞扬
 1 // 添加多个点图
 2 function addMorePoint(data){
 3   if(mapboxMap.map.getSource('iconImageCircle')){
 4     mapboxMap.map.removeLayer('iconCircle')
 5     // mapboxMap.map.removeLayer('lineSources')
 6     mapboxMap.map.removeSource('iconImageCircle')
 7     mapboxMap.map.removeImage('first')
 8     mapboxMap.map.removeImage('second')
 9     mapboxMap.map.removeImage('third')
10   }
11   let features = []
12   for (let index = 0; index < data.length; index++){
13     let arrData =JSON.parse(data[index].points).features
14     arrData.forEach(item=>{
15       features.push(item)
16     })
17     // features.push({
18     //   "type": "Feature",
19     //   geometry:JSON.parse(data[index].points),
20     //   properties: {
21     //     ...data[index],
22     //     channelTypeA: data[index].channelType,
23     //     title:data[index].names
24     //   }
25     // })
26   }
27   for (const marker of features) {
28     var el1 = document.createElement('div');
29     new mapboxgl.Marker(el1)
30     .setLngLat(marker.geometry.coordinates)
31   }
32  
33   //加载img
34   mapboxMap.map.loadImage(require(`../assets/img/circle0.png`), function (error, image) {
35     if (error) throw error
36     mapboxMap.map.addImage('first', image, { sdf: false })
37   })
38   mapboxMap.map.loadImage(require(`../assets/img/circle1.png`), function (error, image) {
39     if (error) throw error
40     mapboxMap.map.addImage('second', image, { sdf: false })
41   })
42   mapboxMap.map.loadImage(require(`../assets/img/circle2.png`), function (error, image) {
43     if (error) throw error
44     mapboxMap.map.addImage('third', image, { sdf: false })
45   })
46   mapboxMap.map.loadImage(require(`../assets/img/point1.png`), function (error, image) {
47     if (error) throw error
48     mapboxMap.map.addImage('fourth', image, { sdf: false })
49   })
50   mapboxMap.map.loadImage(require(`../assets/img/point2.png`), function (error, image) {
51     if (error) throw error
52     mapboxMap.map.addImage('fifth', image, { sdf: false })
53   })
54   mapboxMap.map.addSource('iconImageCircle', {
55     type: 'geojson',
56     data: {
57       type: 'FeatureCollection',
58       features:features
59     }
60   });
61   mapboxMap.map.addLayer({
62     id: "iconCircle",
63     type: "symbol",
64     source: 'iconImageCircle', // 对应addSource第一个参数名字
65     layout: {
66       "icon-image": [
67         "case",
68         ['==', ['get', 'channelTypeA'], '51'],
69         'first',
70         ['==', ['get', 'channelTypeA'], '52'],
71         'second',
72         ['==', ['get', 'channelTypeA'], '53'],
73         'third',
74         ['==', ['get', 'channelTypeA'], '54'],
75         'fourth',
76         ['==', ['get', 'channelTypeA'], '55'],
77         'fifth',
78         "buming",
79       ], // 对应addImage()第一个参数名字
80       'text-field': ['get', 'title'],
81       "icon-allow-overlap": true,//如果设置为true,图标依旧显示,即使和已绘制的其他要素有碰撞
82       "icon-ignore-placement": true,//如果设置成true,即使其他要素有碰撞的情况下,依然可以显示
83       "text-allow-overlap": true,//是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
84       "icon-size": 0.8,//图标的大小
85       "text-size": 12,
86     },
87   })
88 }