MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / getGeoJSONType

Method getGeoJSONType

src/common/format/GeoJSON.js:651–675  ·  view source on GitHub ↗

* @static * @version 12.1.0 * @function GeoJSONFormat.getGeoJSONType * @description 判断一个对象是否是合法的 GeoJSON 对象,如果不合法返回空,如果是合法的 GeoJSON 对象返回 FeatureCollection、Feature 或 Geometry。 * @param {Object} obj - 待判断的对象。 * @returns {string|null} 失败返回 null,成功返回 "FeatureCollection"、"Feature

(obj)

Source from the content-addressed store, hash-verified

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}> 对象。

Callers 3

GeoJSONSpec.jsFile · 0.80
toSuperMapGeometryFunction · 0.80
toSuperMapBoundsFunction · 0.80

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected