前端学习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前端了. 经过老师的建议,说到他每天都会记录下来新的知识点,每天都是在围绕着这些问题来度过,很有必要每天抽出半个小时来写一个知识总结,及时对一天工 ...
随机推荐
- Selenium测试form表单之checkbox和radio
一.定义form表单 用到的元素:checkbox和radiobutton 下图定义了一个选择爱好和选择性别的form表单,区域1用到的表单元素是checkbox(复选框),区域2用到的表单元素是ra ...
- 强化学习训练过程中的过度拟合(overfitting)
相关: A.I. Learns to Drive From Scratch in Trackmania 本文讨论的是强化学习中的过度拟合问题,要知道强化学习中的过拟合和其他的监督.无监督学习的过拟合不 ...
- 如何在国内使用gcr.io镜像进行拉取
[root@k8scloude2 ~]# docker pull gcr.io/google-samples/microservices-demo/emailservice:v0.4.0 换成 [ro ...
- Matlab矩阵运算的硬件资源分析
在用Matlab创建矩阵并计算矩阵乘法运算时,要注意计算机的可用内存大小(空间资源)和CPU性能(影响所用计算时间). 例如我们做以下测试:n为qubit的数目,那么一个矩阵Matrix_A=rand ...
- Android Hybird架构之整合XwalkView,让你的App内置chromium内核
使用XwalkView的目的无非是为了提升Android4.4以下版本(非chromium内核)的Html5渲染性能,并且能够使得H5页面在众多定制化的ROM上拥有一致的体验. 当然了,App内置Ch ...
- 题解:CF771A Bear and Friendship Condition
CF771A Bear and Friendship Condition 题解 算法 并查集,图的基本性质 分析 题目意思是,一旦有一些点联通,那么这些点必须两两直接相连.换句话讲,就是图中的每个联通 ...
- 【Azure 环境】从网络包中分析出TLS加密套件信息
问题描述 在抓取到网络包之后,如何来获取TLS信息呢?比如使用的是是么加密套件呢? 因为在应用层面,获取的错误信息非常简单: An TLS 1.2 connection request was rec ...
- Solr Facet技术的应用与研究
http://tech.meituan.com/solr-facet.html 问题背景 在 <搜索引擎关键字智能提示的一种实现> 一文中介绍过,美团的CRM系统负责管理销售人员的门店 ...
- Elasticsearch之常见问题
一. 聚合操作时,报Fielddata is disabled on text fields by default GET /megacorp/employee/_search { "agg ...
- 阿里云最新npm地址
npm config set registry https://registry.npmmirror.com -g