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

商务网站建设与维护论文石家庄专业商城网站制作

商务网站建设与维护论文,石家庄专业商城网站制作,七台河新闻头条最新消息,电商模板免费下载项目演示了如何使用 Turf.js 的 turf.mask() 方法与 OpenLayers 实现地图遮罩布挖洞效果,支持一键生成洞口区域、遮罩布、以及最终合成的遮罩布挖洞图形。📸效果预览(上图为遮罩布在地图上挖出洞后的样式,仅供参考)&am…

项目演示了如何使用 Turf.js 的 turf.mask() 方法与 OpenLayers 实现地图遮罩布挖洞效果,支持一键生成洞口区域、遮罩布、以及最终合成的遮罩布挖洞图形。


📸效果预览


(上图为遮罩布在地图上挖出洞后的样式,仅供参考)


🧩技术栈

  • Vue3 + Composition API

  • OpenLayers(地图库)

  • Turf.js(地理计算库)

  • Element Plus(UI 控件)

  • Autonavi 高德地图瓦片源


✨功能介绍

按钮名称功能描述
绘制小洞使用 turf.polygon 创建一个小洞区域(Polygon)
绘制遮罩布使用 turf.polygon 创建整个大遮罩布区域
合力遮罩打洞使用 turf.mask(洞, 遮罩布) 将遮罩布打上洞
清除图层清除当前地图上的所有遮罩图形


🧠关键逻辑详解

1️⃣ turf.mask 实现遮罩减洞

const maskResult = () => {turfSource.clear()const hole = turf.polygon(holeData)const mask = turf.polygon(maskData)const masked = turf.mask(hole, JSON.parse(JSON.stringify(mask)))show(masked)
}
  • turf.polygon():构建多边形

  • turf.mask():将 mask 多边形“剪掉” hole 区域,返回一个挖好洞的多边形


2️⃣ GeoJSON 与 OpenLayers 特征同步

const show = (geojsonData) => {const features = new GeoJSON().readFeatures(geojsonData, {dataProjection: 'EPSG:4326',featureProjection: 'EPSG:3857',})turfSource.addFeatures(features)
}
  • 使用 GeoJSON 读取并转换为 OpenLayers 能识别的 Feature 实体,投影从 WGS84 转成 EPSG:3857


3️⃣ 样式定义:遮罩区域 + 多边形点位标注

const vectorLayer = new VectorLayer({source: turfSource,style: [new Style({fill: new Fill({ color: 'rgba(255,0,0,0.2)' }),stroke: new Stroke({ width: 2, color: 'blue' })}),new Style({image: new RegularShape({radius: 6,points: 4,rotation: Math.PI / 4,fill: new Fill({ color: 'white' }),stroke: new Stroke({ color: 'red', width: 2 })}),geometry: function (feature) {const coordinates = feature.getGeometry().getCoordinates()[0]return new MultiPoint(coordinates)}})]
})
  • 外层填充透明红色,描边蓝色

  • 顶点采用红白相间的矩形菱形样式标注(辅助观察)


🧪完整示例运行步骤

✅ 1. 安装依赖

npm install ol @turf/turf

✅ 2. 页面引入组件

将源码内容放置于 Vue 页面中(推荐 *.vue 文件中)


📦完整代码

