OpenLayers源码阅读(一):从ol开始

版本选择 v4.6.5
说明: v3.0.0~v4.6.5采用Closure,而从v5.0.0 之后采用ES Modules。

源码地址:https://github.com/openlayers/openlayers/tree/v4.6.5
openlayers从ol开始,对应文件https://github.com/openlayers/openlayers/blob/v4.6.5/src/ol/index.js
在index.js文件中,主要做了两件事:
第一件事是:定义了25个属性名并赋初始值,主要有:

  • ol.ASSUME_TOUCH = false;
  • ol.DEFAULT_MAX_ZOOM = 42; //最大级别
  • ol.DEFAULT_MIN_ZOOM = 0; //最小级别
  • ol.DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD = 0.5;
  • ol.DEFAULT_TILE_SIZE = 256;//瓦片像素大小
  • ol.DEFAULT_WMS_VERSION = ‘1.3.0’;//WMS服务版本
  • ol.ENABLE_CANVAS = true;//支持canvas
  • ol.ENABLE_PROJ4JS = true;//支持proj4
  • ol.ENABLE_WEBGL = true;//支持webGL
    ……

第二件事是:定义了2个方法

  • ol.inherits //对象继承
  • ol.getUid //获取对象id
    其中,ol.inherits贯穿于openlayers的所有对象,该方法内容如下:
/**
 * Inherit the prototype methods from one constructor into another.
 *
 * Usage:
 *
 *     function ParentClass(a, b) { }
 *     ParentClass.prototype.foo = function(a) { }
 *
 *     function ChildClass(a, b, c) {
 *       // Call parent constructor
 *       ParentClass.call(this, a, b);
 *     }
 *     ol.inherits(ChildClass, ParentClass);
 *
 *     var child = new ChildClass('a', 'b', 'see');
 *     child.foo(); // This works.
 *
 * @param {!Function} childCtor Child constructor.
 * @param {!Function} parentCtor Parent constructor.
 */
ol.inherits = function(childCtor, parentCtor) {
  childCtor.prototype = Object.create(parentCtor.prototype);
  childCtor.prototype.constructor = childCtor;
};

openlayers是采用javascript编写的,而javascript是基于原型的。
这里写图片描述
所以,子对象的原型继承于父对象的原型,子对象的构成函数是其本身。

扩展阅读:https://msdn.microsoft.com/zh-cn/library/hh924508(v=vs.94).aspx
扩展阅读:Js的apply()和call()的异同点,object.create()方法

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值