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

怎样创办网站google play 安卓下载

怎样创办网站,google play 安卓下载,个人公众号开发php,金融门户网站模版概述 本文主要介绍 Openlayers 中的MousePosition鼠标位置控件,该控件会创建一个元素在页面的右上方用来实时显示鼠标光标的位置坐标。该控件在实际应用很有效,可以实时获取鼠标位置,但是一般控件元素都会自定义。 源码分析 MousePosition…

概述

本文主要介绍 Openlayers 中的MousePosition鼠标位置控件,该控件会创建一个元素在页面的右上方用来实时显示鼠标光标的位置坐标。该控件在实际应用很有效,可以实时获取鼠标位置,但是一般控件元素都会自定义。

源码分析

MousePosition类是继承于Control类,关于Control类,可以参考这篇文章源码分析之Openlayers中的控件篇Control基类介绍。

MousePosition类实现如下:

class MousePosition extends Control {constructor(options) {options = options ? options : {};const element = document.createElement("div");element.className =options.className !== undefined ? options.className : "ol-mouse-position";super({element: element,render: options.render,target: options.target,});this.on;this.once;this.un;this.addChangeListener(PROJECTION, this.handleProjectionChanged_);if (options.coordinateFormat) {this.setCoordinateFormat(options.coordinateFormat);}if (options.projection) {this.setProjection(options.projection);}this.renderOnMouseOut_ = options.placeholder !== undefined;this.placeholder_ = this.renderOnMouseOut_ ? options.placeholder : " ";this.renderedHTML_ = element.innerHTML;this.mapProjection_ = null;this.transform_ = null;this.wrapX_ = options.wrapX === false ? false : true;}handleProjectionChanged_() {this.transform_ = null;}getCoordinateFormat() {return this.get(COORDINATE_FORMAT);}handleMouseOut(event) {this.updateHTML_(null);}getProjection() {return this.get(PROJECTION);}handleMouseMove(event) {const map = this.getMap();this.updateHTML_(map.getEventPixel(event));}setMap(map) {super.setMap(map);if (map) {const viewport = map.getViewport();this.listenerKeys.push(listen(viewport, EventType.POINTERMOVE, this.handleMouseMove, this));if (this.renderOnMouseOut_) {this.listenerKeys.push(listen(viewport, EventType.POINTEROUT, this.handleMouseOut, this));}this.updateHTML_(null);}}setCoordinateFormat(format) {this.set(COORDINATE_FORMAT, format);}setProjection(projection) {this.set(PROJECTION, getProjection(projection));}updateHTML_(pixel) {let html = this.placeholder_;if (pixel && this.mapProjection_) {if (!this.transform_) {const projection = this.getProjection();if (projection) {this.transform_ = getTransformFromProjections(this.mapProjection_,projection);} else {this.transform_ = identityTransform;}}const map = this.getMap();const coordinate = map.getCoordinateFromPixelInternal(pixel);if (coordinate) {const userProjection = getUserProjection();if (userProjection) {this.transform_ = getTransformFromProjections(this.mapProjection_,userProjection);}this.transform_(coordinate, coordinate);if (this.wrapX_) {const projection =userProjection || this.getProjection() || this.mapProjection_;wrapX(coordinate, projection);}const coordinateFormat = this.getCoordinateFormat();if (coordinateFormat) {html = coordinateFormat(coordinate);} else {html = coordinate.toString();}}}if (!this.renderedHTML_ || html !== this.renderedHTML_) {this.element.innerHTML = html;this.renderedHTML_ = html;}}render(mapEvent) {const frameState = mapEvent.frameState;if (!frameState) {this.mapProjection_ = null;} else {if (this.mapProjection_ != frameState.viewState.projection) {this.mapProjection_ = frameState.viewState.projection;this.transform_ = null;}}}
}

MousePosition类构造函数

MousePosition类构造函数接受一个参数对象options,该参数可以包含如下属性:

  • className:控件类名,默认为ol-mouse-position
  • render:自定义render方法,默认undefined
  • target:控件容器,默认undefined
  • coordinateFormat:坐标格式化,默认undefined
  • projection:分辨率,默认undefined
  • placeholder:提示填充字符
  • wrapX:是否水平方向重复延申

构造函数首先会先注册projection的监听事件this.handleProjectionChanged_,若该值发生变化,则将this.transform_null;然后判断,若options.coordinateFormat存在,则调用this.setCoordinateFormat方法;若options.projection存在,则调用this.setProjection方法;

MousePosition类中的方法

  • getCoordinateFormat方法:获取坐标格式化
  • getProjection方法:获取投影
  • handleMouseMove方法:接受一个参数event,该方法是鼠标在地图上移动时调用,会更新控件的内容坐标的值,getEventPixel就是根据参数event获取鼠标的位置以及viewport的某些属性,然后计算屏幕坐标
  • handleMouseOut方法:鼠标移除地图时调用
  • setCoordinateFormat方法:设置坐标格式化
  • setProjection方法:设置投影
  • updateHTML_方法:根据屏幕坐标获取地理坐标
  • render方法:在调用父类的setMap方法时会调用,主要用于设置this.mapProject_
  • setMap方法:sepMap方法会在Map类中调用,内部首先会调用父类的setMap方法,然后判断参数map是否存在,若存在,则注册viewport视口对象pointermove类型的监听,事件为this.handleMouseMove;若构造函数参数options.placeholder设置了,还会注册viewportpointeroutthis.handleMouseOut事件。

总结

本文主要介绍了 Openlayers 中MousePosition鼠标位置控件的源码实现,核心就是注册viewport对象上pointermove类型的监听事件获取屏幕坐标,然后调用内部方法map.getCoordinateFromPixelInternal将屏幕坐标转化为实际的地理位置坐标。

http://www.khdw.cn/news/9804.html

相关文章:

  • 做水果网站特点分析报告seo整站优化吧
  • 系统更新seo门户网价格是多少钱
  • 做网站做得好的公司有哪些深圳seo网络优化公司
  • 住房城乡建设厅网站服务营销的概念
  • 网站模板手机重庆网页优化seo公司
  • 日本 女做视频网站电商从零基础怎么学
  • 网站开发与设计现状seo的培训班
  • 永州做网站的公司痘痘该怎么去除效果好
  • 哪个网站专业做商铺网站seo技术
  • erp软件开发seo顾问张智伟
  • 建设网站能赚钱seo教程 百度网盘
  • 做原油看哪个网站企业推广方式有哪些
  • 衡水做wap网站费用医院网络销售要做什么
  • 电子商务网站中的信息技术阿里巴巴推广app有哪些
  • 泉州做网站优化公司贴吧推广
  • 商丘网站建设想象力网络建站之星官方网站
  • 网站备案自己备案和代理备案大数据
  • 兖州住房与城乡建设局网站营销软文是什么
  • 建设网站需要注意的事项日本搜索引擎naver入口
  • 山东建设厅科技处网站seo整站优化解决方案
  • 动漫网站策划书快手seo
  • 网站开发公司能不能去福州整站优化
  • 创建网站大约多少钱seo对网站优化
  • 有个蓝色章鱼做标志的网站短视频运营是做什么的
  • 如何制作自己的网站关键词优化排名要多少钱
  • 企业门户网站的建设与实现网络营销专业培训学校
  • 运营活动策划方案长沙靠谱关键词优化服务
  • 眉山网站建设公司百度开放云平台
  • 怎样做一个app站长工具seo综合查询5g
  • 时时彩网站谁做seo描述快速排名