前端学习openLayers配合vue3(圆形形状的绘制)
上节课我们学了加载了矢量图片,这节我们来学绘制圆形
关键代码,第一段呢是设置圆点的操作,第二步是点击地图获取地图位置来设置圆点,ol还有很多类,各种形状的
//设置圆点
// let anchorLayer = new VectorLayer({
// source: new VectorSource(),
// });
// let anchorFeatures = new Feature({
// geometry: new Point(center),
// }); // anchorFeatures.setStyle(
// new Style({
// image: new Circle({
// radius: 5,
// fill: new Fill({ color: "red" }),
// stroke: new Stroke({ color: "black", width: 1 }),
// }),
// })
// );
// anchorLayer.getSource().addFeature(anchorFeatures);
// map.addLayer(anchorLayer);
let layer = new VectorLayer({
source: new VectorSource(),
});
map.addLayer(layer);
map.on("click", function (e) {
// 点击图层获取相对的位置进行相关圆点的新增
let position = e.coordinate;
let feature = new Feature({
geometry: new Point(position),
});
feature.setStyle(
new Style({
image: new Circle({
radius: 5,
fill: new Fill({ color: "blue" }),
stroke: new Stroke({ color: "black", width: 1 }),
}),
})
);
layer.getSource().addFeature(feature);
});
效果图

