当前位置: 首页 > news >正文

【openlayers框架学习】九:openlayers中的交互类(select和draw)


文章目录

    • openlayers进阶
      • 28 openlayers中的事件
      • 29 openlayers中select交互类的使用
      • 30 openlayers中select常见的配置选项
      • 31 openlayers中绘制交互类(Draw)


openlayers进阶

28 openlayers中的事件

常用进行事件交互的对象:map\view\source

29 openlayers中select交互类的使用

Interaction->Draw

Interaction->Select

import './style.css';
import Map from 'ol/Map';
import 'ol/ol.css';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import { XYZ } from 'ol/source';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON.js';
import VectorLayer from 'ol/layer/Vector.js';
import Style from 'ol/style/Style';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import Select from 'ol/interaction/Select.js';
const center = [114.25, 30.59];
const view = new View({center: center,zoom: 4,projection: "EPSG:4326",
});
//城市矢量地图-高德地图瓦片
const gaodeSource = new XYZ({url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
});
const gaodeLayer = new TileLayer({source: gaodeSource,
});
const map = new Map({target: "map",view: view,layers: [gaodeLayer],
});
//加载矢量地图 将一些矢量数据(很多格式 如GEOJSON)加载到底图上
const vectorSource = new VectorSource({url:'https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json',//处理对应的矢量数据格式format: new GeoJSON(),
});
const vectorLayer = new VectorLayer({source: vectorSource,style: new Style({fill: new Fill({// color: "red", //填充为红色color: "rgba(255,0,0,0.6)", //填充为红色}),stroke: new Stroke({color:"green",}),}),
});
//加载数据需要发送请求 => 异步 在回调函数中处理数据
// vectorSource.on("change",function(){
//     console.log(this.getFeatures());
// });
//GeoJSON的数据格式 记录的是要素信息的集合 要素信息 包括自定义属性 几何信息(经纬度-形状)
map.addLayer(vectorLayer);
const select = new Select();
map.addInteraction(select);
select.on('select',function(e){console.log(e);const f = e.selected[0];f.setStyle(new Style({fill: new Fill({color:"rgba(0,255,0,0.6)",}),}));
});

30 openlayers中select常见的配置选项

main.js

import './style.css';
import Map from 'ol/Map';
import 'ol/ol.css';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import { XYZ } from 'ol/source';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON.js';
import VectorLayer from 'ol/layer/Vector.js';
import Style from 'ol/style/Style';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import Select from 'ol/interaction/Select.js';
import { pointerMove } from 'ol/events/condition';
const center = [114.25, 30.59];
const view = new View({center: center,zoom: 4,projection: "EPSG:4326",
});
//城市矢量地图-高德地图瓦片
const gaodeSource = new XYZ({url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
});
const gaodeLayer = new TileLayer({source: gaodeSource,
});
const map = new Map({target: "map",view: view,layers: [gaodeLayer],
});
//加载矢量地图 将一些矢量数据(很多格式 如GEOJSON)加载到底图上
const vectorSource = new VectorSource({url:'https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json',//处理对应的矢量数据格式format: new GeoJSON(),
});
const vectorLayer = new VectorLayer({source: vectorSource,style: new Style({fill: new Fill({// color: "red", //填充为红色color: "rgba(255,0,0,0.6)", //填充为红色}),stroke: new Stroke({color:"green",}),}),
});
//加载数据需要发送请求 => 异步 在回调函数中处理数据
// vectorSource.on("change",function(){
//     console.log(this.getFeatures());
// });
//GeoJSON的数据格式 记录的是要素信息的集合 要素信息 包括自定义属性 几何信息(经纬度-形状)
map.addLayer(vectorLayer);
const select = new Select({condition:pointerMove,  //鼠标移动时触发,默认是点击时触发filter:function(feature, layer){return layer === vectorLayer; //过滤图层}
});
map.addInteraction(select);
select.on('select',function(e){console.log(e);const f = e.selected[0];f.setStyle(new Style({fill: new Fill({color:"rgba(0,255,0,0.6)",}),}));
});

31 openlayers中绘制交互类(Draw)

Interaction->Draw

main.js

import './style.css';
import Map from 'ol/Map';
import 'ol/ol.css';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import { XYZ } from 'ol/source';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON.js';
import VectorLayer from 'ol/layer/Vector.js';
import Style from 'ol/style/Style';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import Draw from 'ol/interaction/Draw.js';
const center = [114.25, 30.59];
const view = new View({center: center,zoom: 4,projection: "EPSG:4326",
});
//城市矢量地图-高德地图瓦片
const gaodeSource = new XYZ({url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
});
const gaodeLayer = new TileLayer({source: gaodeSource,
});
const map = new Map({target: "map",view: view,layers: [gaodeLayer],
});//加载矢量地图 
const vectorSource = new VectorSource();
const vectorLayer = new VectorLayer({source: vectorSource,style: new Style({stroke: new Stroke({color:"red",width:4,}),}),
});const draw = new Draw({type:'LineString',source: vectorLayer.getSource(),
});map.addInteraction(draw);
map.addLayer(vectorLayer);
http://www.lryc.cn/news/609003.html

相关文章:

  • 安卓调javaScript Not find method “forceLogout“ implementatidsignature or namesp
  • 【C语言符号单词搜索首位置及数量】2022-10-4
  • web前端React和Vue框架与库安全实践
  • 数组和指针的关系
  • 【LeetCode刷题指南】--二叉树的后序遍历,二叉树遍历
  • VUE父级路由没有内容的解决方案
  • Python自动化测试框架:Unittest 断言
  • 数据结构中使用到的C语言
  • elk快速部署、集成、调优
  • [硬件电路-143]:模拟电路 - 开关电源与线性稳压电源的详细比较
  • mybatis-plus从入门到入土(四):持久层接口之BaseMapper和选装件
  • MySQL极简安装挑战
  • nmon使用教程
  • sqli-labs:Less-23关卡详细解析
  • 基于Python实现生产者—消费者分布式消息队列:构建高可用异步通信系统
  • cpy相关函数区分
  • Ollama模型库模型下载慢完美解决(全平台)
  • 设计模式 - 组合模式:用树形结构处理对象之间的复杂关系
  • 新手向:Python制作贪吃蛇游戏(Pygame)
  • FLUX.1 Krea - 告别“AI味”,感受超自然细节,黑森林最新开源文生图模型 支持50系显卡 一键整合包下载
  • 控制建模matlab练习08:根轨迹
  • js--2048小游戏
  • 【openlayers框架学习】十:openlayers中控件的使用
  • Ubuntu系统VScode实现opencv(c++)视频的处理与保存
  • C语言与数据结构:从基础到实战
  • 解决飞书文档中PDF文档禁止下载的问题
  • Linux 环境下 Docker 安装与简单使用指南
  • ubuntu syslog中appindicator报错解决
  • 扩散模型(一)——综述
  • Rust: 获取 MAC 地址方法大全