* @function GeoJSONFormat.prototype.parseGeometry * @description 将一个 GeoJSON 中的几何要素转化成 Geometry 对象。 * @param {GeoJSONObject} obj - 从 GeoJSON 对象中创建一个对象。 * @returns {Geometry} 一个几何要素。 * @private
(obj)
| 710 | * @private |
| 711 | */ |
| 712 | parseGeometry(obj) { |
| 713 | if (obj == null) { |
| 714 | return null; |
| 715 | } |
| 716 | var geometry; |
| 717 | if (obj.type == "GeometryCollection") { |
| 718 | if (!(Util.isArray(obj.geometries))) { |
| 719 | throw "GeometryCollection must have geometries array: " + obj; |
| 720 | } |
| 721 | var numGeom = obj.geometries.length; |
| 722 | var components = new Array(numGeom); |
| 723 | for (var i = 0; i < numGeom; ++i) { |
| 724 | components[i] = this.parseGeometry.apply( |
| 725 | this, [obj.geometries[i]] |
| 726 | ); |
| 727 | } |
| 728 | geometry = new Collection(components); |
| 729 | } else { |
| 730 | if (!(Util.isArray(obj.coordinates))) { |
| 731 | throw "Geometry must have coordinates array: " + obj; |
| 732 | } |
| 733 | if (!this.parseCoords[obj.type.toLowerCase()]) { |
| 734 | throw "Unsupported geometry type: " + obj.type; |
| 735 | } |
| 736 | try { |
| 737 | geometry = this.parseCoords[obj.type.toLowerCase()].apply( |
| 738 | this, [obj.coordinates] |
| 739 | ); |
| 740 | } catch (err) { |
| 741 | // deal with bad coordinates |
| 742 | throw err; |
| 743 | } |
| 744 | } |
| 745 | return geometry; |
| 746 | } |
| 747 | |
| 748 | |
| 749 | /** |
no outgoing calls
no test coverage detected