Skip to content

Commit 52355ee

Browse files
authored
fix GeometryCollection _toJSON error when options is null (#2147)
1 parent bf1ede2 commit 52355ee

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

src/geometry/GeometryCollection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFunction, isArrayHasData, isNil } from '../core/util';
1+
import { isFunction, isArrayHasData, isNil, extend } from '../core/util';
22
import { createFilter, getFilterFeature } from '@maptalks/feature-filter';
33
import { getExternalResources } from '../core/util/resource';
44
import Coordinate from '../geo/Coordinate';
@@ -416,6 +416,8 @@ class GeometryCollection extends Geometry {
416416
}
417417
//for toJSON
418418
_toJSON(options) {
419+
//fix call from feature-filter package
420+
options = extend({}, options);
419421
//Geometry了用的是toGeoJSON(),如果里面包含特殊图形(Circle等),就不能简单的用toGeoJSON代替了,否则反序列化回来就不是原来的图形了
420422
const feature = {
421423
'type': 'Feature',

test/geometry/GeometryCollectionSpec.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,105 @@ describe('#GeometryCollection', function () {
349349
expect(selection.getGeometries()).to.have.length(points.length);
350350
});
351351
});
352+
353+
it('#2146 _toJSON(null) from feature-filter', function () {
354+
const geojson = {
355+
"type": "FeatureCollection",
356+
"name": "aa",
357+
"crs": {
358+
"type": "name",
359+
"properties": {
360+
"name": "EPSG:4490"
361+
}
362+
},
363+
"features": [
364+
{
365+
"type": "Feature",
366+
"geometry": {
367+
"type": "GeometryCollection",
368+
"geometries": [
369+
{
370+
"type": "Polygon",
371+
"coordinates": [
372+
[
373+
[113.7991529327, 23.0121665284],
374+
[113.7605656502, 22.9686311814],
375+
[113.8260686078, 22.9546199745],
376+
[113.8198107317, 23.0045461461],
377+
[113.7991529327, 23.0121665284]
378+
]
379+
]
380+
},
381+
{
382+
"type": "Polygon",
383+
"coordinates": [
384+
[
385+
[113.8688589262, 22.9914540607],
386+
[113.8333100818, 22.9400538911],
387+
[113.8869830716, 22.9190765221],
388+
[113.8939079988, 22.9690147904],
389+
[113.8688589262, 22.9914540607]
390+
]
391+
]
392+
},
393+
{
394+
"type": "Polygon",
395+
"coordinates": [
396+
[
397+
[113.7786088849, 22.9485879648],
398+
[113.7591122414, 22.8866803638],
399+
[113.8297744355, 22.8793652689],
400+
[113.8198854714, 22.9481623574],
401+
[113.7786088849, 22.9485879648]
402+
]
403+
]
404+
},
405+
{
406+
"type": "MultiPolygon",
407+
"coordinates": [
408+
[
409+
[
410+
[113.8654530057, 23.0430565973],
411+
[113.8432406194, 23.0525926525],
412+
[113.8218502836, 23.0236615414],
413+
[113.870137785, 23.0034008379],
414+
[113.8654530057, 23.0430565973]
415+
]
416+
],
417+
[
418+
[
419+
[113.8561406429, 23.0607279435],
420+
[113.8339123801, 23.0802969357],
421+
[113.8189838691, 23.0439658919],
422+
[113.8561406429, 23.0607279435]
423+
]
424+
]
425+
]
426+
}
427+
]
428+
},
429+
"properties": {
430+
"OBJECTID": 1,
431+
"SHAPE_Length": 20977.022743581954,
432+
"SHAPE_Area": 24845610.21174327
433+
}
434+
}
435+
]
436+
}
437+
const polygons = maptalks.GeoJSON.toGeometry(geojson);
438+
layer = new maptalks.VectorLayer("v").addTo(map);
439+
layer.setStyle({
440+
symbol: {
441+
polygonFill: '#FFFFFF',
442+
polygonOpacity: 1,
443+
lineColor: 'blue',
444+
lineWidth: 2,
445+
lineDasharray: [10, 10],
446+
}
447+
})
448+
layer.addGeometry(polygons)
449+
});
450+
352451
});
353452

354453
function genPoints() {

0 commit comments

Comments
 (0)