完整代码
<script setup>
import { onMounted, reactive, ref } from "vue";
import { Feature, Map, View } from "ol";
import TileLayer from "ol/layer/Tile";
import { OSM, XYZ } from "ol/source";
import { fromLonLat } from "ol/proj";
import VectorLayer from "ol/layer/Vector";
import VectorSource from "ol/source/Vector";
import GeoJSON from "ol/format/GeoJSON";
import Style from "ol/style/Style";
import Fill from "ol/style/Fill";
import Stroke from "ol/style/Stroke";
import Icon from "ol/style/Icon";
import { Point } from "ol/geom";
import { Circle } from "ol/style"; defineProps({
msg: String,
});
let map = reactive({});
let view = reactive({});
// let count=ref(0)
// let center=[114.305469, 30.592876];
let center = reactive([114.305469, 30.592876]);
onMounted(() => {
initMap();
});
let initMap = () => {
(view = new View({
center,
zoom: 5,
projection: "EPSG:4326",
})),
(map = new Map({
target: "map", //挂载视图的容器
layers: [
//瓦片图层source第三方,或者自带的,地图的底层
new TileLayer({
// source: new OSM(),//内置的国外地址,需要代理
source: new XYZ({
url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7",
}), //国内第三方数据源
}),
// 矢量图层
new VectorLayer({
source: new VectorSource({
url: "https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json",
format: new GeoJSON(),
}),
//填充颜色
style: new Style({
fill: new Fill({
color: "rgba(255, 0, 0, 0.5)",
}),
stroke: new Stroke({
color: "black",
width: 1,
}),
}),
}),
], //视图
view: view,
})); //设置圆点
// let anchorLayer = new VectorLayer({
// source: new VectorSource(),
// });
// let anchorFeatures = new Feature({
// geometry: new Point(center),
// }); // anchorFeatures.setStyle(
// new Style({
// image: new Circle({
// radius: 5,
// fill: new Fill({ color: "red" }),
// stroke: new Stroke({ color: "black", width: 1 }),
// }),
// })
// );
// anchorLayer.getSource().addFeature(anchorFeatures);
// map.addLayer(anchorLayer); let layer = new VectorLayer({
source: new VectorSource(),
});
map.addLayer(layer);
map.on("click", function (e) {
// 点击图层获取相对的位置进行相关圆点的新增
let position = e.coordinate;
let feature = new Feature({
geometry: new Point(position),
});
feature.setStyle(
new Style({
image: new Circle({
radius: 5,
fill: new Fill({ color: "blue" }),
stroke: new Stroke({ color: "black", width: 1 }),
}),
})
);
layer.getSource().addFeature(feature);
});
}; let move = () => {
// 设置北京的经纬度
const beijing = [116.46, 39.92];
const view = map.getView();
view.animate({
center: beijing,
zoom: 10,
projection: "EPSG:4356",
});
};
</script> <template>
<div id="map">
<div class="btns"></div>
</div>
</template> <style scoped>
.btns {
display: flex;
position: fixed;
left: 20px;
bottom: 20px; z-index: 999;
}
.btns div {
width: 100px;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.read-the-docs {
color: #888;
}
#map {
margin: 0;
width: 100vw;
height: 100vh;
}
</style>
前端学习openLayers配合vue3(圆形形状的绘制)的更多相关文章
- vue—你必须知道的 js数据类型 前端学习 CSS 居中 事件委托和this 让js调试更简单—console AMD && CMD 模式识别课程笔记(一) web攻击 web安全之XSS JSONP && CORS css 定位 react小结
vue—你必须知道的 目录 更多总结 猛戳这里 属性与方法 语法 计算属性 特殊属性 vue 样式绑定 vue事件处理器 表单控件绑定 父子组件通信 过渡效果 vue经验总结 javascript ...
- web前端学习部落22群分享给需要前端练手项目
前端学习还是很有趣的,可以较快的上手然后自己开发一些好玩的项目来练手,网上也可以一抓一大把关于前端开发的小项目,可是还是有新手在学习的时候不知道可以做什么,以及怎么做,因此,就整理了一些前端项目教程, ...
- 前端学习 第五弹: CSS (一)
前端学习 第五弹: CSS (一) 创建css: <link rel="stylesheet" type="text/css" href="my ...
- 【FE前端学习】第二阶段任务-基础
技能学习部分: 1.需要熟练掌握HTML标签以及CSS各个常用属性. 2.掌握CSS3 常用属性 3.掌握jquery的基本用法,对于JS基本逻辑语句需要熟练掌握 上文 [FE前端学习]第二阶段任务- ...
- web前端学习笔记
web前端学习笔记(CSS盒子的定位) 相对定位 使用相对定位的盒子的位置常以标准流的排版方式为基础,然后使盒子相对于它在原本的标准位置偏移指定的距离.相对定位的盒子仍在标准流中,它后面的盒子仍以标准 ...
- 前端学习(十四):CSS布局
进击のpython ***** 前端学习--CSS布局 每个模块的相关央视就算是进本上都完成了,但是,这些模块想放在不同的位置 横着放,竖着放,斜着放... ... 想怎么放怎么放 那就用到了今天要说 ...
- 前端学习(八):CSS
进击のpython ***** 前端学习--CSS 现在的互联网前端分为三层: HTML:超文本标记语言.从语义的角度描述页面结构 CSS:层叠样式表.从审美的角度负责页面样式 JS:Javascri ...
- 前端学习 node 快速入门 系列 —— 简易版 Apache
其他章节请看: 前端学习 node 快速入门 系列 简易版 Apache 我们用 node 来实现一个简易版的 Apache:提供静态资源访问的能力. 实现 直接上代码. - demo - stati ...
- 前端学习 linux —— 第一篇
前端学习 linux - 第一篇 本文主要介绍"linux 发行版本"."cpu 架构"."Linux 目录结构"."vi 和 v ...
- 每天成长一点---WEB前端学习入门笔记
WEB前端学习入门笔记 从今天开始,本人就要学习WEB前端了. 经过老师的建议,说到他每天都会记录下来新的知识点,每天都是在围绕着这些问题来度过,很有必要每天抽出半个小时来写一个知识总结,及时对一天工 ...
随机推荐
- C++处理系统相关权限问题
1.给某个文件或文件夹赋予特定用户的特定访问权限 /* 给文件(夹)szPath设置用户名为pszAccount的可读可写可修改权限 */ bool GiveTheAccountPrivToFile( ...
- 使用switch语句的注意事项
目录 case后需要手动break switch内的变量定义 变量没有定义在语句块内 变量定义在语句块内 表述多情况时不能用逗号 case后需要手动break switch(i){ case 1: 语 ...
- 血泪史: k8s Initial timeout of 40s passed.
背景: k8s不管是 kubeadm init 和join都会报错 kubelet-start] Writing kubelet configuration to file "/var/li ...
- Galera_Cluster_Mysql部署
前言 先来了解下它的身世,Galera Cluster是Codership公司开发的一套免费开源的高可用方案 官网为http://galeracluster.com.Galera Cluster即为安 ...
- TPC-H、TPC-H、TPC-DS部署测试
TPC-H.TPC-H.TPC-DS部署测试 概述 TPC-C TPC-C是业界常用的一套Benchmark,用于评估在线事务处理(OLTP)系统性能的基准测试.它模拟了一个商品批发公司的销售模型,包 ...
- 使用conditional 实现线程精准通讯
实现3个线程之间依次执行 比如有3个线程A,B,C ,需要按照顺序执行,ABC,ABC 依次执行. 这个使用可以使用 Lock 的 conditional来实现线程之间精准通讯. 点击查看代码 pac ...
- 限流中间件IpRateLimitMiddleware的使用
前言 IpRateLimitMiddleware(Github: AspNetCoreRateLimit) 是ASPNETCore的一个限流的中间件,用于控制客户端调用API的频次, 如果客户端频繁访 ...
- Vue.js与jQuery混用
标签: js 坑位 最近开发一个需求,项目有用到jQuery和Vue,发现我jQuery绑定的事件全部都失效了. Why Vue会重新渲染dom,加上是异步实例Vue.所以正常写程序的话jq的$()获 ...
- QEMU CVE-2021-3947 和 CVE-2021-3929 漏洞利用分析
QEMU CVE-2021-3947 和 CVE-2021-3929 漏洞利用分析 CVE-2021-3947 信息泄露漏洞 漏洞分析 漏洞点是 nvme_changed_nslist stati ...
- mysql 创建字段createtime 自动添加时间
1. 创建createtime字段 类型选为timestamp 2. 添加默认值 CURRENT_TIMESTAMP