Skip to content

Commit 71b9aed

Browse files
committed
补充ut review by songym ;修改GeoJSON问题 commit by songym
1 parent 8a4e233 commit 71b9aed

File tree

4 files changed

+420
-254
lines changed

4 files changed

+420
-254
lines changed

src/common/format/GeoJSON.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ export class GeoJSON extends JSONFormat {
259259
if (!geometry.parts && geometry.points) {
260260
geometry.parts = [geometry.points.length];
261261
}
262-
var geo = new ServerGeometry(geometry).toGeometry()||geometry;
263-
var geometryType = geo.geometryType||geo.type;
262+
var geo = new ServerGeometry(geometry).toGeometry() || geometry;
263+
var geometryType = geo.geometryType || geo.type;
264264
var data;
265265
if (geometryType === "LinearRing") {
266266
geometryType = "LineString";
@@ -502,12 +502,18 @@ export class GeoJSON extends JSONFormat {
502502
*/
503503
fromGeoJSON(json, type, filter) {
504504
let feature = this.read(json, type, filter);
505-
return ServerGeometry.fromGeometry(feature);
505+
if (!Util.isArray(feature)) {
506+
return this._toiSevrerFeature(feature);
507+
}
508+
return feature.map((element) => {
509+
return this._toiSevrerFeature(element);
510+
})
506511
}
512+
507513
/**
508514
* @function SuperMap.Format.GeoJSON.prototype.toGeoJSON
509515
* @version 9.1.1
510-
* @descriptionGeoJSON 对象或者GeoJSON 对象字符串转换为iServer Feature JSON。
516+
* @descriptioniServer Feature JSON 对象转换为 GeoJSON 对象
511517
* @param {Object} obj - iServer Feature JSON。
512518
* @returns {GeoJSONObject} GeoJSON 对象。
513519
*/
@@ -533,6 +539,8 @@ export class GeoJSON extends JSONFormat {
533539
let feature = {};
534540
feature.geometry = obj;
535541
geojson = this.extract.feature.apply(this, [feature]);
542+
} else {
543+
geojson = this.extract.feature.apply(this, [obj]);
536544
}
537545

538546
function isGeometry(input) {
@@ -553,10 +561,10 @@ export class GeoJSON extends JSONFormat {
553561
switch (type) {
554562
case "Geometry":
555563
if (Util.indexOf(
556-
["Point", "MultiPoint", "LineString", "MultiLineString",
557-
"Polygon", "MultiPolygon", "Box", "GeometryCollection"
558-
],
559-
obj.type) == -1) {
564+
["Point", "MultiPoint", "LineString", "MultiLineString",
565+
"Polygon", "MultiPolygon", "Box", "GeometryCollection"
566+
],
567+
obj.type) == -1) {
560568
// unsupported geometry type
561569
//SuperMap.Console.error("Unsupported geometry type: " +
562570
// obj.type);
@@ -682,7 +690,22 @@ export class GeoJSON extends JSONFormat {
682690
}
683691
return crs;
684692
}
685-
693+
_toiSevrerFeature(feature) {
694+
const attributes = feature.attributes;
695+
const attrNames = [];
696+
const attrValues = [];
697+
for (var attr in attributes) {
698+
attrNames.push(attr);
699+
attrValues.push(attributes[attr]);
700+
}
701+
const newFeature = {
702+
fieldNames: attrNames,
703+
fieldValues: attrValues,
704+
geometry: ServerGeometry.fromGeometry(feature.geometry)
705+
};
706+
newFeature.geometry.id = feature.fid;
707+
return newFeature;
708+
}
686709
createAttributes(feature) {
687710
if (!feature) {
688711
return null;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy