vue+openlayers 绘制点
绘制点使用point在绘制点的位置,使用Circle绘制点的样式
疑问:将style放在Feature上就绘制不出来样式?
<template> <div class="setting"> <div class="title">设置</div> <ul> <li> <p>边框大小:</p> <el-input-number v-model="borderWidth" controls-position="right" size="mini" @change="changeVector"></el-input-number> </li> <li> <p>边框颜色:</p> <el-color-picker v-model="borderColor" show-alpha size="mini" @change="changeVector"></el-color-picker> </li> <li> <p>内部颜色:</p> <el-color-picker v-model="fillColor" show-alpha size="mini" @change="changeVector"></el-color-picker> </li> <li> <p>大小:</p> <el-input-number v-model="radius" controls-position="right" size="mini" @change="changeVector"></el-input-number> </li> </ul> </div> </template> <script> import { Point } from 'ol/geom'; import Feature from 'ol/Feature'; import VectorLayer from 'ol/layer/Vector.js'; import VectorSource from 'ol/source/Vector.js'; import { Circle, Fill, Stroke, Style } from "ol/style"; export default { name: "pointPage", data() { return { // 边框大小 borderWidth: 1, // 边框颜色 borderColor: '#000', // 内部颜色 fillColor: "#000", // 大小 radius: 5, vector: null } }, created() { this.drawPoint() }, methods: { /** * 绘制点 */ drawPoint() { const map = window._map const stroke = new Stroke({ color: this.borderColor, width: this.borderWidth }) const fill = new Fill({ color: this.fillColor }) const style = new Style({ image: new Circle({ fill: fill, stroke: stroke, radius: this.radius, }), }) const source = new VectorSource({}); this.vector = new VectorLayer({ style: style, source: source, id: 'point', className: 'point' }); map.addLayer(this.vector) let coordinate = [108.885436, 30.054604] let point = new Point(coordinate); let feature = new Feature({ geometry: point }); // 把要素集合添加到源 addFeatures source.addFeature(feature); }, /**修改样式 * * @param {*} value * @param {*} type */ changeVector() { const stroke = new Stroke({ color: this.borderColor, width: this.borderWidth }) const fill = new Fill({ color: this.fillColor }) const style = new Style({ image: new Circle({ fill: fill, stroke: stroke, radius: this.radius, }), }) this.vector.setStyle(style) } } } </script> <style scoped> .setting { position: absolute; left: 10px; top: 10px; width: 300px; background: #FFFFFF; box-shadow: 0px 0px 20px 0px rgba(51,79,124,0.25); z-index: 10; } .title { height: 30px; line-height: 30px; border-bottom: 1px solid rgba(0, 125, 255, .1); font-size: 14px; padding: 0 10px; color: #1556C6; text-align: left; background: linear-gradient(177deg, #63B1FA 0%, #007DFF 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent } ul { margin: 0; padding: 0; } ul li { display: flex; justify-content: flex-start; padding: 10px 20px; font-size: 12px; } p { margin: 0; line-height: 28px; } </style>
绘制出的样式:
分类:
openlayers
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理