Summary
Methods:
| isValidType |
检测GeoJSON对象的类型是否与指定类型一致。当type是“Geometry”时,geoJson的type是“Point”,“MultiPoint”,“LineString”,“MultiLineString”, |
| read |
解析Geojson对象,支持所有标准的geojson对象,即对象的type属性为"Feature","FeatureCollection","GeometryCollection","MultiPolygon","Polygon","MultiLineString","LineString","Point","MultiPoint" |
| readCollectionFeatures |
从GeoJSON格式字符串或GeoJSON对象对解析出含有集合几何体的地理要素数组。 |
| readFeature |
从GeoJSON格式字符串或GeoJSON对象中解析出地理要素。 |
| readFeatureFromObject |
从GeoJSON对象中解析出地理要素。 |
| readFeatures |
从GeoJSON格式字符串或GeoJSON对象解析出地理要素数组(注意:GeoJSON类型定义中不包含线环(LinearRing)类型)。 |
| readFeaturesByGeometryType |
从GeoJSON对象中解析出指定类型的地理要素数组。 |
| readFeaturesFromObject |
从GeoJSON对象中解析出地理要素数组。 |
| readGeometry |
从GeoJSON格式字符串或GeoJSON对象中解析出几何体。 |
| readGeometryFromObject |
从GeoJSON对象中解析出几何体。 |
| readLineFeatures |
从GeoJSON格式字符串或GeoJSON对象中解析出含有线状几何体的地理要素数组。 |
| readMLineFeatures |
从GeoJSON格式字符串或GeoJSON对象中对解析出多线含有多线几何体的地理要素。 |
| readMPointFeatures |
从GeoJSON格式字符串或GeoJSON对象对解析出含有多点几何体的地理要素数组。 |
| readMPolyFeatures |
从GeoJSON格式字符串或GeoJSON对象对解析出含有多面几何体的地理要素数组。 |
| readPointFeatures |
从GeoJSON格式字符串或GeoJSON对象解析出含有点状几何体的地理要素数组。 |
| readPolyFeatures |
从GeoJSON格式字符串或GeoJSON对象对解析出含有面状几何体的地理要素数组。 |
| writeFeature |
把一个地理要素解析成"Feature"类型的GeoJSON格式的数据。 |
| writeFeatureObject |
把一个地理要素转换成"Feature"类型的GeoJSON格式的数据。 |
| writeFeatures |
把一个地理要素数组解析成"FeatureCollection"类型的GeoJSON数据格式。 |
| writeFeaturesObject |
把一个地理要素数组解析成"FeatureCollection"类型的GeoJSON格式的数据。 |
| writeGeometry |
把一个几何体转化成GeoJSON格式对象。 |
Constructor
new GeoJSON()
Example
let geoJSON = new hmap.format.GeoJSON();
Methods
-
isValidType(geoJson, type) → {Boolean}
-
检测GeoJSON对象的类型是否与指定类型一致。当type是“Geometry”时,geoJson的type是“Point”,“MultiPoint”,“LineString”,“MultiLineString”,
“Polygon”,“MultiPolygon”和“GeometryCollection”中的一种返回true,否则返回false;当type是其他类型时,判断geoJson的type是否和type相同,相同返回true,
不同返回false。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
typeString 类型
Returns:
Boolean -为true时表示该对象类型与给定类型一致;为false则不一致。
Example
let geoJSON = new GeoJSON(); let jsonObj ={ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": {"prop0": "value0"} }, { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] ] }, "properties": { "prop0": "value0", "prop1": 0.0 } }, ] }; let isValid = geoJSON.isValidType(jsonObj,"FeatureCollection"); let jsonObj2 = { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] }, * "properties": { "prop0": "value0", "prop1": {"this": "that"} } }; isValid = geoJSON.isValidType(jsonObj2,"Geometry"); -
read(geoJson) → {Array.<module:feature~Vector>}
-
解析Geojson对象,支持所有标准的geojson对象,即对象的type属性为"Feature","FeatureCollection","GeometryCollection","MultiPolygon","Polygon","MultiLineString","LineString","Point","MultiPoint"
Parameters:
Name Type Description geoJsonObject GeoJson对象
-
readCollectionFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象对解析出含有集合几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readFeature(geoJson, filter) → {module:feature~Vector}
-
从GeoJSON格式字符串或GeoJSON对象中解析出地理要素。
Parameters:
Name Type Description geoJsonObject “Feature”类型的GeoJSON格式字符串或GeoJSON对象,当类型是字符串时,可以使用第二个参数指定的过滤函数进行过滤。
filterfunction 可选项。过滤函数,处理JSON对象中每个键值对,过滤函数返回的结果将替代原对象中的值。
Example
// geoJson参数为:Feature const exampleData = `{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5, 0] }, "properties": { "prop0": "value0" } }`; let result = geoJSON.readFeature(exampleData,function(key,value){ if(key == "properties"){ value.name = "point"; return value; } }); -
readFeatureFromObject(geoJsonObject) → {module:feature~Vector}
-
从GeoJSON对象中解析出地理要素。
Parameters:
Name Type Description geoJsonObjectObject “Feature”类型的GeoJSON对象。
Example
// geoJson参数为:Feature const exampleData = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5, 0] }, "properties": { "prop0": "value0" } }; let result = geoJSON.readFeaturesFromObject(exampleData); -
readFeatures(geoJson, filter) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象解析出地理要素数组(注意:GeoJSON类型定义中不包含线环(LinearRing)类型)。
Parameters:
Name Type Description geoJsonObject “FeatureCollection”类型的GeoJSON格式字符串或GeoJSON对象,当为字符串格式时,可通过filter函数进行过滤。
当不是FeatureCollection类型时,返回空数组。filterfunction 可选项。过滤函数,处理JSON对象中每个键值对,过滤函数返回的结果将替代原对象中的值。
Example
let geoJSON = new GeoJSON(); // geoJson参数为:FeatureCollection const exampleData1 = { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5, 0] }, "properties": { "prop0": "value0" } }] }; let result = geoJSON.readFeatures(exampleData1); -
readFeaturesByGeometryType(geoJsonObject, type) → {Array.<module:feature~Vector>}
-
从GeoJSON对象中解析出指定类型的地理要素数组。
Parameters:
Name Type Description geoJsonObjectObject “FeatureCollection”类型的GeoJSON对象,如果不是“FeatureCollection”类型,返回空数组。
typeString 地理要素的几何类型,可以是“Point”,“MultiPoint”,“LineString”,“MultiLineString”,“Polygon”,“MultiPolygon”中的一种,
其他类型将返回空数组。Example
let geoJSON = new GeoJSON(); // geoJson参数为:FeatureCollection const exampleData = { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5, 0] }, "properties": { "prop0": "value0" } }] }; let result = geoJSON.readFeaturesByGeometryType(exampleData,"Point"); -
readFeaturesFromObject(geoJsonObject) → {Array.<module:feature~Vector>}
-
从GeoJSON对象中解析出地理要素数组。
Parameters:
Name Type Description geoJsonObjectObject “FeatureCollection”类型的GeoJSON对象。当参数不是FeatureCollection时,返回空数组。
Example
let geoJSON = new GeoJSON(); // geoJson参数为:FeatureCollection const exampleData1 = { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5, 0] }, "properties": { "prop0": "value0" } }] }; let result = geoJSON.readFeaturesFromObject(exampleData1); -
readGeometry(geoJson, filter) → {module:geom~Geometry}
-
从GeoJSON格式字符串或GeoJSON对象中解析出几何体。
Parameters:
Name Type Description geoJsonString GeoJSON格式字符串或GeoJSON对象,支持“Point”,“MultiPoint”,“LineString”,“MultiLineString”,“Polygon”,“MultiPolygon”和“GeometryCollection”。
filterfunction 可选项。过滤函数,处理JSON对象中每个键值对,过滤函数返回的结果将替代原对象中的值。
-
readGeometryFromObject(geoJsonObject) → {module:geom~Geometry}
-
从GeoJSON对象中解析出几何体。
Parameters:
Name Type Description geoJsonObjectObject GeoJSON对象,支持“Point”,“MultiPoint”,“LineString”,“MultiLineString”,“Polygon”,“MultiPolygon”和“GeometryCollection”。
Throws:
当GeoJSON对象坐标数组或者GeoJSON对象类型不支持时,抛出异常
-
readLineFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象中解析出含有线状几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readMLineFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象中对解析出多线含有多线几何体的地理要素。
结果以几何体数组的形式返回,数组中几何体的类型均为多线几何体。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readMPointFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象对解析出含有多点几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readMPolyFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象对解析出含有多面几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readPointFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象解析出含有点状几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
readPolyFeatures(geoJson) → {Array.<module:feature~Vector>}
-
从GeoJSON格式字符串或GeoJSON对象对解析出含有面状几何体的地理要素数组。
结果以几何体数组的形式返回,数组中几何体的类型相同。Parameters:
Name Type Description geoJsonObject GeoJSON对象。
-
writeFeature(feature) → {String}
-
把一个地理要素解析成"Feature"类型的GeoJSON格式的数据。
Parameters:
Name Type Description featuremodule:feature~Vector 地理要素。
Returns:
String -GeoJSON格式数据的字符串。
Example
let point = new hmap.geom.Point(new hmap.basetype.Coordinate(120,30,0)); let feature = new hmap.feature.Vector(point); let geoJSON = new GeoJSON(); let result = geoJSON.writeFeature(feature); -
writeFeatureObject(feature) → {Object}
-
把一个地理要素转换成"Feature"类型的GeoJSON格式的数据。
Parameters:
Name Type Description featuremodule:feature~Vector 地理要素。
Returns:
Object -GeoJSON格式的数据。
Example
let geoJSON = new GeoJSON(); const point = new hmap.geom.Point(new hmap.basetype.Coordinate(120,30,0)); let feature = new hmap.feature.Vector(point,{'name':'name1','type':'type1'}); let result = geoJSON.writeFeatureObject(feature); -
writeFeatures(features) → {String}
-
把一个地理要素数组解析成"FeatureCollection"类型的GeoJSON数据格式。
Parameters:
Name Type Description featuresArray.<module:feature~Vector> 地理要素数组。
Returns:
String -GeoJSON数据格式的字符串。
Example
let coord1 = new hmap.basetype.Coordinate(120,30,0); let coord2 = new hmap.basetype.Coordinate(121,31,0); let point1 = new hmap.geom.Point(coord1); let point2 = new hmap.geom.Point(coord2); let feature1 = new hmap.feature.Vector(point1); let feature2 = new hmap.feature.Vector(point2); let geoJSON = new GeoJSON(); let result = geoJSON.writeFeatures([feature1,feature2]); -
writeFeaturesObject(features) → {Object}
-
把一个地理要素数组解析成"FeatureCollection"类型的GeoJSON格式的数据。
Parameters:
Name Type Description featuresArray.<module:feature~Vector> 地理要素数组。
Throws:
当参数features数组中的元素不是地理要素时,抛出异常
Returns:
Object -GeoJSON格式的数据。
-
writeGeometry(geom) → {Object}
-
把一个几何体转化成GeoJSON格式对象。
Parameters:
Name Type Description geommodule:geom~Geometry 几何体。
Returns:
Object -GeoJSON对象。
Example
let geoJSON = new GeoJSON(); let coord = new hmap.basetype.Coordinate(120,30,0); let point = new hmap.geom.Point(coord); let result = geoJSON.writeGeometry(point);