39 openlayers 对接地图图层 绘制点线面圆

前言

这里主要是展示一下 openlayers 的一个基础的使用 

主要是设计 接入地图服务器的 卫星地图, 普通的二维地图, 增加地区标记 

增加 省市区县 的边界标记

基础绘制 点线面园 等等

测试用例

<template><div style="width: 1920px; height:1080px;" ><div class="olMapUsageClass"></div><div class="overdelay1" ref="overdelay1" >this is over delay1</div></div></template><script>import Map from 'ol/Map'import View from 'ol/View'import DragPan from 'ol/interaction/DragPan'import MouseWheelZoom from 'ol/interaction/MouseWheelZoom'import PointerInteraction from 'ol/interaction/Pointer'import GeoJSON from 'ol/format/GeoJSON'import {Tile as TileLayer} from 'ol/layer'import {Vector as VectorLayer} from 'ol/layer'import {Image as ImageLayer} from 'ol/layer'import {Vector as VectorSource} from 'ol/source'import {Feature as Feature} from 'ol'import Point from 'ol/geom/Point'import LineString from 'ol/geom/LineString'import Polygon from 'ol/geom/Polygon'import CircleGeo from 'ol/geom/Circle'import XYZ from "ol/source/XYZ"import ImageStatic from "ol/source/ImageStatic"import {Circle, Fill, Icon, RegularShape, Stroke, Style, Text} from 'ol/style'import Overlay from 'ol/Overlay'import {transformExtent, transform} from "ol/proj"let sichuanJson = require(`../../public/json/sichuan.json`)export default {name: "olMapUsage",components: {},props: {},data() {return {map: null,tdtImgLayer: null,labelLayer: null,overlay: null,};},computed: {},watch: {},created() {},mounted() {this.initMap()this.test01AddBoundsLayer()this.test02AddDtImageLayer()// this.test03AddDtTDLayer()this.test04AddDtLabelLayer()this.test05AddImageLayer()this.test06AddCircleLayer([104.065735, 30.359462])this.test06AddCircleLayer([104.565735, 30.859462], "red")this.test07AddLineLayer()this.test08AddAreaLayer()this.test09AddCircleLayer()// this.test12SetCenterThenAddOverlay()},methods: {initMap() {let center = [104.065735, 30.659462]let projection = "EPSG:4326"let zoom = 10let minZoom = 5let maxZoom = 20const layer = []const view = new View({...(this.viewOptions || {}),projection,center,zoom,minZoom,maxZoom})this.map = new Map({...(this.mapOptions || {}),layers: [].concat(layer),view: view,target: this.$el,controls: [],interactions: [new DragPan(),new MouseWheelZoom(),new PointerInteraction({handleEvent: this.handleEvent})]})},test01AddBoundsLayer() {const source = new VectorSource({})const style = {color: 'rgba(75,165,234,1)', width: '3'}const fill = 'rgba(255,255,255,0)'let parsedStyle = this.parseStyle({style, fill})const boundsLayer = new VectorLayer({zIndex: 1,source,parsedStyle})this.appendBounds2VectorLayer(boundsLayer, sichuanJson)this.map.addLayer(boundsLayer)},test02AddDtImageLayer() {this.tdtImgLayer = new TileLayer({zIndex: 2,source: new XYZ({projection: "EPSG:4326",url: "http://192.168.1.111:8888/tianditu/servlet/GoogleSatelliteMap?x={x}&y={y}&z={z}",}),});this.map.addLayer(this.tdtImgLayer);},test03AddDtTDLayer() {this.tdtImgLayer = new TileLayer({zIndex: 2,source: new XYZ({projection: "EPSG:4326",url: "http://192.168.1.111:8888/tianditu/servlet/GoogleTDMap?x={x}&y={y}&z={z}",}),});this.map.addLayer(this.tdtImgLayer);},test04AddDtLabelLayer() {this.labelLayer = new TileLayer({zIndex: 2,source: new XYZ({projection: "EPSG:4326",url: "http://192.168.1.111:8888/tianditu/servlet/GoogleTransparentMap?x={x}&y={y}&z={z}",}),});this.map.addLayer(this.labelLayer);},test05AddImageLayer() {// let extent = transformExtent([104.065735, 30.659462, 104.165735, 30.759462], "EPSG:4326", "EPSG:4326")let extent = [104.065735, 30.659462, 104.165735, 30.759462]let imageLayer = new ImageLayer({zIndex: 20,source: new ImageStatic({url: "/img/theme/desktop/17.jpg",projection: "EPSG:4326",imageExtent: extent}),});this.map.addLayer(imageLayer);},test06AddCircleLayer(coord, color) {color = color || 'green'let style = new Style({image: new Circle({radius:20,fill: new Fill({color: color})})})let feature = new Feature({geometry: new Point(coord)})feature.setStyle(style)let source = new VectorSource()source.addFeature(feature)let layer = new VectorLayer({zIndex: 20,source: source})this.map.addLayer(layer);},test07AddLineLayer() {let style = new Style({stroke: new Stroke({color: "blue",width: 3})})let feature = new Feature({geometry: new LineString([[104.065735, 30.359462],[104.165735, 30.359462],[104.265735, 30.459462],])})feature.setStyle(style)let source = new VectorSource()source.addFeature(feature)let layer = new VectorLayer({zIndex: 20,source: source})this.map.addLayer(layer);},test08AddAreaLayer() {let style = new Style({fill: new Fill({color: "#ff0000"}),stroke: new Stroke({color: "blue",width: 3})})let feature = new Feature({geometry: new Polygon([[transform([104.065735, 30.559462], "EPSG:4326", "EPSG:4326"),transform([104.165735, 30.559462], "EPSG:4326", "EPSG:4326"),transform([104.165735, 30.659462], "EPSG:4326", "EPSG:4326"),]])})feature.setStyle(style)let source = new VectorSource()source.addFeature(feature)let layer = new VectorLayer({zIndex: 20,source: source})this.map.addLayer(layer);},test09AddCircleLayer() {let style = new Style({fill: new Fill({color: "#ffff00"}),stroke: new Stroke({color: "#00ffff",width: 3})})let feature = new Feature({geometry: new CircleGeo(transform([104.665735, 30.559462], "EPSG:4326", "EPSG:4326"), 0.2)// geometry: new Circle([104.265735, 30.559462], 300)})feature.setStyle(style)let source = new VectorSource()source.addFeature(feature)let layer = new VectorLayer({zIndex: 20,source: source})this.map.addLayer(layer);},test10SetCenter(coord, color) {this.map.getView().setCenter(coord)this.test06AddCircleLayer(coord, color)},test11AddOverlay(coord) {this.overlay && this.map.removeOverlay(this.overlay)this.overlay = new Overlay({element: this.$refs.overdelay1,position: coord,positioning: "bottom-center",offset: [0, 0],autoPan: true,autoPanMargin: 200,autoPanAnimation: {duration: 1000},map: this.map})this.map.addOverlay(this.overlay)},test12SetCenterThenAddOverlay() {// refer cyclethis.test06AddCircleLayer([10.265735, 10.659462], "#007f5a")this.test06AddCircleLayer([105.565735, 30.759462], "#0039ff")let _this = this// use this for map.addOverlay's animation updatesetTimeout(function() {_this.test11AddOverlay([10.065735, 10.459462])_this.test10SetCenter([10.065735, 10.459462], "yellow")}, 2000)// the core case, normal or exception or compensatedsetTimeout(function() {// case1. function of addOverlay_this.test11AddOverlay([105.065735, 30.259462])// case2. normal case// _this.test11AddOverlay([105.065735, 30.259462])// _this.test10SetCenter([105.065735, 30.259462], "red")// case3. exception case// _this.test10SetCenter([105.065735, 30.259462], "red")// _this.test11AddOverlay([105.065735, 30.259462])// case4. compensated case// _this.test10SetCenter([105.065735, 30.259462], "red")// setTimeout(function() {//   _this.test11AddOverlay([105.065735, 30.259462])// }, 1000)}, 5000)},appendBounds2VectorLayer(layer, json) {const geoJson = this.geoJsonDecode(json);let features = new GeoJSON().readFeatures(geoJson) || [];features = features.map(feature => {feature.__vm__ = this;return feature});const source = layer.getSource();source.addFeatures(features)},handleEvent(e) {if (e.type === "pointermove") {return true}console.log(" handle event : ", e)return true},geoJsonDecode(json) {const features = json.features || []features.forEach(feature => {const geometry = feature.geometry || {}const {coordinates, encodeOffsets} = geometryif (!encodeOffsets) returngeometry.coordinates = coordinates.map((coordinate, i) => {if (Array.isArray(coordinate)) {return coordinate.map((item, j) => {return this.decodePolygon(item, encodeOffsets[i][j])})} else {return this.decodePolygon(coordinate, encodeOffsets[i])}})geometry.encodeOffsets = null})return json},decodePolygon(coordinate, encodeOffsets) {const result = [];let prevX = encodeOffsets[0];let prevY = encodeOffsets[1];for (let i = 0; i < coordinate.length; i += 2) {let x = coordinate.charCodeAt(i) - 64;let y = coordinate.charCodeAt(i + 1) - 64;x = (x >> 1) ^ (-(x & 1));y = (y >> 1) ^ (-(y & 1));x += prevX;y += prevY;prevX = x;prevY = y;result.push([x / 1024, y / 1024]);}return result;},parseStyle(settings, StyleModel) {const PROPS_MAP = {fill: Fill,text: Text,stroke: Stroke,circle: Circle,icon: Icon,regularShape: RegularShape,backgroundFill: Fill,backgroundStroke: Stroke}const IMAGE_PROPS = [Circle, Icon, RegularShape]const opts = {};Object.entries(settings).forEach(([key, value]) => {const Model = PROPS_MAP[key];if (key === 'font') {value = `${value} sans-serif`}opts[IMAGE_PROPS.includes(Model) ? 'image' : key] = this.parseValue(Model, key, value)});return new (StyleModel || Style)(opts)},parseValue(Model, key, value) {if (value === undefined || value === null) return;if (!Model) return value;if (['fill', 'backgroundFill'].includes(key)) return this.parseFill(value);if (key === 'text') {return isObject(value) ? parse(value, Model) : value}return parse(value, Model)},parseFill(fill) {const opts = this.isObject(fill) ? fill : {color: fill}return new Fill(opts)},isObject(value) {return typeof value === 'object'}}};
</script><style lang="scss">.olMapUsageClass {}.overdelay1 {position: absolute;border: 1px greenyellow solid;width: 200px;height: 50px;}
</style>

绘制卫星地图 + 地图标注

执行效果如下 

二维地图 + 地图标注

执行效果如下 

二维地图 + 地图边界

执行效果如下 

绘制点线面园 

执行效果如下 

卫星地图 + 地图标注 + 点线面园 

执行效果如下 

完 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/765175.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端canvas项目实战——简历制作网站(六):加粗、斜体、下划线、删除线(上)

目录 前言一、效果展示二、实现步骤1. 视图部分&#xff1a;实现用于切换字体属性的按钮2. 逻辑部分&#xff1a;点击按钮之后要做什么&#xff1f;3. 根据Textbox的属性实时更新按钮的状态 三、Show u the code后记 前言 上一篇博文中&#xff0c;我们实现了对文字的字体、字…

优化选址问题 | 基于灰狼算法求解基站选址问题含Matlab源码

目录 问题代码问题 灰狼优化算法(Grey Wolf Optimizer, GWO)是一种基于自然界中灰狼群体狩猎行为的优化算法。这种算法通过模拟灰狼的社会等级和狩猎行为来寻找问题的最优解。 基站选址问题通常是一个多目标优化问题,涉及到覆盖范围、信号质量、成本等多个因素。使用灰狼算…

web服务架构

1 Web服务器&#xff08;如Nginx、Apache等&#xff09;和Web应用框架&#xff08;如Flask、Django等&#xff09; Web服务器&#xff08;如Nginx、Apache等&#xff09;和Web应用框架&#xff08;如Flask、Django等&#xff09;在Web应用开发和部署中扮演着不同的角色&#xf…

软考中级 --网络工程师真题试卷 2023下半年

在EIGRP协议中&#xff0c;某个路由器收到了两条路径到达目标网络&#xff0c;路径1的带宽为100Mbps&#xff0c;延迟2ms&#xff0c;路径2的带宽为50Mbps&#xff0c;迟为4ms&#xff0c;如果EIGRP使用带宽和延迟的综合度量标准&#xff0c;那么该路由器选择的最佳路径是(D)。…

Codeforces Round 930 (Div. 2)(A,B,C,D)

比赛链接 C是个交互&#xff0c;D是个前缀和加二分。D还是很难写的。 A. Shuffle Party 题意&#xff1a; 您将得到一个数组 a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1​,a2​,…,an​ 。最初&#xff0c;每个 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n 对应 a i i a_ii…

win10 禁止谷歌浏览器自动更新(操作贼简单)

禁止谷歌浏览器自动更新 &#xff08;1&#xff09;修改 "C:\Windows\System32\drivers\etc\hosts 文件&#xff0c;在最后增加 127.0.0.1 update.googleapis.com&#xff08;2&#xff09;保存后&#xff0c;winr 快捷键&#xff0c;输入cmd &#xff0c;打开命令行 &am…

AJAX踩坑指南(知识点补充)

JWT JSON Web Token是目前最为流行的跨域认证解决方案 如何获取&#xff1a;在使用JWT身份验证中&#xff0c;当用户使用其凭据成功登录时&#xff0c;将返回JSON Web Token(令牌&#xff09; Token本质就是一个包含了信息的字符串 如何获取Token:登录成功之后&#xff0c;服务…

Springboot解决跨域问题方案总结(包括Nginx,Gateway网关等)

&#x1f3f7;️个人主页&#xff1a;牵着猫散步的鼠鼠 &#x1f3f7;️系列专栏&#xff1a;Java全栈-专栏 &#x1f3f7;️个人学习笔记&#xff0c;若有缺误&#xff0c;欢迎评论区指正 目录 前言 解决跨域问题方案 1.Spring Boot 中解决跨域 1.1 通过注解跨域 1.2 通…

什么是RabbitMQ的死信队列

RabbitMQ的死信队列&#xff08;Dead Letter Queue&#xff0c;简称DLQ&#xff09;是一种用于处理消息失败或无法路由的消息的机制。它允许将无法被正常消费的消息重新路由到另一个队列&#xff0c;以便稍后进行进一步处理、分析或排查问题。 当消息对立里面的消息出现以下几…

深度学习基础之《TensorFlow框架(10)—案例:实现线性回归(2)》

增加其他功能 一、增加变量显示 1、目的&#xff1a;在TensorBoard当中观察模型的参数、损失值等变量值的变化 2、收集变量 不同的变量要用不同的方式收集 &#xff08;1&#xff09;tf.summary.scalar(name, tensor) 收集对于损失函数和准确率等单值变量&#xff0c;name为…

Spring Boot 自动化单元测试类的编写过程

前言 Web环境模拟测试 企业开发不仅要保障业务层与数据层的功能安全有效&#xff0c;也要保障表现层的功能正常。但是我们一般对表现层的测试都是通过postman手工测试的&#xff0c;并没有在打包过程中代码体现表现层功能被测试通过。那么能否在测试用例中对表现层进行功能测…

LabVIEW高效光伏数据监控与管理系统

LabVIEW高效光伏数据监控与管理系统 随着新能源技术的发展&#xff0c;光伏发电系统作为一种清洁、高效的能源获取方式受到了广泛的关注。但是&#xff0c;由于光伏发电的特性受到多种环境因素的影响&#xff0c;其运行效率和安全性成为了关键问题。因此&#xff0c;开发一个高…

K8S--SpringCloud应用整合Nacos实战

原文网址&#xff1a;K8S--SpringCloud应用整合Nacos实战-CSDN博客 简介 本文介绍K8S部署SpringCloud应用整合Nacos实战。 本文是将原来的SpringCloud项目&#xff08;闪速优选&#xff09;迁移到K8S上&#xff0c;一行代码都不需要改动。用K8S运行Nacos、Gateway、SpringCl…

Mac nvm install failed python: not found

报错 $>./configure --prefix/Users/xxx/.nvm/versions/node/v12.22.12 < ./configure: line 3: exec: python: not found nvm: install v12.22.12 failed!解决方法 到 App 文件夹&#xff0c;并且打开 cd /System/Applications/Utilities/ open .记得改完 Rosetta 之…

模拟-算法

文章目录 替换所有的问号提莫攻击Z字形变换外观数列数青蛙 替换所有的问号 算法思路&#xff1a; 从前往后遍历整个字符串&#xff0c;找到问号之后&#xff0c;就遍历 a ~ z 去尝试替换即可。 class Solution {public String modifyString(String s) {char[] ss s.toCharA…

mac下 3.6.3 版本 maven

问题 Blocked mirror for repositories: [snapshots (http://xxx/artifactory/gm-maven-vir, default, releasessnapshots)]无法访问 Maven 3.8.1 http 仓库。可能的解决方案: - 检查 Maven settings.xml 是否不包含 http 仓库 - 检查 Maven pom 文件是否不包含 http 仓库 htt…

bs4的基本使用

下载基本使用标签定位标签属性定位选择器定位数据的提取 下载 pip install bs4 pip install lxml基本使用 from bs4 import BeautifulSoup #1.创建一个BeautifulSoup的工具对象&#xff0c;然后把即将被解析的页面源码数据加载到该对象中#参数1&#xff1a;被解析的页面源码数…

【STM32嵌入式系统设计与开发】——6矩阵按键应用(4x4)

这里写目录标题 一、任务描述二、任务实施1、SingleKey工程文件夹创建2、函数编辑&#xff08;1&#xff09;主函数编辑&#xff08;2&#xff09;LED IO初始化函数(LED_Init())&#xff08;3&#xff09;开发板矩阵键盘IO初始化&#xff08;ExpKeyBordInit()&#xff09;&…

【管理咨询宝藏56】大型德企业务战略规划报告

本报告首发于公号“管理咨询宝藏”&#xff0c;如需阅读完整版报告内容&#xff0c;请查阅公号“管理咨询宝藏”。 【管理咨询宝藏56】大型德企业务战略规划报告 【格式】PDF 【关键词】战略规划、商业分析、管理咨询 【核心观点】 - 这是一份非常完整的知名德企在华业务战略…

7-Zip 23.00 beta以上版本的压缩包兼容性问题

7-Zip 23.00 beta加入了ARM64 filter&#xff0c;7-Zip 24.02 beta加入了RISCV filter&#xff0c;这两个filter不能在之前的版本解压&#xff0c;这两个filter目前只适用于ARM64/RISCV的扩展名是exe/dll的可执行文件&#xff0c;其中ARM64的exe/dll目前比较常见&#xff0c;RI…