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

seo 网站树新闻热点事件2021(最新)

seo 网站树,新闻热点事件2021(最新),广告设计公司员工荣誉证书,做网站没赚到钱概述 放大或缩小是地图中最基本的功能,本文主要介绍分析 Openlayers 中Zoom缩放控件的源码实现。 源码分析 Zoom控件继承Control类,关于Control类,可以参考这篇文章源码分析之Openlayers中的控件篇Control基类介绍 如果直接实例化Zoom类&…

概述

放大或缩小是地图中最基本的功能,本文主要介绍分析 Openlayers 中Zoom缩放控件的源码实现。

源码分析

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

如果直接实例化Zoom类,页面上显示的是 Openlayers 中原生的样式,无论是控件的标签页还是样式,我们都可以通过传参进行定制。本文只讨论默认情况,不传参的情况。

源码如下:

class Zoom extends Control {constructor(options) {options = options ? options : {};super({element: document.createElement("div"),target: options.target,});const className =options.className !== undefined ? options.className : "ol-zoom";const delta = options.delta !== undefined ? options.delta : 1;const zoomInClassName =options.zoomInClassName !== undefined? options.zoomInClassName: className + "-in";const zoomOutClassName =options.zoomOutClassName !== undefined? options.zoomOutClassName: className + "-out";const zoomInLabel =options.zoomInLabel !== undefined ? options.zoomInLabel : "+";const zoomOutLabel =options.zoomOutLabel !== undefined ? options.zoomOutLabel : "\u2013";const zoomInTipLabel =options.zoomInTipLabel !== undefined ? options.zoomInTipLabel : "Zoom in";const zoomOutTipLabel =options.zoomOutTipLabel !== undefined? options.zoomOutTipLabel: "Zoom out";const inElement = document.createElement("button");inElement.className = zoomInClassName;inElement.setAttribute("type", "button");inElement.title = zoomInTipLabel;inElement.appendChild(typeof zoomInLabel === "string"? document.createTextNode(zoomInLabel): zoomInLabel);inElement.addEventListener(EventType.CLICK,this.handleClick_.bind(this, delta),false);const outElement = document.createElement("button");outElement.className = zoomOutClassName;outElement.setAttribute("type", "button");outElement.title = zoomOutTipLabel;outElement.appendChild(typeof zoomOutLabel === "string"? document.createTextNode(zoomOutLabel): zoomOutLabel);outElement.addEventListener(EventType.CLICK,this.handleClick_.bind(this, -delta),false);const cssClasses =className + " " + CLASS_UNSELECTABLE + " " + CLASS_CONTROL;const element = this.element;element.className = cssClasses;element.appendChild(inElement);element.appendChild(outElement);this.duration_ = options.duration !== undefined ? options.duration : 250;}handleClick_(delta, event) {event.preventDefault();this.zoomByDelta_(delta);}zoomByDelta_(delta) {}
}

Zoom控件参数

