diff --git a/src/geometry/GeometryCollection.js b/src/geometry/GeometryCollection.js index f8ffa5b98..fc4f9a64c 100644 --- a/src/geometry/GeometryCollection.js +++ b/src/geometry/GeometryCollection.js @@ -1,4 +1,4 @@ -import { isFunction, isArrayHasData, isNil } from '../core/util'; +import { isFunction, isArrayHasData, isNil, extend } from '../core/util'; import { createFilter, getFilterFeature } from '@maptalks/feature-filter'; import { getExternalResources } from '../core/util/resource'; import Coordinate from '../geo/Coordinate'; @@ -416,6 +416,8 @@ class GeometryCollection extends Geometry { } //for toJSON _toJSON(options) { + //fix call from feature-filter package + options = extend({}, options); //Geometry了用的是toGeoJSON(),如果里面包含特殊图形(Circle等),就不能简单的用toGeoJSON代替了,否则反序列化回来就不是原来的图形了 const feature = { 'type': 'Feature', diff --git a/test/geometry/GeometryCollectionSpec.js b/test/geometry/GeometryCollectionSpec.js index a708ae1d9..75ffc2c7a 100644 --- a/test/geometry/GeometryCollectionSpec.js +++ b/test/geometry/GeometryCollectionSpec.js @@ -349,6 +349,105 @@ describe('#GeometryCollection', function () { expect(selection.getGeometries()).to.have.length(points.length); }); }); + + it('#2146 _toJSON(null) from feature-filter', function () { + const geojson = { + "type": "FeatureCollection", + "name": "aa", + "crs": { + "type": "name", + "properties": { + "name": "EPSG:4490" + } + }, + "features": [ + { + "type": "Feature", + "geometry": { + "type": "GeometryCollection", + "geometries": [ + { + "type": "Polygon", + "coordinates": [ + [ + [113.7991529327, 23.0121665284], + [113.7605656502, 22.9686311814], + [113.8260686078, 22.9546199745], + [113.8198107317, 23.0045461461], + [113.7991529327, 23.0121665284] + ] + ] + }, + { + "type": "Polygon", + "coordinates": [ + [ + [113.8688589262, 22.9914540607], + [113.8333100818, 22.9400538911], + [113.8869830716, 22.9190765221], + [113.8939079988, 22.9690147904], + [113.8688589262, 22.9914540607] + ] + ] + }, + { + "type": "Polygon", + "coordinates": [ + [ + [113.7786088849, 22.9485879648], + [113.7591122414, 22.8866803638], + [113.8297744355, 22.8793652689], + [113.8198854714, 22.9481623574], + [113.7786088849, 22.9485879648] + ] + ] + }, + { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [113.8654530057, 23.0430565973], + [113.8432406194, 23.0525926525], + [113.8218502836, 23.0236615414], + [113.870137785, 23.0034008379], + [113.8654530057, 23.0430565973] + ] + ], + [ + [ + [113.8561406429, 23.0607279435], + [113.8339123801, 23.0802969357], + [113.8189838691, 23.0439658919], + [113.8561406429, 23.0607279435] + ] + ] + ] + } + ] + }, + "properties": { + "OBJECTID": 1, + "SHAPE_Length": 20977.022743581954, + "SHAPE_Area": 24845610.21174327 + } + } + ] + } + const polygons = maptalks.GeoJSON.toGeometry(geojson); + layer = new maptalks.VectorLayer("v").addTo(map); + layer.setStyle({ + symbol: { + polygonFill: '#FFFFFF', + polygonOpacity: 1, + lineColor: 'blue', + lineWidth: 2, + lineDasharray: [10, 10], + } + }) + layer.addGeometry(polygons) + }); + }); function genPoints() {