网站后台权限设计,html5 单页网站,个人网站做联盟营销,常见的erp系统大概要多少钱概述
本文主要介绍GeometryCollection类,GeometryCollection类继承于Geometry类,关于Geometry类,参考这篇文章源码分析之Openlayers中Geometry基类介绍
GeometryCollection类就是一组几何对象的集合.
源码分析
GeometryCollection类源码实现
GeometryCollection类源码实现…概述
本文主要介绍GeometryCollection类,GeometryCollection类继承于Geometry类,关于Geometry类,参考这篇文章源码分析之Openlayers中Geometry基类介绍
GeometryCollection类就是一组几何对象的集合.
源码分析
GeometryCollection类源码实现
GeometryCollection类源码实现如下:
class GeometryCollection extends Geometry {constructor(geometries) {super();this.geometries_ geometries;this.changeEventKeys_ [];this.listenGeometriesChange_();}unlistenGeometriesChange_() {this.changeEventsKeys_.forEach(unlistenByKey);this.changeEventsKeys_.length 0;}listenGeometriesChange_() {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {this.changeEventsKeys_.push(listen(geometries[i], EventType.CHANGE, this.changed, this));}}clone() {const geometryCollection new GeometryCollection(cloneGeometries(this.geometries_));geometryCollection.applyProperties(this);return geometryCollection;}closestPointXY(x, y, closestPoint, minSquaredDistance) {if (minSquaredDistance closestSquaredDistanceXY(this.getExtent(), x, y)) {return minSquaredDistance;}const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {minSquaredDistance geometries[i].closestPointXY(x,y,closestPoint,minSquaredDistance);}return minSquaredDistance;}containsXY(x, y) {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {if (geometries[i].containsXY(x, y)) {return true;}}return false;}computeExtent(extent) {createOrUpdateEmpty(extent);const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {extend(extent, geometries[i].getExtent());}return extent;}getGeometries() {return cloneGeometries(this.geometries_);}getGeometriesArray() {return this.geometries_;}getGeometriesArrayRecursive() {/** type {ArrayGeometry} */let geometriesArray [];const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {if (geometries[i].getType() this.getType()) {geometriesArray geometriesArray.concat(geometries[i].getGeometriesArrayRecursive());} else {geometriesArray.push(geometries[i]);}}return geometriesArray;}getSimplifiedGeometry(squaredTolerance) {if (this.simplifiedGeometryRevision ! this.getRevision()) {this.simplifiedGeometryMaxMinSquaredTolerance 0;this.simplifiedGeometryRevision this.getRevision();}if (squaredTolerance 0 ||(this.simplifiedGeometryMaxMinSquaredTolerance ! 0 squaredTolerance this.simplifiedGeometryMaxMinSquaredTolerance)) {return this;}const simplifiedGeometries [];const geometries this.geometries_;let simplified false;for (let i 0, ii geometries.length; i ii; i) {const geometry geometries[i];const simplifiedGeometry geometry.getSimplifiedGeometry(squaredTolerance);simplifiedGeometries.push(simplifiedGeometry);if (simplifiedGeometry ! geometry) {simplified true;}}if (simplified) {const simplifiedGeometryCollection new GeometryCollection(simplifiedGeometries);return simplifiedGeometryCollection;}this.simplifiedGeometryMaxMinSquaredTolerance squaredTolerance;return this;}getType() {return GeometryCollection;}intersectsExtent(extent) {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {if (geometries[i].intersectsExtent(extent)) {return true;}}return false;}isEmpty() {return this.geometries_.length 0;}rotate(angle, anchor) {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {geometries[i].rotate(angle, anchor);}this.changed();}scale(sx, sy, anchor) {if (!anchor) {anchor getCenter(this.getExtent());}const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {geometries[i].scale(sx, sy, anchor);}this.changed();}setGeometries(geometries) {this.setGeometriesArray(cloneGeometries(geometries));}setGeometriesArray(geometries) {this.unlistenGeometriesChange_();this.geometries_ geometries;this.listenGeometriesChange_();this.changed();}applyTransform(transformFn) {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {geometries[i].applyTransform(transformFn);}this.changed();}translate(deltaX, deltaY) {const geometries this.geometries_;for (let i 0, ii geometries.length; i ii; i) {geometries[i].translate(deltaX, deltaY);}this.changed();}disposeInternal() {this.unlistenGeometriesChange_();super.disposeInternal();}
}GeometryCollection类构造函数
GeometryCollection类构造函数接受一个参数geometries,geometries是一个包含多个几何对象数组,该参数会赋给全局变量this.geometries_,然后初始化一个变量this.changeEventsKeys_为空数组,最后调用this.listenGeometriesChange_方法.
GeometryCollection类的方法
GeometryCollection类的方法主要是对几何对象的一些操作,会去遍历this.geometries_变量,逐一进行操作.GeometryCollection类中的主要方法如下: listenGeometriesChange_方法:该方法在构造函数中就会被调用,其核心逻辑就是循环遍历this.geometries_,调用listen方法注册每个几何对象的change事件监听,注册事件返回的keys值保存在全局变量this.changeEventsKeys_中.listen方法的实现可以参考这篇文章源码分析之Openlayers中的Observable类 unlistenGeometriesChange_方法:用于取消监听,重置this.changeEventKeys_为空数组,解绑方法unlistenByKey同样是在event.js中实现的. clone方法:clone方法会返回一个新的几何对象集合,其内部会先调用cloneGeometries方法去clone每一个Geometry,然后实例化GeometryCollection类,再会调用applyProperties去应用this,applyProperties方法是在Object类中实现的,主要就是复制属性. closestPointXY方法:用于获取对几何对象稽核最近的点坐标,以及修改并获取最短距离;方法接受四个参数目标点坐标xy,最近点坐标以及最短距离,会先调用closestSquaredDistanceXY获取目标坐标点到边界范围的平方距离,若最短距离大于该参数最短平方距离,则返回参数minSquaredDistance;然后遍历this.geometries_,调用每一个几何对象的closestPointXY方法,修改最近点坐标和最短距离;最后返回最短距离 containsXY方法:同样地也是遍历this.geometries_调用几何对象的containsXY方法containsXY方法就是判断点是否在几何对象集合的边界上返回一个布尔值。 computeExtent方法:获取几何对象集合的边界范围 getGeometries方法:获取几何对象集合的副本调用cloneGeometries方法 getGeometriesArray方法:获取几何对象集合数组 getGeometriesArrayRecursive方法:将嵌套的几何对象如子集合展平成一个平坦的数组即若几何对象数组中的数组项也是一个数组那么就会递归调用它的getGeometriesArrayRecursive方法。 getSimplifiedGeometry方法:该方法就是用于简化几何采用了Douglas-Peucker算法。这个算法常用于简化折线几何减少点的数量同时尽可能保持原始几何形状的准确性。简化通过一个容差值来控制简化的程度容差值越大简化的结果就越简单。getSimplifiedGeometry方法会先检查修订号若当前几何对象的修订号与上次简化的修订号不一致这说明几何对象已经发生了变化需要重新计算简化后的几何对象然后会检查容差值若容差值小于0或者小于已经记录的最大容差值则不需要重新计算直接返回当前对象然后初始化一个空数组,simplifiedGeometries用于存储简化后的几何对象再遍历this.geometries_调用每个几何对象的getSimplifiedGeometry方法简化每一个几何对象若简化后的实例对象不等于原始对象则将simplified赋值为true然后实例化GeometryCollection类生成一个几何对象集合实例并返回若简化后的实例对象与原始对象相同一个几何对象也没有被简化则返回当前对象this. getType方法:获取类型返回GeometryCollection intersectsExtent方法:遍历this.geometries_然后调用每个几何对象的intersectsExtent方法判断几何对象是否与extent相交若有一个几何对象和extent相交则返回true若一个都不相交则返回false。 isEmpty方法:判断几何对象集合是否为空返回一个布尔值。 rotate方法:遍历this.geometries_然后调用每个几何对象的rotate方法,最后调用this.changed方法 scale方法:遍历this.geometries_然后调用每个几何对象的scale方法,最后调用this.changed方法 setGeometries方法:会先调用cloneGeometries方法clone每个几何对象然后调用this.setGeometriesArray方法 setGeometriesArray方法:会调用this.unlistenGeometriesChange_取消监听然后设置this.geometries_再调用this.listenGeometriesChange_方法注册监听最后调用this.changed方法 applyTransform方法:遍历this.geometries_然后调用每个几何对象的applyTransform方法,最后调用this.changed方法 translate方法:遍历this.geometries_然后调用每个几何对象的translate方法,最后调用this.changed方法 disposeInternal方法:清理函数调用this.unlistenGeometriesChange_取消监听再调用父类的disposeInternal方法
总结
本文介绍了GeometryCollection类的源码实现由此可以清晰理解GeometryCollection类主要还是一组多个对几何对象进行平移、旋转和缩放转换以及空间关系的判断等等。 文章转载自: http://www.morning.hhxpl.cn.gov.cn.hhxpl.cn http://www.morning.lzttq.cn.gov.cn.lzttq.cn http://www.morning.gmnmh.cn.gov.cn.gmnmh.cn http://www.morning.yhrfg.cn.gov.cn.yhrfg.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.bhrkx.cn.gov.cn.bhrkx.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.qcmhs.cn.gov.cn.qcmhs.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.fqsxf.cn.gov.cn.fqsxf.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.zshuhd015.cn.gov.cn.zshuhd015.cn http://www.morning.nzcys.cn.gov.cn.nzcys.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.klwxh.cn.gov.cn.klwxh.cn http://www.morning.ppqzb.cn.gov.cn.ppqzb.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.1000sh.com.gov.cn.1000sh.com http://www.morning.wxlzr.cn.gov.cn.wxlzr.cn http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn http://www.morning.ggnfy.cn.gov.cn.ggnfy.cn http://www.morning.ityi666.cn.gov.cn.ityi666.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.jpnfm.cn.gov.cn.jpnfm.cn http://www.morning.zqfz.cn.gov.cn.zqfz.cn http://www.morning.touziyou.cn.gov.cn.touziyou.cn http://www.morning.bbxbh.cn.gov.cn.bbxbh.cn http://www.morning.nqfxq.cn.gov.cn.nqfxq.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.srgnd.cn.gov.cn.srgnd.cn http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.qpqwd.cn.gov.cn.qpqwd.cn http://www.morning.ydmml.cn.gov.cn.ydmml.cn http://www.morning.lpnb.cn.gov.cn.lpnb.cn http://www.morning.hpdpp.cn.gov.cn.hpdpp.cn http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn http://www.morning.qjngk.cn.gov.cn.qjngk.cn http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.pggkr.cn.gov.cn.pggkr.cn http://www.morning.rykmz.cn.gov.cn.rykmz.cn http://www.morning.fwqgy.cn.gov.cn.fwqgy.cn http://www.morning.nwczt.cn.gov.cn.nwczt.cn http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.ghrlx.cn.gov.cn.ghrlx.cn http://www.morning.rynrn.cn.gov.cn.rynrn.cn http://www.morning.khtyz.cn.gov.cn.khtyz.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.webife.com.gov.cn.webife.com http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn http://www.morning.jzykw.cn.gov.cn.jzykw.cn http://www.morning.nxkyr.cn.gov.cn.nxkyr.cn http://www.morning.khxwp.cn.gov.cn.khxwp.cn http://www.morning.skpdg.cn.gov.cn.skpdg.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.nbiotank.com.gov.cn.nbiotank.com http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.cpqwb.cn.gov.cn.cpqwb.cn http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.nccqs.cn.gov.cn.nccqs.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.ybgpk.cn.gov.cn.ybgpk.cn http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn http://www.morning.qzpkr.cn.gov.cn.qzpkr.cn http://www.morning.yfwygl.cn.gov.cn.yfwygl.cn http://www.morning.lqklf.cn.gov.cn.lqklf.cn http://www.morning.rxydr.cn.gov.cn.rxydr.cn http://www.morning.lhqw.cn.gov.cn.lhqw.cn http://www.morning.uytae.cn.gov.cn.uytae.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.tdzxy.cn.gov.cn.tdzxy.cn http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn