* @static * @version 12.1.0 * @function GeoJSONFormat.getGeoJSONType * @description 判断一个对象是否是合法的 GeoJSON 对象,如果不合法返回空,如果是合法的 GeoJSON 对象返回 FeatureCollection、Feature 或 Geometry。 * @param {Object} obj - 待判断的对象。 * @returns {string|null} 失败返回 null,成功返回 "FeatureCollection"、"Feature
(obj)
| 649 | * @returns {string|null} 失败返回 null,成功返回 "FeatureCollection"、"Feature" 或 "Geometry"。 |
| 650 | */ |
| 651 | static getGeoJSONType(obj) { |
| 652 | if (typeof obj !== 'object' || obj === null) { |
| 653 | return null; |
| 654 | } |
| 655 | if (obj.type === 'FeatureCollection') { |
| 656 | return Util.isArray(obj.features) ? 'FeatureCollection' : null; |
| 657 | } |
| 658 | if (obj.type === 'Feature') { |
| 659 | if (!obj.hasOwnProperty('geometry')) { |
| 660 | return null; |
| 661 | } |
| 662 | return 'Feature'; |
| 663 | } |
| 664 | const geometryTypes = [ |
| 665 | 'Point', 'MultiPoint', 'LineString', 'MultiLineString', |
| 666 | 'Polygon', 'MultiPolygon', 'GeometryCollection' |
| 667 | ]; |
| 668 | if (geometryTypes.indexOf(obj.type) === -1) { |
| 669 | return null; |
| 670 | } |
| 671 | if (obj.type === 'GeometryCollection') { |
| 672 | return Util.isArray(obj.geometries) ? 'Geometry' : null; |
| 673 | } |
| 674 | return Util.isArray(obj.coordinates) ? 'Geometry' : null; |
| 675 | } |
| 676 | /** |
| 677 | * @function GeoJSONFormat.prototype.parseFeature |
| 678 | * @description 将一个 GeoJSON 中的 feature 转化成 {@link FeatureVector}> 对象。 |
no test coverage detected