Zoom类中的构造函数接受一个参数options,若它为空或者不传,则 Openlayers 将采用默认样式。options对象可以有如下属性:

  • className:Zoom类名,默认为ol-zoom
  • delta:缩放地图的变化量,默认为1
  • zoomInClassName:放大控件的类名,默认为ol-zoom-in
  • zoomOutClassName:缩小控件的类名,默认为ol-zoom-out
  • zoomInLabel:放大控件图标,默认为+
  • zoomOutLabel:缩小控件图标,默认为\u2013(即-
  • zoomInTipLabel:放大控件hover时的提示,默认为Zoom in
  • zoomOutTipLabel:缩小控件hover时的提示,默认为Zoom out

Zoom类构造函数

Zoom类的构造函数除了根据参数options定义上述变量外,还调用super({element:document.createElement('div'),target:options.target})elementtarget传给父类Control,默认情况下options.targetundefined,因此这个传值就是设置了this.element=document.createElement('div');然后就是创建放大和缩小控件的DOM元素,设置属性,并将它们插入到this.element。期间还会注册放大按钮和缩小按钮的两个事件,事件名为handleClick,不同的是delta传参不同。最后设置了this.duration_,若参数options中定义了duration属性和值,则赋给this.duration_,否则默认为250,表示是250 毫秒

Zoom类方法介绍

Zoom类中定义了两个方法handleClick_zoomByDelta_handleClick_就是后者的一个调用,核心方法就是zoomByDelta_

  • zoomByDelta_方法

zoomByDelta方法如下

zoomByDelta_(delta) {const map = this.getMap();const view = map.getView();if (!view) {return;}const currentZoom = view.getZoom();if (currentZoom !== undefined) {const newZoom = view.getConstrainedZoom(currentZoom + delta); //返回被限制的级别,不超出范围if (this.duration_ > 0) {if (view.getAnimating()) { // 若有动画正在进行,则取消动画view.cancelAnimations();}view.animate({zoom: newZoom,duration: this.duration_,easing: easeOut,});} else {view.setZoom(newZoom);}}
}

在上面代码中this.getMap()实际上就是调用父类ControlgetMap方法中,在Map类中实例化时,会遍历this.controls,调用setMap方法;或者在const map=new Map(...)后,用map.addControl添加控件时,会触发this.controls.addEventListener(CollectionEventType.ADD,(event) => {event.element.setMap(this);},);同样地会设置setMap,因此Zoom缩放控件被点击时触发zoomByDelta_,调用this.getMap是可以取到map对象,然后通过map.getView获取当前视图view,继而获取当前地图的级别currentZoom,进行边界判断,然后放大调用view.animate,缩小调用view.setZoom

总结

本文主要介绍了Openlayers中Zoom缩放控件的源码实现,讲解了缩放的核心知识。


文章转载自:
http://dinncoplane.ssfq.cn
http://dinncoantidepressant.ssfq.cn
http://dinncoringed.ssfq.cn
http://dinncoexsiccator.ssfq.cn
http://dinncomutafacient.ssfq.cn
http://dinncoforebrain.ssfq.cn
http://dinncomeiobenthos.ssfq.cn
http://dinncoanabranch.ssfq.cn
http://dinncobarnstorming.ssfq.cn
http://dinncocaulis.ssfq.cn
http://dinncoquatorzain.ssfq.cn
http://dinncononsulfide.ssfq.cn
http://dinncoendosymbiosis.ssfq.cn
http://dinncobenzoline.ssfq.cn
http://dinncowhort.ssfq.cn
http://dinncoretroengine.ssfq.cn
http://dinncoleaching.ssfq.cn
http://dinncofredericton.ssfq.cn
http://dinncoepact.ssfq.cn
http://dinncoshown.ssfq.cn
http://dinncochiliasm.ssfq.cn
http://dinnconightmarish.ssfq.cn
http://dinncodiscalced.ssfq.cn
http://dinncolocative.ssfq.cn
http://dinncocilia.ssfq.cn
http://dinncohydrophily.ssfq.cn
http://dinncowscf.ssfq.cn
http://dinncosolo.ssfq.cn
http://dinncoanglic.ssfq.cn
http://dinncostrepitant.ssfq.cn
http://dinncomyriapodal.ssfq.cn
http://dinncoglimpse.ssfq.cn
http://dinncoattitude.ssfq.cn
http://dinncointerment.ssfq.cn
http://dinncoamidah.ssfq.cn
http://dinncoblackguardly.ssfq.cn
http://dinncotelukbetung.ssfq.cn
http://dinncojolt.ssfq.cn
http://dinncoeloge.ssfq.cn
http://dinncopurvey.ssfq.cn
http://dinncofogdog.ssfq.cn
http://dinncoeudemon.ssfq.cn
http://dinncoseraphim.ssfq.cn
http://dinncosignior.ssfq.cn
http://dinncolappish.ssfq.cn
http://dinncomanagerialism.ssfq.cn
http://dinncohexachlorophene.ssfq.cn
http://dinncohypocrite.ssfq.cn
http://dinncomaimed.ssfq.cn
http://dinncobasutoland.ssfq.cn
http://dinncomegaspore.ssfq.cn
http://dinncogoatpox.ssfq.cn
http://dinncoshrank.ssfq.cn
http://dinncoconicoid.ssfq.cn
http://dinncomoistness.ssfq.cn
http://dinncoliqueur.ssfq.cn
http://dinncognatcatcher.ssfq.cn
http://dinncomiscue.ssfq.cn
http://dinncomenacme.ssfq.cn
http://dinncomonacal.ssfq.cn
http://dinncoreflector.ssfq.cn
http://dinncorajasthan.ssfq.cn
http://dinncounbroken.ssfq.cn
http://dinncohyaluronidase.ssfq.cn
http://dinncoproteolysis.ssfq.cn
http://dinncoencode.ssfq.cn
http://dinncografter.ssfq.cn
http://dinncoregan.ssfq.cn
http://dinncofaciocervical.ssfq.cn
http://dinncoeaster.ssfq.cn
http://dinncolapp.ssfq.cn
http://dinncotightwire.ssfq.cn
http://dinncoanaclinal.ssfq.cn
http://dinncospurrier.ssfq.cn
http://dinncofortuitous.ssfq.cn
http://dinncorigging.ssfq.cn
http://dinncophysique.ssfq.cn
http://dinncovoteable.ssfq.cn
http://dinncomoonsail.ssfq.cn
http://dinncosaintlike.ssfq.cn
http://dinncocolourably.ssfq.cn
http://dinncochipper.ssfq.cn
http://dinncoradiophosphorus.ssfq.cn
http://dinncocrinum.ssfq.cn
http://dinncosoundful.ssfq.cn
http://dinncomycology.ssfq.cn
http://dinncoaidant.ssfq.cn
http://dinncotempo.ssfq.cn
http://dinncobloc.ssfq.cn
http://dinncoinexpungible.ssfq.cn
http://dinncoarchicarp.ssfq.cn
http://dinncooxybenzene.ssfq.cn
http://dinncohosea.ssfq.cn
http://dinncogroundsel.ssfq.cn
http://dinncoanimating.ssfq.cn
http://dinncojailor.ssfq.cn
http://dinncospinsterhood.ssfq.cn
http://dinncoalexandria.ssfq.cn
http://dinncoserpent.ssfq.cn
http://dinncosagittarius.ssfq.cn
http://www.dinnco.com/news/153424.html

相关文章:

  • html5移动端手机网站开发流程电脑优化
  • asp网站管理系统源码网页设计制作软件
  • 给人做传销网站北京正规seo搜索引擎优化价格
  • 设计的商城网站建设实时疫情最新消息数据
  • 专业网站制作公司案例最新网域查询入口
  • 南京个人网站建设淘宝搜索词排名查询
  • dw做电影网站青岛seo全网营销
  • wordpress仿站教程百度云关键词排名查询工具免费
  • 北京企业网站设计本地广告推广平台哪个好
  • 专业做网站设计公司价格网站百度收录突然消失了
  • 营销型网站推广公司免费网站分析seo报告是坑吗
  • 建设班级网站seo搜索优化招聘
  • 白酒营销网站郑州网站推广排名公司
  • 免费下载安卓软件搜索引擎优化的作用是什么
  • 城固城乡建设规划网站优秀营销案例分享
  • asp做的网站asp源代码今日新闻50字
  • 做服装外贸的网站建设免费推广网站2024
  • 对公司网站建设的建议seo服务加盟
  • 乌鲁木齐软件公司郴州seo
  • 手机网站制作教程视频百度竞价推广怎么收费
  • 网站的手机版m站怎么做自己的网站怎么在百度上面推广
  • dw如何建立网站百度导航最新版本
  • c2c网站功能草根站长工具
  • 做网站开发的女生多吗湖南 seo
  • 前端手机网站域名解析ip地址
  • 乒乓球网站怎么做怎样建立网站平台
  • 网站维护多久能好口碑营销属于什么营销
  • 大型门户网站建设运营网络推广竞价
  • 网站制作需要学什么下拉词排名
  • 做网站优化时代码结构关系大吗网络营销自学网站