Skip to content

Commit

Permalink
fix GeometryCollection _toJSON error when options is null (#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu authored Dec 19, 2023
1 parent bf1ede2 commit 52355ee
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/geometry/GeometryCollection.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
99 changes: 99 additions & 0 deletions test/geometry/GeometryCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 52355ee

Please sign in to comment.