<!--* @Author: 彭麒* @Date: 2025/7/14* @Email: 1062470959@qq.com* @Description: 此源码版权归吉檀迦俐所有,可供学习和借鉴或商用。-->
<template><div class="container"><div class="w-full flex justify-center flex-wrap"><div class="font-bold text-[24px]">Vue3中使用OpenLayers+Turf 实现遮罩布挖洞效果</div></div><div class="flex gap-2 mb-4 w-full justify-center"><el-button type="primary" size="small" @click="drawHole">绘制小洞</el-button><el-button type="primary" size="small" @click="drawMask">绘制遮罩布</el-button><el-button type="primary" size="small" @click="maskResult">合力遮罩打洞</el-button><el-button type="danger" size="small" @click="clearSource">清除图层</el-button></div><div id="vue-openlayers" ref="mapContainer"></div></div>
</template><script setup>
import 'ol/ol.css'
import { ref, onMounted } from 'vue'
import Map from 'ol/Map'
import View from 'ol/View'
import TileLayer from 'ol/layer/Tile'
import XYZ from 'ol/source/XYZ'
import VectorSource from 'ol/source/Vector'
import VectorLayer from 'ol/layer/Vector'
import GeoJSON from 'ol/format/GeoJSON'
import { Fill, Stroke, Style, RegularShape } from 'ol/style'
import { fromLonLat } from 'ol/proj'
import { MultiPoint } from 'ol/geom'
import * as turf from '@turf/turf'const map = ref(null)
const mapContainer = ref(null)const turfSource = new VectorSource({ wrapX: false })const holeData = [[[112, -21],[116, -36],[146, -39],[153, -24],[133, -10],[112, -21]]
]const maskData = [[[90, -55],[170, -55],[170, 10],[90, 10],[90, -55]]
]const show = (geojsonData) => {const features = new GeoJSON().readFeatures(geojsonData, {dataProjection: 'EPSG:4326',featureProjection: 'EPSG:3857',})turfSource.addFeatures(features)
}const clearSource = () => {turfSource.clear()
}const drawHole = () => {const hole = turf.polygon(holeData)show(hole)
}const drawMask = () => {const mask = turf.polygon(maskData)show(mask)
}const maskResult = () => {turfSource.clear()const hole = turf.polygon(holeData)const mask = turf.polygon(maskData)const masked = turf.mask(hole, JSON.parse(JSON.stringify(mask)))show(masked)
}const initMap = () => {const baseLayer = new TileLayer({source: new XYZ({url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=en&size=1&scl=1&style=7'})})const vectorLayer = new VectorLayer({source: turfSource,style: [new Style({fill: new Fill({ color: 'rgba(255,0,0,0.2)' }),stroke: new Stroke({ width: 2, color: 'blue' })}),new Style({image: new RegularShape({radius: 6,points: 4,rotation: Math.PI / 4,fill: new Fill({ color: 'white' }),stroke: new Stroke({ color: 'red', width: 2 })}),geometry: function (feature) {const coordinates = feature.getGeometry().getCoordinates()[0]return new MultiPoint(coordinates)}})]})map.value = new Map({target: mapContainer.value,layers: [baseLayer, vectorLayer],view: new View({projection: 'EPSG:3857',center: fromLonLat([146, -39]),zoom: 2})})
}onMounted(() => {initMap()
})
</script><style scoped>
.container {width: 840px;height: 570px;margin: 50px auto;border: 1px solid #42B983;
}#vue-openlayers {width: 800px;height: 400px;margin: 0 auto;border: 1px solid #42B983;position: relative;
}
</style>

🧭适用场景

  • 土地规划中的“保留区挖空”

  • 可视区域剔除遮罩高亮

  • 城市管理中对敏感区域进行裁剪遮罩

  • GIS 应用中实现地理图层 Mask 操作


✍️结语

本篇展示了如何通过 OpenLayers 与 Turf.js 组合实现地理遮罩布打洞功能。遮罩效果不仅直观,也非常适合拓展复杂图层控制、互动分析等 GIS 需求。

如果你觉得文章对你有帮助,欢迎点赞、评论、收藏!
你也可以关注我,查看更多 Vue3 + OpenLayers + Turf + Cesium 的三维地理可视化实战内容!


文章转载自:

http://A3nbi0WA.rLtmn.cn
http://Vbo97L7H.rLtmn.cn
http://9oj0NGso.rLtmn.cn
http://Plci2gAy.rLtmn.cn
http://hahBuWmO.rLtmn.cn
http://UEqZkjId.rLtmn.cn
http://nT7wo5p2.rLtmn.cn
http://lI6RulQ7.rLtmn.cn
http://sOpreIZZ.rLtmn.cn
http://7bGvgA4C.rLtmn.cn
http://3jJYCG8c.rLtmn.cn
http://NdC9yjur.rLtmn.cn
http://WVcJGc20.rLtmn.cn
http://wcXEnbQU.rLtmn.cn
http://oHkzcE4v.rLtmn.cn
http://ugsMbxG5.rLtmn.cn
http://zHUBWBps.rLtmn.cn
http://2rp6wmc0.rLtmn.cn
http://wiUaah9s.rLtmn.cn
http://VPxqxcMN.rLtmn.cn
http://OWpWvWnV.rLtmn.cn
http://ow9dcqUU.rLtmn.cn
http://CWk78nM8.rLtmn.cn
http://7lCdUe0h.rLtmn.cn
http://fiulBiZB.rLtmn.cn
http://0u95P7Mh.rLtmn.cn
http://oiUxqo9Y.rLtmn.cn
http://WFz0r1Kh.rLtmn.cn
http://m6VJJKPL.rLtmn.cn
http://NZRgriNx.rLtmn.cn
http://www.dtcms.com/wzjs/775194.html

相关文章:

  • 宝塔面板如何安装wordpressseo免费推广软件
  • 学校网站建设对教学的意义口碑好的东莞网站建设
  • 科技部做财务决算的网站是什么wordpress 固定导航
  • 描述建设网站的一个具体步骤团购网站大全做相册
  • 做网站佛山广州邮局网站
  • 网站建设教程在线网站关键词排名消失
  • 建设网站人员制作图片的软件加字
  • wordpress08影视站佛山网站建设专业现状
  • 网站 宗旨led网站建设
  • 网站上的html内容怎么修改西塞山区建设局网站
  • 网站的作用和意义wordpress评论去掉邮箱
  • 建设一个商城式网站可以吗国内无代码和低代码平台
  • 钦州公司做网站慈溪市网站建设
  • 在线自动取名网站怎么做百度seo搜索
  • 合肥seo管理沈阳网页关键词优化
  • 百色建设网站公司宣传一般建的是网页还是网站
  • 找一些好的网站建设案例小型企业网络营销方案
  • 网站开发是用html还是jspwordpress网上在线插件
  • 国内做心理咨询师培训出名的网站自己做的网站403
  • 西安网站建设网wordpress禁止搜索页面
  • 安徽网新科技有限公司 网站开发网站备案填写要求吗
  • vs做网站登录界面大型网站的空间
  • wordpress 网站提速无锡自助做网站
  • 如何自建网站做外贸文化馆建设网站
  • 如何购买网站流量电子图书网站开发的目的
  • “网站制作”做企业网站设计
  • 做网站软件图标是一个箭头的织梦手机端网站怎么做
  • 门户网站建设与运行情况良好wordpress 数据导入
  • 淘宝电子网站建设论文高端画册定制印刷公司
  • 贵州做网站的公司域名怎么查