当前位置: 首页 > wzjs >正文

山东网站定制设计公司网站开发图片

山东网站定制设计公司,网站开发图片,最新的网站建设软件,建设银行网站的特点优势1. 使用场景 在开发WebGIS应用时,我们常需要将自定义UI组件与地图元素结合。本文介绍如何将Vue组件集成到Mapbox/Maplibre的Marker标记点和Popup弹窗中,实现动态交互式的地图功能。 2. 为什么需要特殊处理? 在常规开发中我们大多的处理是 …

1. 使用场景

在开发WebGIS应用时,我们常需要将自定义UI组件与地图元素结合。本文介绍如何将Vue组件集成到Mapbox/Maplibre的Marker标记点和Popup弹窗中,实现动态交互式的地图功能。

2. 为什么需要特殊处理?

在常规开发中我们大多的处理是

const tipsEle = document.createElement("div")tipsEle.setAttribute("class", "tips")tipsEle.style.color = "#e73f32"tipsEle.style.fontSize = "12px"tipsEle.style.fontWeight = "400"tipsEle.innerHTML = "删除"const tipsOption = {element: tipsEle,anchor: "left",offset: [-45, 30],}new maplibregl.Marker(tipsOption).setLngLat(coords).addTo(map)

这样的写法显而易见维护难,调试难,ui在复杂一点复杂程度也跟着上去了,如果换成组件形式的话,所有问题迎刃而解了。

3. 使用createVNode实现

/*** @description: 创建地图Marker 和 Popup 组件, 渲染自定义组件* @author: jihai* @createTime: 2025/03/05 15:05:01*/
import {createVNode, render} from "vue";
import * as maplibregl from 'maplibre-gl';class CreateVNode{declare map:anydeclare coordinates:anydeclare markerComponentId: stringdeclare marker:anydeclare markerElement: anydeclare popupComponentId: stringdeclare popup:anydeclare popupElement: anyconstructor(option: {map: any,coordinates: any}) {const {map, coordinates} = optionthis.map = mapthis.coordinates = coordinatesthis.markerComponentId = `markerComponentId-${performance.now().toString()}`this.marker = nullthis.markerElement = nullthis.popupComponentId = `popupComponentId-${performance.now().toString()}`this.popup = nullthis.popupElement = null}createMarker(options: {component: {component: any, // 自定义vue组件props: any      // 自定义组件props},config?: {offset: number[],anchor: string}}){const { component, config } = optionsconst app = createVNode(component?.component, {data: component?.props})this.markerElement = document.createElement("div")this.markerElement.setAttribute("id", this.markerComponentId)this.marker = new maplibregl.Marker({element: this.markerElement,anchor: config?.anchor ?? 'bottom',offset: config?.offset ?? [0, 0]}).setLngLat(this.coordinates).addTo(this.map)render(app, this.markerElement)}createPopup(options: {component: {component: any, // 自定义vue组件props: any      // 自定义vue组件props},config?: {offset: number[],anchor: string,closeButton: boolean}}){const { component, config } = optionsconst app = createVNode(component?.component, {data: component?.props})this.popupElement = document.createElement("div")this.popupElement.setAttribute("id", this.popupComponentId)this.popup = new maplibregl.Popup({className: 'custom-popup', closeButton: config?.closeButton ?? true, anchor: config?.anchor ?? 'bottom'}).setMaxWidth('none').setOffset(config?.offset ?? [0, 0]) // 这里设置偏移量.setLngLat(this.coordinates).setDOMContent(this.popupElement).addTo(this.map)render(app, this.popupElement)}removeMarker(){if(this.marker){this.marker.remove()}if(this.markerElement){this.markerElement.remove()}}removePopup(){if(this.popup){this.popup.remove()}if(this.popupElement){this.popupElement.remove()}}remove(){this.removeMarker()this.removePopup()}
}export default CreateVNode

4. 使用方法

  // 简单使用 具体使用根据业务场景合理清除图层let marker = new CreateVNode({map: map,coordinates: coordinates})marker.createMarker({component: {component: markerComp,props: markerProps},config: {offset: [0, 120],anchor: 'bottom'}})//  图层清除marker.removeMarker()marker = null

5. 效果展示

红色框里为element组件渲染结果
在这里插入图片描述

http://www.dtcms.com/wzjs/568426.html

相关文章:

  • 如何做百万格子网站网络营销专业就业公司
  • 合肥市建设工程市场价格信息网站用python做的电商网站
  • 文化集团网站模板可画设计软件下载
  • 虚拟体验网站网站正在建设中色综合
  • 云南省建设监理协会网站网站如何备份
  • 深圳市建设局网站首页工信部网站手机备案查询
  • 河北省建设环境备案网站网站建设要考虑哪些方面
  • 垡头街道网站建设兰州市住房建设局网站
  • 网站的标签修改龙江做网站
  • 1997年做网站是什么语言cc域名做门户网站
  • 网站建设的目的与意义是什么超市小程序怎么做
  • 上海网站开发公司哪家好中山推广网站
  • 网页设计网站长沙怎么在ps里做网站设计
  • 宁晋网站建设公司页面设计层级一般控制()层
  • 加密网站如何做企业招聘网站
  • 吉安网站揭阳市建设局网站
  • 南通市建设局网站马建明网络推广有哪些形式
  • 简历网站推荐建设局网站自查自纠
  • 学网站建设需要学多久雄安做网站公司
  • 国开网站怎么做搭建网页整体框架技术
  • 天津网站建设 熊掌号营销型网站建设范文
  • 惠阳网站建设安装wordpress 脚本
  • vscode 网站开发教程成都品牌设计公司有哪些
  • 做ic芯片的要去哪个网站上海个人网站建设
  • 免费做金融网站有哪些东莞大岭山属于哪个镇
  • 中国最大的做网站公司网站设计报告
  • 做微信推送网站平面设计师证报名入口
  • 富通建设工程有限公司网站网站制作及维护合同
  • 旅游网站有哪些功能农业网站建设
  • 温州 网站平面设计提升培训机构