实现效果如图:

代码如下:

<template><div class="screen-container"><div class="map-container"><div class="rlt_btn"><el-button class="btn" type="primary" @click="createclusterLayer('icon_1', 1)">添加点位1</el-button><el-button class="btn" type="primary" @click="createclusterLayer('icon_2', 2)">添加点位2</el-button></div><!-- 超图及echart组件 --><sm-web-map v-if="flag" @load="mapLoad" @click="mapClick" :loading="!flag" :map-options="options"><sm-echarts-layer :options="echartsOptions"></sm-echarts-layer></sm-web-map><!-- 桩位信息浮窗 --><div :style="{ left: pointPosition.x + 160 + 'px', top: (pointPosition.y <= 200 ? 100 : pointPosition.y - 200) + 'px' }"v-if="pointVisible" class="point-info"><div class="pile-point-item" style="height:150px;"><h2 class="pile-name">桩号:{{ pointPosition.data.stake_no }}</h2><p class="road-section">路段:{{ pointPosition.data.highway_service_name }}</p><div class="detail"><p class="lnglat">X经度:{{ pointPosition.data.lng }}</p><p class="lnglat">Y纬度:{{ pointPosition.data.lat }}</p></div></div></div></div></div>
</template><script>
import { HomeApi } from '@/services/Home'
import '@supermap/iclient-mapboxgl';
import { DatasourceService, GetFeaturesByGeometryParameters } from '@supermap/iclient-mapboxgl';
import { gantry, blockList } from '@/assets/json/gantry'
import * as turf from '@turf/turf'
import icon_1 from '@/assets/ali.png'
const icon_2 = 'https://cdn.bootcdn.net/ajax/libs/leaflet/1.0.0/images/marker-icon.png'
export default {data() {return {options: {},echartsOptions: {},flag: false,visible: false,// 超图实例supermapInstance: {},prefix: 'http://localhost:8090/',nearestList: [],symbolSize: 8,pointVisible: false,// 点位位置信息pointPosition: {x: 0,y: 0,data: {}},pos: {x: 0,y: 0},// echart实例echartInstance: {},heatMapLayer: {},clusterLayer: null,//聚合图层};},watch: {},props: {},computed: {},created() {},async mounted() {await this.render()},methods: {// 创建聚合图层createclusterLayer(iconName, index) {let e = this.supermapInstance;if (e.map.getSource(`poidata-${index}`)) {this.removeclusterLayer(index)}let iconMap = {'icon_1': icon_1,'icon_2': icon_2}const icon = iconMap[iconName]var geojson = {"type": "FeatureCollection","features": []};// 后端接口返回点坐标数据geojson.features = [{type: 'Feature',geometry: {type: 'Point',coordinates: [120.02225397864616 + index * 0.1, 30.2407888431817 + index * 0.1]},properties: {title: '点一',id: 1,}},{type: 'Feature',geometry: {type: 'Point',coordinates: [119.978604 + index * 0.1, 30.23495 + index * 0.1]},},{type: 'Feature',geometry: {type: 'Point',coordinates: [119.94344968972486 + index * 0.1, 30.253317832596277 + index * 0.1]},},{type: 'Feature',geometry: {type: 'Point',coordinates: [119.91344968972486 + index * 0.1, 30.273317832596277 + index * 0.1]},}]// 创建聚合图层e.map.addSource(`poidata-${index}`, {type: 'geojson',data: geojson,cluster: true,//最大的聚合级别,超过级别不进行聚合clusterMaxZoom: 12,//聚合的半径,单位是像素 clusterRadius: 80,//最小聚合的点数量clusterMinPoints: 2});e.map.loadImage(icon, function (error, image) {if (error) throw error;e.map.addImage(`custom-icon-${index}`, image);e.map.addLayer({id: `clusters-${index}`,type: "circle",// 第一个图层为circle类型,无需显示图标,目的是根据点位大小创建圆形图层,以供点击聚合点位缩放事件source: `poidata-${index}`,filter: ["has", "point_count"],paint: {"circle-color": ["step",["get", "point_count"],"rgba(0,0,0,0)",100,"rgba(0,0,0,0)",750,"rgba(0,0,0,0)",],"circle-radius": ["step",["get", "point_count"],20,100,30,750,40]}});e.map.addLayer({id: `cluster-count-${index}`,type: "symbol",source: `poidata-${index}`,filter: ["has", "point_count"],layout: {"text-field": "{point_count_abbreviated}","text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],"text-size": 16,// "text-offset": [2, 2], 'icon-image': `custom-icon-${index}`,'icon-size': 0.8,},paint: {"text-color": "#fff","text-translate": [16, -16],"text-halo-color": "#1753aa", // 文本的光晕颜色(可选,默认值为 rgba(0,0,0,0))"text-halo-width": 16, // 文本的光晕宽度(可选,值 >= 0,默认值为 0,单位:像素)// "text-halo-blur": 0, // 文本的光晕模糊宽度(可选,值 >= 0,默认值为 0,单位:像素)}});e.map.addLayer({id: `unclustered-point-${index}`,type: "symbol",source: `poidata-${index}`,filter: ["!", ["has", "point_count"]],layout: {'icon-image': `custom-icon-${index}`,'icon-size': 0.8,}});// 监听聚合图层点击事件// 聚合点点击事件e.map.on('click', `clusters-${index}`, function (el) {console.log(el)var features = e.map.queryRenderedFeatures(el.point, {layers: [`clusters-${index}`]});var clusterId = features[0].properties.cluster_id;e.map.getSource(`poidata-${index}`).getClusterExpansionZoom(clusterId, function (err, zoom) {if (err)return;e.map.flyTo({center: features[0].geometry.coordinates,zoom: zoom});});});// 散点点击事件e.map.on('click', `unclustered-point-${index}`, function (el) {var features = e.map.queryRenderedFeatures(el.point, {layers: [`unclustered-point-${index}`]});console.log(features, '散点点击事件')});e.map.on('mouseenter', `clusters-${index}`, function () {e.map.getCanvas().style.cursor = 'pointer';});e.map.on('mouseleave', `clusters-${index}`, function () {e.map.getCanvas().style.cursor = '';});});},// 清除聚合图层removeclusterLayer(index) {let e = this.supermapInstance;if (e.map.getSource(`poidata-${index}`)) {e.map.removeImage(`custom-icon-${index}`)e.map.removeLayer(`clusters-${index}`)e.map.removeLayer(`cluster-count-${index}`)e.map.removeLayer(`unclustered-point-${index}`)e.map.removeSource(`poidata-${index}`)}},mapClick(e) {this.render()},render() {this.flag = falsethis.echartsOptions = {GLMap: {roam: true},coordinateSystem: 'GLMap',animation: false,series: []}let baseUrl = this.prefix + '/iserver/services/map-hhymap0822/rest/maps/hhy@hhymap'this.options = {container: 'map', // 地图容器 idstyle: {'version': 8,// glyphs为字体文件地址,必填,不然聚合缩放时聚合点位数量字体无法显示"glyphs": "https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China/tileFeature/sdffonts/{fontstack}/{range}.pbf",'sources': {'raster-tiles': {'type': 'raster','tiles': [`${baseUrl}/zxyTileImage.gif?z={z}&x={x}&y={y}&transparent=true`],'tileSize': 256},baseLayer_img: {type: 'raster',tiles: [// process.env.BASE_IMG_API`${baseUrl}/zxyTileImage.gif?z={z}&x={x}&y={y}&transparent=true`],tileSize: 256},baseLayer_vec: {type: 'raster',tiles: [// process.env.BASE_VEC_API`${baseUrl}/zxyTileImage.gif?z={z}&x={x}&y={y}&transparent=true`],tileSize: 256},labelLayer_img: {type: 'raster',tiles: [// process.env.LABEL_IMG_API`${baseUrl}/zxyTileImage.gif?z={z}&x={x}&y={y}&transparent=true`],tileSize: 256},labelLayer_vec: {type: 'raster',tiles: [// process.env.LABEL_VEC_API`${baseUrl}/zxyTileImage.gif?z={z}&x={x}&y={y}&transparent=true`],tileSize: 256}},'layers': [{id: 'baseLayer_img',type: 'raster',source: 'baseLayer_img',minzoom: 0,maxzoom: 12},{id: 'baseLayer_vec',type: 'raster',source: 'baseLayer_vec',minzoom: 12,maxzoom: 18},{id: 'labelLayer_img',type: 'raster',source: 'labelLayer_img',minzoom: 0,maxzoom: 12},{id: 'labelLayer_vec',type: 'raster',source: 'labelLayer_vec',minzoom: 12,maxzoom: 18}]},center: [120.02225397864616, 30.2407888431817], // 地图中心点zoom: 10, // 地图初始缩放级别minZoom: 8,echartsOptions: this.echartsOptions}this.flag = true},getData() {}},};
</script>

SuperMap for MapboxGL 实现自定义图标点位及多点位聚合相关推荐

  1. GIS定位和自定义图标

    开发工具与关键技术:VS软件,GIS定位和自定义图标 作者:陈隆 撰写时间:2020年05月02日 说到GIS可能很多人都很陌生吧,其实只有没接触过的就肯定是不知道这到底是什么来的,可能知道GPS的比 ...

  2. iview weapp icon组件自定义图标 小程序

    写小程序图标没有想要的,需要自定义的时候.可以使用阿里巴巴矢量图标库自定义图标. 找到自己需要的,然后先加入购物车,点开购物车选择下载代码,然后解压压缩包. 复制 iconfont.css中的内容,到 ...

  3. elementUI-添加自定义图标

    elementui的小图标有限,跟UI给的不一样,这个时候咋办呢?百度走起....参考了两篇博主分享的 自定义elementui中的图标 和 建立图标库,这里主要用到第一种 实际中: elementU ...

  4. python图标的演变_把Python脚本生成exe文件并添加版本信息和自定义图标

    pyinstaller和py2exe把Python脚本生成exe文件,并添加版本信息和自定义图标. 写了一个查找产品通道号的小程序,目前还没进行异常处理. 以下是程序源码. # -*- coding: ...

  5. 更换百度地图图标html,百度地图接口,自定义图标,点击切换图标

    这里实现了一个指定地区的地图,自定义图标,点击切换图标 1.[代码][JavaScript]代码 body, html,#allmap {width: 100%;height: 100%;overfl ...

  6. 图标插件java_java – Eclipse插件:标记的自定义图标

    请参阅bug 260909"markerImageProviders扩展点不起作用"(在阅读this thread后找到) Tod Creasey 2009-01-21 07:32 ...

  7. android自定义工具栏,Android工具栏中的自定义图标

    我正在使用支持工具栏中定义一个自定义图标,但唯一显示的图标是左箭头-我尝试以布局和编程方式设置它,但结果是一样的. 这是我的活动 public class MainActivity extends A ...

  8. android百度地图单点定位_Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡...

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...

  9. react ant-design自定义图标

    ant-design给我们提供的图标不够怎么办呢?答案是我们可以自定义图标. 自定义图标也挺简单的,现在图标推荐用svg格式,那么我们就需要制作svg图片. 下面让我们看看如果制作svg图片吧. 1. ...

最新文章

  1. 清朝人如何变戏法?带你来看AI修复的1904年老电影(滑稽慎入)
  2. 安装Mysql与nginx结合的小型服务
  3. 微软4年后重登市值第一,纳德拉如何做到的?
  4. 什么注解可以改变BigDecimal类型的字段返回的小数位数?
  5. Java 算法 特殊的数字四十
  6. 使用阿里云服务器(OOS)实现图片上传
  7. laravel database.php,php Laravel框架学习(一) 之 建立数据库并填充测试数据
  8. [LeetCode]50.Pow(x, n)
  9. 旧物手工机器人制作图片_自制送给小朋友的生日礼物,DIY帅气的不织布机器人...
  10. java做抽奖小程序_随机抽奖小程序
  11. 进销存系统测试实战-功能测试
  12. python word文档合并_[Python 学习笔记]用Python进行docx文档合并
  13. mybatis常用标签
  14. 搭建资金运营体系提高企业的运营能力
  15. 电话聊天狂人 (34 分)
  16. VS Code 报错 local-server-1> ssh child died, shutting down解决方法
  17. 黑镜狗再现!波士顿动力「大黄狗」上岗SpaceX,勘察火箭爆炸现场
  18. expdp和impdp备份数据库(数据泵备份)
  19. C/C++实例goto语句实现“关机代码”
  20. Go语言和Java、python等其他语言的对比分析

热门文章

  1. 墨尘 - UE4 入门教程笔记 —— 二
  2. matlab spline边界约束,三阶样条插值(一阶导数边界条件) matlab程序
  3. HDU 6441 Find Integer
  4. 用ZXING生成二维码的工具类(可以去掉白边,添加logo)
  5. 像扫二维码一样的快速录入银行卡信息
  6. 是否能够成为真正的编程高手,主要是在于是否有毅力坚持学习和练习。输出名言“贵有恒,何必三更起五更睡:最无益,只怕一日曝十日寒。”主要是想让读者激励自己,坚持学习C语言。
  7. itext 5.3.0实现对pdf文件添加(文字和图片)水印
  8. IOS 5 拦截手机短信(需越狱)
  9. MUI初体验 模仿微信页面
  10. FTP上传文件报错200 PORT command successful. Consider using PASV. 553 Could not create file.