leaflet 移动端h5地图开发(一) 点聚合矢量瓦片(附项目代码和数据)

2024-06-10 07:08

本文主要是介绍leaflet 移动端h5地图开发(一) 点聚合矢量瓦片(附项目代码和数据),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

leaflet 移动端h5地图开发(一) 点聚合&矢量瓦片(附项目代码和数据)

leaflet是一个轻量级的GIS前端框架,支持多种GIS服务(wfs,wms,wmts,arcgis mapserver,mvt矢量切片)。但是leaflet不支持三维,如果不考虑三维的话,leaflet是做移动端h5地图很好的选择。

技术栈

前端 : vue (uniapp) +leaflet

GIS服务器:geoserver

案例项目界面效果(仿高德):

在线预览地址:http://magic1412.gitee.io/h5_leaflet/#/

一、加载点marker,并添加点击事件

运用到markercluster插件实现点的聚合效果

插件地址:https://github.com/Leaflet/Leaflet.markercluster

封装请求wfs服务的函数

requestWFSData = (opts) => {return new Promise((resolve, reject) => {var urlString = opts.root + '/wfs'var param = {service: 'WFS',version: '1.0.0',request: 'GetFeature',typeName: opts.layerId,outputFormat: 'application/json',maxFeatures: 3200,srsName: 'EPSG:4326',}if (opts.cql_filter) param.CQL_FILTER = opts.cql_filteraxios.get(urlString + L.Util.getParamString(param, urlString)).then(res => {if (res.data) {resolve(res)} else {reject('请求wfs错误')}})})
}

将返回的点json,遍历实例化成marker,添加点击事件后,添加至markerClusterGroup中

addMakerLayer = (opts) => {this.requestWFSData(opts).then(res => {if (res.data.features.length > 0) {this._layerDict[opts.layerId] = L.markerClusterGroup({spiderfyOnMaxZoom: false,showCoverageOnHover: false,zoomToBoundsOnClick: false}).addTo(this._map)res.data.features.forEach(f => {var c = f.geometry.coordinatesvar title = f.properties[opts.idField]var marker = L.marker(new L.LatLng(c[0][1], c[0][0]))marker.on('click', evt => {this._map.flyTo(evt.latlng, 16)})marker.bindPopup(title.toString())this._layerDict[opts.layerId].addLayer(marker)})}})
}

二、加载矢量瓦片

使用Leaflet.VectorGrid插件加载geoserver矢量瓦片

插件地址:https://github.com/Leaflet/Leaflet.VectorGrid

addVectorTileLayer = (opts) => {this._layerDict[opts.layerId] = L.vectorGrid.protobuf(opts.url, {rendererFactory: L.canvas.tile,tms: true,interactive: true,vectorTileLayerStyles: opts.vectorTileLayerStyles}).addTo(this._map)
}

实现点击矢量瓦片跳转页面

定义个list,初始化图层时,存储图层信息。

addToClickSearchList = (opts) => {this._clickSearchList.push({root: opts.root, //wfs服务根地址layerId: opts.layerId, //图层ididField: opts.idField, //id字段crs: opts.crs,//坐标系added: true //是否})
}

遍历list,构造crs(坐标系) 和 cql_filter (筛选条件) 参数

getClickFeatrue = (pt) => {if (this._clickSearchList.length === 0) returnif (document.getElementById("popup")) document.getElementById("popup").remove()var content = '<a id="popup" style="text-decoration: underline;cursor: pointer;">'this._clickSearchList.forEach(l => {if (l.added) {var cptif (l.crs === 'EPSG:4326') cpt = L.CRS.EPSG4326.project(pt)if (l.crs === 'EPSG:3857') cpt = L.CRS.EPSG3857.project(pt)l.cql_filter = 'INTERSECTS(geom,POINT(' + cpt.x + ' ' + cpt.y + '))'this.requestWFSData(l).then(res => {if (res.data.features.length !== 0) {var geoObj = L.geoJSON(res.data)content += res.data.features[0].properties[l.idField] + '</a>'this._clickResLayer = geoObj.addTo(this._map)geoObj.bindPopup(content).openPopup()		}})}})
}

三、案例数据

疫情数据:

来源于腾讯疫情小区地图,原接口已不能用,现在的地址是

https://map.wap.qq.com/app/mp/online/h5-epidemic-20200203/OutMapDetail.html?hideBrowserTitle=1

上海小区边界和学校边界(国测局/高德坐标)

扫描关注 “GIS攻城狮” 公众号,回复”上海小区学校边界“,获取数据数据百度云链接
在这里插入图片描述

四、案例项目代码

https://gitee.com/magic1412/h5_leaflet

在这里插入图片描述

这篇关于leaflet 移动端h5地图开发(一) 点聚合矢量瓦片(附项目代码和数据)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1047483

相关文章

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

用Microsoft.Extensions.Hosting 管理WPF项目.

首先引入必要的包: <ItemGroup><PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /><PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /><PackageReference Include="Serilog

eclipse运行springboot项目,找不到主类

解决办法尝试了很多种,下载sts压缩包行不通。最后解决办法如图: help--->Eclipse Marketplace--->Popular--->找到Spring Tools 3---->Installed。

公共筛选组件(二次封装antd)支持代码提示

如果项目是基于antd组件库为基础搭建,可使用此公共筛选组件 使用到的库 npm i antdnpm i lodash-esnpm i @types/lodash-es -D /components/CommonSearch index.tsx import React from 'react';import { Button, Card, Form } from 'antd'

17.用300行代码手写初体验Spring V1.0版本

1.1.课程目标 1、了解看源码最有效的方式,先猜测后验证,不要一开始就去调试代码。 2、浓缩就是精华,用 300行最简洁的代码 提炼Spring的基本设计思想。 3、掌握Spring框架的基本脉络。 1.2.内容定位 1、 具有1年以上的SpringMVC使用经验。 2、 希望深入了解Spring源码的人群,对 Spring有一个整体的宏观感受。 3、 全程手写实现SpringM

【服务器运维】MySQL数据存储至数据盘

查看磁盘及分区 [root@MySQL tmp]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical)

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

代码随想录算法训练营:12/60

非科班学习算法day12 | LeetCode150:逆波兰表达式 ,Leetcode239: 滑动窗口最大值  目录 介绍 一、基础概念补充: 1.c++字符串转为数字 1. std::stoi, std::stol, std::stoll, std::stoul, std::stoull(最常用) 2. std::stringstream 3. std::atoi, std

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开