Vue+Openlayer中使用select选择要素
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Vue+Openlayer中使用select选择要素,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2135字,纯文字阅读大概需要4分钟。
内容图文
本文通过实例代码给大家介绍Vue+Openlayer中使用select选择要素,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧 |
效果图:
实现代码:
<template> <div id="map" ref="map" style="width: 100vw; height: 100vh"></div> </template> <script> import "ol/ol.css"; import { Map, View } from "ol"; import { OSM, Vector as VectorSource } from "ol/source"; import { Vector as VectorLayer, Tile as TileLayer } from "ol/layer"; import GeoJSON from "ol/format/GeoJSON"; import Select from "ol/interaction/Select"; import { altKeyOnly, click, pointerMove } from "ol/events/condition"; export default { name: "gif", data() { return { map: {}, layer: {}, geojsonData: { type: "FeatureCollection", features: [ { type: "Feature", properties: { title: "警报1", }, geometry: { type: "Point", coordinates: [91.48879670091165, 37.83814884701121], }, }, { type: "Feature", properties: { title: "警报2", }, geometry: { type: "Point", coordinates: [99.19515576149941, 26.713646654711134], }, }, { type: "Feature", properties: { title: "警报3", }, geometry: { type: "Point", coordinates: [123.74363825288785, 44.363694825734726], }, }, ], }, select: {}, }; }, mounted() { this.initMap(); }, methods: { // 初始化地图 initMap() { this.layer = new VectorLayer({ source: new VectorSource({ features: new GeoJSON().readFeatures(this.geojsonData), }), }); this.map = new Map({ target: "map", layers: [ new TileLayer({ source: new OSM(), }), this.layer, ], view: new View({ projection: "EPSG:4326", center: [104.912777, 34.730746], zoom: 4.5, }), }); this.select = new Select({ condition: click, //单击选择 }); this.map.addInteraction(this.select); this.select.on("select", (e) => { let coordinate = e.mapBrowserEvent.coordinate; //获取选择的坐标 let properties = e.selected[0].getProperties(); //获取当前要素的所有属性 }); // 设置鼠标划过矢量要素的样式 this.map.on("pointermove", (e) => { const isHover = this.map.hasFeatureAtPixel(e.pixel); this.map.getTargetElement().style.cursor = isHover ? "pointer" : ""; }); }, }, }; </script>
到此这篇关于Vue+Openlayer中使用select选择要素的实现代码的文章就介绍到这了
本文地址:https://www.linuxprobe.com/vue-openlayer-select.html
原文:https://www.cnblogs.com/cainiaoyige1/p/15236646.html
内容总结
以上是互联网集市为您收集整理的Vue+Openlayer中使用select选择要素全部内容,希望文章能够帮你解决Vue+Openlayer中使用select选择要素所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。