首页 > 其他分享 >Mapbox添加多个不同的点图标

Mapbox添加多个不同的点图标

时间:2024-07-30 18:10:10浏览次数:8  
标签:map index mapboxMap image Mapbox 添加 error data 图标

 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 }

 

标签:map,index,mapboxMap,image,Mapbox,添加,error,data,图标
From: https://www.cnblogs.com/guwufeiyang/p/18333060

相关文章

  • GIS视效升级!零代码添加环境效果,支持多种GIS影像协议
    在当今的数字化时代,GIS(地理信息系统)不再仅仅只能通过一些二维示意图或简陋的三维地形图表示,它可以通过专业的软件简单升级视效。想象一下,在你的GIS场景中,阳光明媚的天气、突如其来的暴风雨、缭绕的晨雾,统统都可以通过零代码的操作轻松实现,而这个效果我是使用一款叫做山海鲸可视化......
  • 新建MRS工程并添加BLE从机功能
    目录使用沁恒的risc-v系列MCU,在MRS编译器中搭建一个工程,主要涉及到链接脚本文件(.ld文件)、头文件(.h文件)、源文件(.c文件)、启动文件(.s文件)、库文件(.a文件)。本文以向新建工程中添加BLE从机功能为例,介绍如何配置各个路径。注:当实在找不到哪里的路径配置出现问题时,一目了然......
  • vue echarts图表添加背景图
    实现效果: 代码实现:varcolor=newecharts.graphic.LinearGradient(0,0,1,0,//这四个参数分别表示渐变的起点(x1,y1)与终点(x2,y2)的位置[{offset:0,color:'green'},//0%处的颜色{offset:0.5,color:'blue'},//50%处......
  • 在 html 上添加 json 数据(数据包含多种特殊字符),使用 JSON.stringify 读取 error
    letjsonObj=[{ "Name":"test" "Attach":"www!@#$%^&*(){}|:\"<>?,./;'[]\\"}]lethtml=jsonObj.map((i,v)=>{ letjsonStr=JSON.stringify(jsonObj) return`<trdata='${json......
  • Tornado 添加任务的几种方式
    add_callback:功能:将一个普通的回调函数或者同步函数添加到事件循环中执行。特点:适合处理简单的任务,但要注意不要添加会阻塞事件循环的任务。示例:tornado.ioloop.IOLoop.current().add_callback(callback_function)spawn_callback:功能:将一个异步的协程函数(coroutinefu......
  • QSplitter添加QLayout,奇怪的现象
    用QSplitter作为容器,直接将QWidget添加到QSplitter中,设置好比例,但是这个QSplitter要作为另一个QWidget的一部分,需要添加到另一个QWidget的布局器中,再将另一个QWidget设置到QTabWidget中,在这个过程中,QSplitter中的QWidget比例发生变化,并不是原来设置的比例,不论界面如何放大缩小,高度......
  • Taro 框架中使用iconfont 阿里巴巴矢量图标 class版
    想必大家都知道这个图标库的图标还是很多的‘大家应该都也用过 最进开发Taro+nut-ui的H5移动端的时候我发现一些图标我在组件库中找不到我看到了nut-ui中还有另一种使用方法这个叫做自定一图标、我来用实际操作代码来介绍一下这个怎么使用 我总结文章......
  • 将dynamicTemplate添加到谷歌云模板启动
    我们使用谷歌云功能通过以下方式启动模板:https://cloud.google.com/dataflow/docs/reference/rest/v1b3/projects.locations.templates/launch我们想添加一个通过具有以下布局的动态模板将请求的暂存位置:DYNAMICTEMPLATE={"gcsPath":GCSPATH,"stagingLocation"......
  • Python:添加到相对于当前运行脚本的 sys.path 的最佳方法
    我有一个充满脚本的目录(比如说project/bin)。我还有一个位于project/lib的库,并希望脚本自动加载它。这是我通常在每个脚本的顶部使用的:#!/usr/bin/pythonfromos.pathimportdirname,realpath,sep,pardirimportsyssys.path.append(dirname(realpath(_......
  • 如何在 python 中为具有不同类型作为值的字典添加类型声明
    我有一个字典如下my_dict={"key_1":"value_1","key_2":{"key_1":True,"key_2":1200}"key_3":True,}并且在我的类中@dataclassclassTestClass:my_dict:typing......