当前位置:网站首页>openlayers不常用接口介绍
openlayers不常用接口介绍
2022-08-02 18:47:00 【Jennifer33K】
openlayers不常用接口介绍
renderSync()
// Requests an immediate render in a synchronous manner.
// 同步方式请求一个立即渲染
ol.map.renderSync();
on(type, listener)
// Listen for a certain type of event.
// 监听特定类型的事件。
// 参数:
// type:string | Array.<string>
// The event type or 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.
// 不监听一个特定类型事件
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() 方法用于向指定元素添加监听事件。且同一元素目标可重复添加,不会覆盖之前相同事件,配合 removeEventListener() 方法来移除事件。
// 参数说明:有三个参数
// 参数1、事件名称,字符串,必填。
// 事件名称不用带 "on" 前缀,点击事件直接写:"click",键盘放开事件写:"keyup"
// 参数2、执行函数,必填。
// 填写需要执行的函数,如:function(){代码...}
// 当目标对象事件触发时,会传入一个事件参数,参数名称可自定义,如填写event,不需要也可不填写。 事件对象的类型取决于特定的事件。
// 例如, “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().
// 使用键移除事件监听 用on()或once()返回
// 移除地图要素点击事件
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;
};
// 格式化面积
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;
};
边栏推荐
猜你喜欢
I have 8 years of experience in the Ali test, and I was able to survive by relying on this understanding.
Jupyter Notebook(Anaconda)——两个环境分别修改默认打开目录(深度学习第一周番外篇)
中职网络安全竞赛之应用服务漏洞扫描与利用
MySQL详细安装与配置
音频隐写一
浅谈一下pyd文件的逆向
力扣 622. 设计循环队列
EasyCVR平台通过国标GB28181接入柯达NVR显示注册失败,该如何解决?
Why young people are snapping up domestic iPhone, because it is much cheaper and more populist
LSB利器-zsteg
随机推荐
回收站删除的文件怎么恢复,2个方法汇总助您快速解决
From the technical panorama to the actual scene, analyze the evolutionary breakthrough of "narrowband high-definition"
药品研发--检验记录与检验报告书的书写细则
【OpenNI2】资料整理 -- 不断更新中
注释
Unity 打包和切换平台|Build Settings窗口介绍
流量分析三—远程登陆
7.22 - 每日一题 - 408
「日志」深度学习 CUDA环境配置
【C语言刷题】双指针原地修改数组(力扣原题分析)
MySQL 事件调度
去年,一道蚂蚁金服笔试题,还行,中等难度
【C语言刷题】牛客JZ65——不用四则运算作加法
js Fetch返回数据res.json()报错问题
[论文分享] VideoFlow: A Flow-Based Generative Model for Video
Monitor is easy to Mars debut: distributed operations help TOP3000 across management gap
面试官:谈谈如何防止消息丢失和消息重复
【C语言刷题】Leetcode169——多数元素
十六进制文本的字节序问题
arcgis 分子式标注