当前位置:网站首页>Introduction of uncommon interfaces of openlayers
Introduction of uncommon interfaces of openlayers
2022-08-02 22:31:00 【Jennifer33K】
openlayersInfrequently used interface introduction
renderSync()
// Requests an immediate render in a synchronous manner.
// Synchronous mode requests an immediate render
ol.map.renderSync();
on(type, listener)
// Listen for a certain type of event.
// Listen for specific types of events.
// 参数:
// type:string | Array.<string>
// The event type or array of event types.
// A time type or an array of event types
// listener:function
// The listener function.
// 监听函数
ol.map.on('pointermove', pointerMoveHandler);
ol/MapBrowserEvent~MapBrowserEvent
un(type, listener)
Unlisten for a certain type of event.
// Does not listen for a specific type of event
ol/interaction/DragBox.DragBoxEvent
drawTool = new ol.interaction.Draw({
source: source,
type: geotype,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'orange',
lineDash: [10, 10],
width: 2
}),
image: new ol.style.Circle({
radius: 5,
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 0.7)'
}),
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
})
})
})
});
drawTool = new ol.interaction.DragBox({
source: source,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.5)'
}),
stroke: new ol.style.Stroke({
color: 'orange',
lineDash: [10, 10],
width: 2
}),
image: new ol.style.Circle({
radius: 5,
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 0.7)'
}),
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
})
})
})
});
drawTool.on('boxstart', function (e) {
});
ol.map.addInteraction(drawTool);
var source=ol.map.drawLayer.getSource();
infoDiv = options.infoDiv;
toolElement.title = options.controlText;
toolElement.className=options.className;
toolElement.removeEventListener('click',handleMeasure);
toolElement.addEventListener('click', handleMeasure, false);
// addEventListener() The method is used to add a listener event to the specified element.And the same element target can be added repeatedly,The same events as before will not be overwritten,配合 removeEventListener() method to remove events.
// 参数说明:有三个参数
// 参数1、事件名称,字符串,必填.
// The event name is not required "on" 前缀,Click event to write directly:"click",The keyboard release event is written:"keyup"
// 参数2、执行函数,必填.
// Fill in the function that needs to be executed,如:function(){代码...}
// When the target object event fires,An event parameter is passed in,Parameter names can be customized,如填写event,Not required or not required. 事件对象的类型取决于特定的事件.
// 例如, “click” 事件属于 MouseEvent(鼠标事件) 对象.
// function(event){console.log(event)}
// 参数3、触发类型,布尔型,可空
// true - 事件在捕获阶段执行
// false - 事件在冒泡阶段执行,默认是false
import {
unByKey} from 'ol/Observable';
// Removes an event listener using the key returned by on() or once().
// Use the key to remove event listeners 用on()或once()返回
// Remove map feature click events
SSMap.prototype.removeFeatureClick=function(){
this.olMap.unByKey(this.popupclickkey);
this.olMap.unByKey(this.pointermoveKey);
this.container.style.cursor='crosshair';
};
// 格式化距离
var formatLength = function (line,cir) {
var length;
if (geodesicmeasures) {
var coordinates = line.getCoordinates();
length = 0;
var sourceProj = 'EPSG:900913';
for (var i = 0, ii = coordinates.length - 1; i < ii; ++i) {
var c1 = ol.proj.transform(coordinates[i], sourceProj, 'EPSG:4326');
var c2 = ol.proj.transform(coordinates[i + 1], sourceProj,'EPSG:4326');
length += wgs84Sphere.haversineDistance(c1, c2);
// if(cir&&coordinates.length>2&&(i+1== coordinates.length - 1)){
// var c1 = ol.proj.transform(coordinates[i+1], sourceProj, 'EPSG:4326');
// var c2 = ol.proj.transform(coordinates[0], sourceProj,'EPSG:4326');
// length += wgs84Sphere.haversineDistance(c1, c2);
// }
}
} else {
length = Math.round(line.getLength() * 100) / 100;
}
var output;
if (length > 1000) {
output = '距离:'+(Math.round(length / 1000 * 100) / 100) + ' ' + 'km';
} else {
output = '距离:'+(Math.round(length * 100) / 100) + ' ' + 'm';
}
return output;
};
// format area
var formatArea = function (polygon) {
var area;
if (geodesicmeasures) {
var sourceProj = 'EPSG:900913';
var geom = /** @type {ol.geom.Polygon} */
(polygon.clone().transform(sourceProj, 'EPSG:4326'));
var coordinates = geom.getLinearRing(0).getCoordinates();
area = Math.abs(wgs84Sphere.geodesicArea(coordinates));
} else {
area = polygon.getArea();
}
var output;
if (area > 10000) {
output ='面积:'+ (Math.round(area / 1000000 * 100) / 100) + ' '
+ 'km<sup>2</sup>';
} else {
output ='面积:'+ (Math.round(area * 100) / 100) + ' ' + 'm<sup>2</sup>';
}
var line=new ol.geom.LineString( polygon.getCoordinates()[0]);
var lineout=formatLength(line,true);
return lineout+';'+output;
};
边栏推荐
- Three.js入门
- 安装Mac版Mysql卡在Installation阶段,彻底清理mysql并重装mysql
- 流量分析第一题
- Dynamically generate different types of orders, how do I deposit to mongo database?
- 2022-07-27
- 深度学习-学习笔记(持续更新)
- 技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
- 【Psychology · Characters】Issue 1
- 【C语言刷题】牛客JZ65——不用四则运算作加法
- SCANIA SCANIA OTL tag is introduced
猜你喜欢
Three.js入门
Based on OpenGL glaciers and firebird (illumination calculation model, visual, particle system)
thinkphp框架5.0.23安全更新问题-漏洞修复-/thinkphp/library/think/App.php具体怎么改以及为什么要这么改
geoserver+mysql+openlayers问题点
扫码预约 | 观看Apache Linkis数据处理实践以及计算治理能力
Go----Go 语言快速体验之开发环境搭建及第一个项目HelloWord
【LeetCode】118. 杨辉三角 - Go 语言题解
当TIME_WAIT状态的TCP正常挥手,收到SYN后…
EasyCVR平台通过国标GB28181接入柯达NVR显示注册失败,该如何解决?
JWT学习
随机推荐
geoserver+mysql+openlayers问题点
MySQL安装配置教程(超级详细)
cache2go-源码阅读
简单有效又有用的关闭antimalware service executable的方法·备份记录
thinkphp框架5.0.23安全更新问题-漏洞修复-/thinkphp/library/think/App.php具体怎么改以及为什么要这么改
Detailed explanation of common examples of dynamic programming
golang刷leetcode动态规划(11)不同路径
MySQL安装时一直卡在starting server
Compose主题切换——让你的APP也能一键换肤
技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
es DELETE index 源码分析
平稳发展 | 西欧地区手游玩家的数据和洞察
银保监会:人身险产品信披材料应由保险公司总公司统一负责管理
项目分析(复杂嵌入式系统设计)
松鼠短视频系统为用户加入随机头像代码-快速为用户加上随机头衔
Kali命令ifconfig报错command not found
Flutter自带国际化适配自动生成方案
Caldera(二)高级实战
MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
SQL-UDT是什么功能?