Class: GeoJSONFormat

GeoJSONFormat

GeoJSON 的读和写。使用 GeoJSONObject 构造器创建一个 GeoJSON 解析器。

new GeoJSONFormat(options)

Usage
import { GeoJSONFormat } from '@supermapgis/iclient-leaflet';

new GeoJSONFormat(options);
<script type="text/javascript" src="https://iclient.supermap.io/dist/leaflet/iclient-leaflet.js"></script>
<script>
  new L.supermap.Format.GeoJSON({paramsNames});
  // 弃用的写法
  new SuperMap.Format.GeoJSON(options);
</script>
common/format/GeoJSON.js, line 44
Name Type Description
options Object 可选

可选参数。

Name Type Default Description
indent string " " 可选

用于格式化输出,indent 字符串会在每次缩进的时候使用一次。

space string " " 可选

用于格式化输出,space 字符串会在名值对的 ":" 后边添加。

newline string "\n" 可选

用于格式化输出,newline 字符串会用在每一个名值对或数组项末尾。

level number 0 可选

用于格式化输出,表示的是缩进级别。

pretty boolean false 可选

是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。

nativeJSON boolean 可选

需要被注册的监听器对象。

ignoreExtraDims boolean true 可选

忽略维度超过 2 的几何要素。

Extends

GeoJSONFormat -> JSONFormat -> Format

Members

dataObject

当 keepData 属性设置为 true,这是传递给 read 操作的要被解析的字符串。

ignoreExtraDimsboolean

忽略维度超过 2 的几何要素。

Default Value:
true

indentstring

用于格式化输出,indent 字符串会在每次缩进的时候使用一次。

Default Value:
" "

keepDataObject

保持最近读到的数据的引用(通过 data 属性)。

levelnumber

用于格式化输出,表示的是缩进级别。

nativeJSONboolean

判断浏览器是否原生支持 JSON 格式数据。

newlinestring

用于格式化输出,newline 字符串会用在每一个名值对或数组项末尾。

Default Value:
"\n"

prettyboolean

是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。

serialize

提供一些类型对象转 JSON 字符串的方法。

spacestring

用于格式化输出,space 字符串会在名值对的 ":" 后边添加。

Default Value:
" "

Methods

static getGeoJSONType(obj){string|null}

common/format/GeoJSON.js, line 643

判断一个对象是否是合法的 GeoJSON 对象,如果不合法返回空,如果是合法的 GeoJSON 对象返回 FeatureCollection、Feature 或 Geometry。

Name Type Description
obj Object

待判断的对象。

Version:
  • 12.1.0
Returns:
Type Description
string | null 失败返回 null,成功返回 "FeatureCollection"、"Feature" 或 "Geometry"。

static isGeoJSON(obj){boolean}

common/format/GeoJSON.js, line 624

判断一个对象是否是合法的 GeoJSON 对象。

Name Type Description
obj Object

待判断的对象。

Version:
  • 12.1.0
Returns:
Type Description
boolean 是否是合法的 GeoJSON 对象。

inherited destroy()

common/format/Format.js, line 38

销毁该格式类,释放相关资源。

fromGeoJSON(json, type, filter){Object}

common/format/GeoJSON.js, line 525

将 GeoJSON 对象或者 GeoJSON 对象字符串转换为 SuperMap iServer Feature JSON。

Name Type Default Description
json GeoJSONObject

GeoJSON 对象。

type string 'FeaureCollection' 可选

可选的字符串,它决定了输出的格式。支持的值有:"Geometry","Feature",和 "FeatureCollection",如果此值为null。

filter function

对象中每个层次每个键值对都会调用此函数得出一个结果。每个值都会被 filter 函数的结果所替换掉。这个函数可被用来将某些对象转化成某个类相应的对象,或者将日期字符串转化成Date对象。

Version:
  • 9.1.1
Returns:
Type Description
Object SuperMap iServer Feature JSON。

read(json, type, filter){Object}

common/format/GeoJSON.js, line 434

将 GeoJSON 对象或者 GeoJSON 对象字符串转换为 SuperMap Feature 对象。

Name Type Default Description
json GeoJSONObject

GeoJSON 对象。

type string 'FeaureCollection' 可选

可选的字符串,它决定了输出的格式。支持的值有:"Geometry","Feature",和 "FeatureCollection",如果此值为null。

filter function

对象中每个层次每个键值对都会调用此函数得出一个结果。每个值都会被 filter 函数的结果所替换掉。这个函数可被用来将某些对象转化成某个类相应的对象,或者将日期字符串转化成Date对象。

Returns:
Type Description
Object 返回值依赖于 type 参数的值。
-如果 type 等于 "FeatureCollection",返回值将会是 FeatureVector 数组。
-如果 type 为 "Geometry",输入的 JSON 对象必须表示一个唯一的几何体,然后返回值就会是 Geometry
-如果 type 为 "Feature",输入的 JSON 对象也必须表示的一个要素,这样返回值才会是 FeatureVector

toGeoJSON(obj, options){GeoJSONObject}

common/format/GeoJSON.js, line 544

将 SuperMap iServer Feature JSON 对象转换为 GeoJSON 对象。

Name Type Description
obj Object

SuperMap iServer Feature JSON。

options Object 可选

转换选项。

Name Type Description
parseProperties boolean 可选

是否对查询返回的要素属性进行反序列化。

extraKeys boolean 可选

true: 额外的属性和properties平级,false:额外的属性存入properties。

Version:
  • 9.1.1
Returns:
Type Description
GeoJSONObject GeoJSON 对象。

write(obj, pretty){GeoJSONObject}

common/format/GeoJSON.js, line 515

SuperMap iServer Geometry JSON 对象 转 GeoJSON 对象字符串。

Name Type Default Description
obj Object

SuperMap iServer Geometry JSON 对象。

pretty boolean false 可选

是否使用换行和缩进来控制输出。

Returns:
Type Description
GeoJSONObject 一个 GeoJSON 字符串,它表示了输入的几何对象,要素对象,或者要素对象数组。