/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved. * This program are made available under the terms of the Apache License, Version 2.0 * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/ import { SuperMap } from '../SuperMap'; import { Vector } from '../commontypes/Vector'; import { Util } from '../commontypes/Util'; import { Bounds } from '../commontypes/Bounds'; import { Collection } from '../commontypes/geometry/Collection'; import { JSONFormat } from './JSON'; import { Point } from '../commontypes/geometry/Point'; import { MultiPoint } from '../commontypes/geometry/MultiPoint'; import { LineString } from '../commontypes/geometry/LineString'; import { MultiLineString } from '../commontypes/geometry/MultiLineString'; import { LinearRing } from '../commontypes/geometry/LinearRing'; import { Polygon } from '../commontypes/geometry/Polygon'; import { MultiPolygon } from '../commontypes/geometry/MultiPolygon'; import { ServerGeometry } from '../iServer/ServerGeometry'; /** * @class SuperMap.Format.GeoJSON * @classdesc GeoJSON ç读ååãä½¿ç¨ {@link SuperMap.Format.GeoJSON} æé å¨å建ä¸ä¸ª GeoJSON è§£æå¨ã * @category BaseTypes Format * @param {Object} [options] - åæ°ã * @param {string} [options.indent=" "] - ç¨äºæ ¼å¼åè¾åºï¼indent å符串ä¼å¨æ¯æ¬¡ç¼©è¿çæ¶å使ç¨ä¸æ¬¡ã * @param {string} [options.space=" "] - ç¨äºæ ¼å¼åè¾åºï¼space å符串ä¼å¨åå¼å¯¹ç ":" å边添å ã * @param {string} [options.newline="\n"] - ç¨äºæ ¼å¼åè¾åº, newline å符串ä¼ç¨å¨æ¯ä¸ä¸ªåå¼å¯¹ææ°ç»é¡¹æ«å°¾ã * @param {number} [options.level=0] - ç¨äºæ ¼å¼åè¾åº, è¡¨ç¤ºçæ¯ç¼©è¿çº§å«ã * @param {boolean} [options.pretty=false] - æ¯å¦å¨åºååçæ¶å使ç¨é¢å¤çç©ºæ ¼æ§å¶ç»æãå¨ write æ¹æ³ä¸ä½¿ç¨ã * @param {boolean} [options.nativeJSON] - éè¦è¢«æ³¨åççå¬å¨å¯¹è±¡ã * @param {boolean} [options.ignoreExtraDims=true] - 忽ç¥ç»´åº¦è¶ è¿ 2 çå ä½è¦ç´ ã * @extends {SuperMap.Format.JSON} */ export class GeoJSON extends JSONFormat { constructor(options) { super(options); /** * @member {boolean} [SuperMap.Format.GeoJSON.prototype.ignoreExtraDims=true] * @description 忽ç¥ç»´åº¦è¶ è¿ 2 çå ä½è¦ç´ ã */ this.ignoreExtraDims = true; this.CLASS_NAME = "SuperMap.Format.GeoJSON"; /** * @member {Object} SuperMap.Format.GeoJSON.prototype.parseCoords * @private * @description ä¸ä¸ªå±æ§å对åºç GeoJSON 对象çå ä½ç±»åçå¯¹è±¡ãæ¯ä¸ªå±æ§å ¶å®é½æ¯ä¸ä¸ªå®é ä¸åè§£æç¨çæ¹æ³ã */ this.parseCoords = { /** * @function SuperMap.Format.GeoJSON.parseCoords.point * @description å°ä¸ç»åæ 转æä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çä¸ç»åæ ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "point": function (array) { if (this.ignoreExtraDims === false && array.length != 2) { throw "Only 2D points are supported: " + array; } return new Point(array[0], array[1]); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.multipoint * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çåæ ç»æ°ç»ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "multipoint": function (array) { var points = []; var p = null; for (var i = 0, len = array.length; i < len; ++i) { try { p = this.parseCoords["point"].apply(this, [array[i]]); } catch (err) { throw err; } points.push(p); } return new MultiPoint(points); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.linestring * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çåæ ç»æ°ç»ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "linestring": function (array) { var points = []; var p = null; for (var i = 0, len = array.length; i < len; ++i) { try { p = this.parseCoords["point"].apply(this, [array[i]]); } catch (err) { throw err; } points.push(p); } return new LineString(points); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.multilinestring * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çåæ ç»æ°ç»ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "multilinestring": function (array) { var lines = []; var l = null; for (var i = 0, len = array.length; i < len; ++i) { try { l = this.parseCoords["linestring"].apply(this, [array[i]]); } catch (err) { throw err; } lines.push(l); } return new MultiLineString(lines); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.polygon * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "polygon": function (array) { var rings = []; var r, l; for (var i = 0, len = array.length; i < len; ++i) { try { l = this.parseCoords["linestring"].apply(this, [array[i]]); } catch (err) { throw err; } r = new LinearRing(l.components); rings.push(r); } return new Polygon(rings); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.multipolygon * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çåæ ç»æ°ç»ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "multipolygon": function (array) { var polys = []; var p = null; for (var i = 0, len = array.length; i < len; ++i) { try { p = this.parseCoords["polygon"].apply(this, [array[i]]); } catch (err) { throw err; } polys.push(p); } return new MultiPolygon(polys); }, /** * @function SuperMap.Format.GeoJSON.parseCoords.box * @description å°åæ ç»æ°ç»è½¬åæä¸ºä¸ä¸ª {@link SuperMap.Geometry} 对象ã * @param {Object} array - GeoJSON çæ®µä¸çåæ ç»æ°ç»ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½å¯¹è±¡ã */ "box": function (array) { if (array.length != 2) { throw "GeoJSON box coordinates must have 2 elements"; } return new Polygon([ new LinearRing([ new Point(array[0][0], array[0][1]), new Point(array[1][0], array[0][1]), new Point(array[1][0], array[1][1]), new Point(array[0][0], array[1][1]), new Point(array[0][0], array[0][1]) ]) ]); } }; /** * @member {Object} SuperMap.Format.GeoJSON.prototype.extract * @private * @description ä¸ä¸ªå±æ§å对åºçGeoJSONç±»åç对象ãå ¶å¼ä¸ºç¸åºçå®é çè§£ææ¹æ³ã */ this.extract = { /** * @function SuperMap.Format.GeoJSON.extract.feature * @description è¿åä¸ä¸ªè¡¨ç¤ºå个è¦ç´ 对象ç GeoJSON çä¸é¨åã * @param {SuperMap.ServerFeature} feature - iServer è¦ç´ 对象ã * @returns {Object} ä¸ä¸ªè¡¨ç¤ºç¹ç对象ã */ 'feature': function (feature) { var geom = this.extract.geometry.apply(this, [feature.geometry]); var json = { "type": "Feature", "properties": this.createAttributes(feature), "geometry": geom }; if (feature.geometry && feature.geometry.type === 'TEXT') { json.properties.texts = feature.geometry.texts; json.properties.textStyle = feature.geometry.textStyle; } if (feature.fid) { json.id = feature.fid; } if (feature.ID) { json.id = feature.ID; } return json; }, /** * @function SuperMap.Format.GeoJSON.extract.geometry * @description è¿åä¸ä¸ªè¡¨ç¤ºå个å ä½å¯¹è±¡ç GeoJSON çä¸é¨åã * @param {Object} geometry - iServer å ä½å¯¹è±¡ã * @returns {Object} ä¸ä¸ªè¡¨ç¤ºå ä½ä½ç对象ã */ 'geometry': function (geometry) { if (geometry == null) { return null; } if (!geometry.parts && geometry.points) { geometry.parts = [geometry.points.length]; } var geo = geometry.hasOwnProperty('geometryType') ? geometry : new ServerGeometry(geometry).toGeometry() || geometry; var geometryType = geo.geometryType || geo.type; var data; if (geometryType === "LinearRing") { geometryType = "LineString"; } if (geometryType === "LINEM") { geometryType = "MultiLineString"; } data = this.extract[geometryType.toLowerCase()].apply(this, [geo]); geometryType = geometryType === 'TEXT' ? 'Point' : geometryType; var json; if (geometryType === "Collection") { json = { "type": "GeometryCollection", "geometries": data }; } else { json = { "type": geometryType, "coordinates": data }; } return json; }, /** * @function SuperMap.Format.GeoJSON.extract.point * @description ä»ä¸ä¸ªç¹å¯¹è±¡ä¸è¿åä¸ä¸ªåæ ç»ã * @param {SuperMap.Geometry.Point} point - ä¸ä¸ªç¹å¯¹è±¡ã * @returns {Array} ä¸ä¸ªè¡¨ç¤ºä¸ä¸ªç¹çåæ ç»ã */ 'point': function (point) { var p = [point.x, point.y]; for (var name in point) { if (name !== "x" && name !== "y" && point[name] !== null && !isNaN(point[name])) { p.push(point[name]); } } return p; }, /** * @function SuperMap.Format.GeoJSON.extract.point * @description ä»ä¸ä¸ªææ¬å¯¹è±¡ä¸è¿åä¸ä¸ªåæ ç»ã * @param {Object} geo - ä¸ä¸ªææ¬å¯¹è±¡ã * @returns {Array} ä¸ä¸ªè¡¨ç¤ºä¸ä¸ªç¹çåæ ç»ã */ 'text': function (geo) { return [geo.points[0].x, geo.points[0].y]; }, /** * @function SuperMap.Format.GeoJSON.extract.multipoint * @description ä»ä¸ä¸ªå¤ç¹å¯¹è±¡ä¸è¿ä¸ä¸ªåæ ç»æ°ç»ã * @param {SuperMap.Geometry.MultiPoint} multipoint - å¤ç¹å¯¹è±¡ã * @returns {Array} ä¸ä¸ªè¡¨ç¤ºå¤ç¹çåæ ç»æ°ç»ã */ 'multipoint': function (multipoint) { var array = []; for (var i = 0, len = multipoint.components.length; i < len; ++i) { array.push(this.extract.point.apply(this, [multipoint.components[i]])); } return array; }, /** * @function SuperMap.Format.GeoJSON.extract.linestring * @description ä»ä¸ä¸ªçº¿å¯¹è±¡ä¸è¿åä¸ä¸ªåæ ç»æ°ç»ã * @param {SuperMap.Geometry.Linestring} linestring - 线对象ã * @returns {Array} ä¸ä¸ªè¡¨ç¤ºçº¿å¯¹è±¡çåæ ç»æ°ç»ã */ 'linestring': function (linestring) { var array = []; for (var i = 0, len = linestring.components.length; i < len; ++i) { array.push(this.extract.point.apply(this, [linestring.components[i]])); } return array; }, /** * @function SuperMap.Format.GeoJSON.extract.multilinestring * @description ä»ä¸ä¸ªå¤çº¿å¯¹è±¡ä¸è¿åä¸ä¸ªçº¿æ°ç»ã * @param {SuperMap.Geometry.MultiLinestring} multilinestring - å¤çº¿å¯¹è±¡ã * * @returns {Array} ä¸ä¸ªè¡¨ç¤ºå¤çº¿ç线æ°ç»ã */ 'multilinestring': function (multilinestring) { var array = []; for (var i = 0, len = multilinestring.components.length; i < len; ++i) { array.push(this.extract.linestring.apply(this, [multilinestring.components[i]])); } return array; }, /** * @function SuperMap.Format.GeoJSON.extract.polygon * @description ä»ä¸ä¸ªé¢å¯¹è±¡ä¸è¿åä¸ç»çº¿ç¯ã * @param {SuperMap.Geometry.Polygon} polygon - é¢å¯¹è±¡ã * @returns {Array} ä¸ç»è¡¨ç¤ºé¢ç线ç¯ã */ 'polygon': function (polygon) { var array = []; for (var i = 0, len = polygon.components.length; i < len; ++i) { array.push(this.extract.linestring.apply(this, [polygon.components[i]])); } return array; }, /** * @function SuperMap.Format.GeoJSON.extract.multipolygon * @description ä»ä¸ä¸ªå¤é¢å¯¹è±¡ä¸è¿åä¸ç»é¢ã * @param {SuperMap.Geometry.MultiPolygon} multipolygon - å¤é¢å¯¹è±¡ã * @returns {Array} ä¸ç»è¡¨ç¤ºå¤é¢çé¢ã */ 'multipolygon': function (multipolygon) { var array = []; for (var i = 0, len = multipolygon.components.length; i < len; ++i) { array.push(this.extract.polygon.apply(this, [multipolygon.components[i]])); } return array; }, /** * @function SuperMap.Format.GeoJSON.extract.collection * @description ä»ä¸ä¸ªå ä½è¦ç´ éåä¸ä¸ç»å ä½è¦ç´ æ°ç»ã * @param {SuperMap.Geometry.Collection} collection - å ä½è¦ç´ éåã * @returns {Array} ä¸ç»è¡¨ç¤ºå ä½è¦ç´ éåçå ä½è¦ç´ æ°ç»ã */ 'collection': function (collection) { var len = collection.components.length; var array = new Array(len); for (var i = 0; i < len; ++i) { array[i] = this.extract.geometry.apply(this, [collection.components[i]]); } return array; } }; } /** * @function SuperMap.Format.GeoJSON.prototype.read * @description å° GeoJSON 对象æè GeoJSON 对象å符串转æ¢ä¸º SuperMap Feature 对象ã * @param {GeoJSONObject} json - GeoJSON 对象ã * @param {string} [type='FeaureCollection'] - å¯éçå符串ï¼å®å³å®äºè¾åºçæ ¼å¼ãæ¯æç弿ï¼"Geometry","Feature"ï¼å "FeatureCollection"ï¼å¦ææ¤å¼ä¸ºnullã * @param {Function} filter - å¯¹è±¡ä¸æ¯ä¸ªå±æ¬¡æ¯ä¸ªé®å¼å¯¹é½ä¼è°ç¨æ¤å½æ°å¾åºä¸ä¸ªç»æãæ¯ä¸ªå¼é½ä¼è¢« filter 彿°çç»æææ¿æ¢æãè¿ä¸ªå½æ°å¯è¢«ç¨æ¥å°æäºå¯¹è±¡è½¬åææä¸ªç±»ç¸åºçå¯¹è±¡ï¼æè å°æ¥æå符串转åæDate对象ã * @returns {Object} è¿åå¼ä¾èµäº type åæ°çå¼ã * -妿 type çäº "FeatureCollection"ï¼è¿åå¼å°ä¼æ¯ {@link SuperMap.Feature.Vector} æ°ç»ã * -妿 type 为 "Geometry",è¾å ¥ç JSON å¯¹è±¡å¿ é¡»è¡¨ç¤ºä¸ä¸ªå¯ä¸çå ä½ä½ï¼ç¶åè¿åå¼å°±ä¼æ¯ {@link SuperMap.Feature.Geometry}ã * -妿 type 为 "Feature"ï¼è¾å ¥ç JSON 对象ä¹å¿ 须表示çä¸ä¸ªè¦ç´ ï¼è¿æ ·è¿å弿伿¯ {@link SuperMap.Feature.Vector}ã */ read(json, type, filter) { type = (type) ? type : "FeatureCollection"; var results = null; var obj = null; if (typeof json == "string") { obj = super.read(json, filter); } else { obj = json; } if (!obj) { //SuperMap.Console.error("Bad JSON: " + json); } else if (typeof (obj.type) != "string") { //SuperMap.Console.error("Bad GeoJSON - no type: " + json); } else if (this.isValidType(obj, type)) { switch (type) { case "Geometry": try { results = this.parseGeometry(obj); } catch (err) { //SuperMap.Console.error(err); } break; case "Feature": try { results = this.parseFeature(obj); results.type = "Feature"; } catch (err) { //SuperMap.Console.error(err); } break; case "FeatureCollection": // for type FeatureCollection, we allow input to be any type results = []; switch (obj.type) { case "Feature": try { results.push(this.parseFeature(obj)); } catch (err) { results = null; //SuperMap.Console.error(err); } break; case "FeatureCollection": for (var i = 0, len = obj.features.length; i < len; ++i) { try { results.push(this.parseFeature(obj.features[i])); } catch (err) { results = null; // SuperMap.Console.error(err); } } break; default: try { var geom = this.parseGeometry(obj); results.push(new Vector(geom)); } catch (err) { results = null; //SuperMap.Console.error(err); } } break; default: break; } } return results; } /** * @function SuperMap.Format.GeoJSON.prototype.write * @description iServer Geometry JSON 对象 转 GeoJSON对象å符串ã * @param {Object} obj - iServer Geometry JSON 对象ã * @param {boolean} [pretty=false] - æ¯å¦ä½¿ç¨æ¢è¡åç¼©è¿æ¥æ§å¶è¾åºã * @returns {GeoJSONObject} ä¸ä¸ª GeoJSON å符串ï¼å®è¡¨ç¤ºäºè¾å ¥çå ä½å¯¹è±¡ï¼è¦ç´ å¯¹è±¡ï¼æè è¦ç´ 对象æ°ç»ã */ write(obj, pretty) { return super.write(this.toGeoJSON(obj), pretty); } /** * @function SuperMap.Format.GeoJSON.prototype.fromGeoJSON * @version 9.1.1 * @description å° GeoJSON 对象æè GeoJSON 对象å符串转æ¢ä¸ºiServer Feature JSONã * @param {GeoJSONObject} json - GeoJSON 对象ã * @param {string} [type='FeaureCollection'] - å¯éçå符串ï¼å®å³å®äºè¾åºçæ ¼å¼ãæ¯æç弿ï¼"Geometry","Feature"ï¼å "FeatureCollection"ï¼å¦ææ¤å¼ä¸ºnullã * @param {Function} filter - å¯¹è±¡ä¸æ¯ä¸ªå±æ¬¡æ¯ä¸ªé®å¼å¯¹é½ä¼è°ç¨æ¤å½æ°å¾åºä¸ä¸ªç»æãæ¯ä¸ªå¼é½ä¼è¢« filter 彿°çç»æææ¿æ¢æãè¿ä¸ªå½æ°å¯è¢«ç¨æ¥å°æäºå¯¹è±¡è½¬åææä¸ªç±»ç¸åºçå¯¹è±¡ï¼æè å°æ¥æå符串转åæDate对象ã * @returns {Object} iServer Feature JSONã */ fromGeoJSON(json, type, filter) { let feature = this.read(json, type, filter); if (!Util.isArray(feature)) { return this._toiSevrerFeature(feature); } return feature.map((element) => { return this._toiSevrerFeature(element); }) } /** * @function SuperMap.Format.GeoJSON.prototype.toGeoJSON * @version 9.1.1 * @description å° iServer Feature JSON 对象转æ¢ä¸º GeoJSON 对象ã * @param {Object} obj - iServer Feature JSONã * @returns {GeoJSONObject} GeoJSON 对象ã */ toGeoJSON(obj) { var geojson = { "type": null }; if (Util.isArray(obj)) { geojson.type = "FeatureCollection"; var numFeatures = obj.length; geojson.features = new Array(numFeatures); for (var i = 0; i < numFeatures; ++i) { var element = obj[i]; if (isGeometry(element)) { let feature = {}; feature.geometry = element; geojson.features[i] = this.extract.feature.apply(this, [feature]); } else { geojson.features[i] = this.extract.feature.apply(this, [element]); } } } else if (isGeometry(obj)) { let feature = {}; feature.geometry = obj; geojson = this.extract.feature.apply(this, [feature]); } else { geojson = this.extract.feature.apply(this, [obj]); } function isGeometry(input) { return (input.hasOwnProperty("parts") && input.hasOwnProperty("points")) || input.hasOwnProperty("geoParts"); } return geojson; } /** * @function SuperMap.Format.GeoJSON.prototype.isValidType * @description æ£æ¥ä¸ä¸ª GeoJSON 对象æ¯å¦åç»å®çç±»åç¸ç¬¦çåæ³ç对象ã * @returns {boolean} GeoJSON æ¯å¦æ¯ç»å®ç±»åçåæ³å¯¹è±¡ã * @private */ isValidType(obj, type) { var valid = false; switch (type) { case "Geometry": if (Util.indexOf( ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "Box", "GeometryCollection" ], obj.type) == -1) { // unsupported geometry type //SuperMap.Console.error("Unsupported geometry type: " + // obj.type); } else { valid = true; } break; case "FeatureCollection": // allow for any type to be converted to a feature collection valid = true; break; default: // for Feature types must match if (obj.type == type) { valid = true; } else { //SuperMap.Console.error("Cannot convert types from " + //obj.type + " to " + type); } } return valid; } /** * @function SuperMap.Format.GeoJSON.prototype.parseFeature * @description å°ä¸ä¸ª GeoJSON ä¸ç feature è½¬åæ {@link SuperMap.Feature.Vector}> 对象ã * @private * @param {GeoJSONObject} obj - ä» GeoJSON 对象ä¸å建ä¸ä¸ªå¯¹è±¡ã * @returns {SuperMap.Feature.Vector} ä¸ä¸ªè¦ç´ ã */ parseFeature(obj) { var feature, geometry, attributes, bbox; attributes = (obj.properties) ? obj.properties : {}; bbox = (obj.geometry && obj.geometry.bbox) || obj.bbox; try { geometry = this.parseGeometry(obj.geometry); } catch (err) { // deal with bad geometries throw err; } feature = new Vector(geometry, attributes); if (bbox) { feature.bounds = Bounds.fromArray(bbox); } if (obj.id) { feature.fid = obj.id; } return feature; } /** * @function SuperMap.Format.GeoJSON.prototype.parseGeometry * @description å°ä¸ä¸ª GeoJSON ä¸çå ä½è¦ç´ è½¬åæ {@link SuperMap.Geometry} 对象ã * @param {GeoJSONObject} obj - ä» GeoJSON 对象ä¸å建ä¸ä¸ªå¯¹è±¡ã * @returns {SuperMap.Geometry} ä¸ä¸ªå ä½è¦ç´ ã * @private */ parseGeometry(obj) { if (obj == null) { return null; } var geometry; if (obj.type == "GeometryCollection") { if (!(Util.isArray(obj.geometries))) { throw "GeometryCollection must have geometries array: " + obj; } var numGeom = obj.geometries.length; var components = new Array(numGeom); for (var i = 0; i < numGeom; ++i) { components[i] = this.parseGeometry.apply( this, [obj.geometries[i]] ); } geometry = new Collection(components); } else { if (!(Util.isArray(obj.coordinates))) { throw "Geometry must have coordinates array: " + obj; } if (!this.parseCoords[obj.type.toLowerCase()]) { throw "Unsupported geometry type: " + obj.type; } try { geometry = this.parseCoords[obj.type.toLowerCase()].apply( this, [obj.coordinates] ); } catch (err) { // deal with bad coordinates throw err; } } return geometry; } /** * @function SuperMap.Format.GeoJSON.prototype.createCRSObject * @description ä»ä¸ä¸ªè¦ç´ 对象ä¸å建ä¸ä¸ªåæ åè系对象ã * @param {SuperMap.Feature.Vector} object - è¦ç´ 对象ã * @private * @returns {GeoJSONObject} ä¸ä¸ªå¯ä½ä¸º GeoJSON 对象ç CRS 屿§ä½¿ç¨ç对象ã */ createCRSObject(object) { var proj = object.layer.projection.toString(); var crs = {}; if (proj.match(/epsg:/i)) { var code = parseInt(proj.substring(proj.indexOf(":") + 1)); if (code == 4326) { crs = { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }; } else { crs = { "type": "name", "properties": { "name": "EPSG:" + code } }; } } return crs; } _toiSevrerFeature(feature) { const attributes = feature.attributes; const attrNames = []; const attrValues = []; for (var attr in attributes) { attrNames.push(attr); attrValues.push(attributes[attr]); } const newFeature = { fieldNames: attrNames, fieldValues: attrValues, geometry: ServerGeometry.fromGeometry(feature.geometry) }; newFeature.geometry.id = feature.fid; return newFeature; } createAttributes(feature) { if (!feature) { return null; } var attr = {}; processFieldsAttributes(feature, attr); var exceptKeys = ["fieldNames", "fieldValues", "geometry", "stringID", "ID"]; for (var key in feature) { if (exceptKeys.indexOf(key) > -1) { continue; } attr[key] = feature[key]; } function processFieldsAttributes(feature, attributes) { if (!(feature.hasOwnProperty("fieldNames") && feature.hasOwnProperty("fieldValues"))) { return; } var names = feature.fieldNames, values = feature.fieldValues; for (var i in names) { attributes[names[i]] = values[i]; } } return attr; } } SuperMap.Format.GeoJSON = GeoJSON;