当前位置: 首页 > 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.dtcms.com/a/313007.html

相关文章:

  • GaussDB SQL执行计划详解
  • Rust: 获取 MAC 地址方法大全
  • Zama的使命
  • 【读论文】KAG-Thinker:升级版RAG 框架
  • 推荐系统学习笔记(九)曝光过滤 Bloom Filter
  • 【DL学习笔记】感受野(Receptive Field)
  • 映射网络驱动器后,重启映射就没了
  • 王之凝视 免安中文 离线运行版
  • 【Bluetooth】【Transport层篇】第四章 基于基础UART的蓝牙硬件发送协议 UART H4 Transport详解
  • wordpress登陆前登陆后显示不同的顶部菜单
  • 前后端交流
  • Go语言声明变量
  • mybatis实现固定三层树形结构的嵌套查询
  • 怎么修改论文格式呢?提供一份论文格式模板
  • 【ProtoBuf】初识ProtoBuf
  • 【UE5医学影像可视化】读取本地Dicom生成VolumeTexture,实现2D显示和自动翻页
  • 关于记录一下“bug”,在做图片上传的时候出现的小问题
  • B3953 [GESP202403 一级] 找因数
  • 大模型智能体(Agent)技术全景:架构演进、协作范式与应用前沿
  • Python Dash 全面讲解
  • 使用 Vuepress + GitHub Pages 搭建项目文档
  • io_getevents系统调用及示例
  • Android 之 图片加载(Fresco/Picasso/Glide)
  • 第四章:OSPF 协议
  • Docker环境离线安卓安装指南
  • Android 之 存储(Assets目录,SharedPreferences,数据库,内部存储等)
  • 音视频学习(五十):音频无损压缩
  • 使用 Docker 部署 Golang 程序
  • 计数组合学7.12( RSK算法的一些推论)
  • 考研复习-计算机组成原理-第二章-数据的表示和运算