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

Method read

src/common/format/GeoJSON.js:446–513  ·  view source on GitHub ↗

* @function GeoJSONFormat.prototype.read * @description 将 GeoJSON 对象或者 GeoJSON 对象字符串转换为 SuperMap Feature 对象。 * @param {GeoJSONObject} json - GeoJSON 对象。 * @param {string} [type='FeaureCollection'] - 可选的字符串,它决定了输出的格式。支持的值有:"Geometry","Feature",和 "FeatureCollection",如果此值为null。 * @p

(json, type, filter)

Source from the content-addressed store, hash-verified

444 */
445
446 read(json, type, filter) {
447 type = (type) ? type : "FeatureCollection";
448 var results = null;
449 var obj = null;
450 if (typeof json == "string") {
451 obj = super.read(json, filter);
452 } else {
453 obj = json;
454 }
455 if (!obj) {
456 //console.error("Bad JSON: " + json);
457 } else if (typeof (obj.type) != "string") {
458 //console.error("Bad GeoJSON - no type: " + json);
459 } else if (this.isValidType(obj, type)) {
460 switch (type) {
461 case "Geometry":
462 try {
463 results = this.parseGeometry(obj);
464 } catch (err) {
465 //console.error(err);
466 }
467 break;
468 case "Feature":
469 try {
470 results = this.parseFeature(obj);
471 results.type = "Feature";
472 } catch (err) {
473 //console.error(err);
474 }
475 break;
476 case "FeatureCollection":
477 // for type FeatureCollection, we allow input to be any type
478 results = [];
479 switch (obj.type) {
480 case "Feature":
481 try {
482 results.push(this.parseFeature(obj));
483 } catch (err) {
484 results = null;
485 //console.error(err);
486 }
487 break;
488 case "FeatureCollection":
489 for (var i = 0, len = obj.features.length; i < len; ++i) {
490 try {
491 results.push(this.parseFeature(obj.features[i]));
492 } catch (err) {
493 results = null;
494 // console.error(err);
495 }
496 }
497 break;
498 default:
499 try {
500 var geom = this.parseGeometry(obj);
501 results.push(new Vector(geom));
502 } catch (err) {
503 results = null;

Callers 1

fromGeoJSONMethod · 0.95

Calls 4

isValidTypeMethod · 0.95
parseGeometryMethod · 0.95
parseFeatureMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected