Skip to content

Commit 1cfd123

Browse files
authored
VectorMap: support mixed geometry types in GeoJSON (T1327745) (#33477)
1 parent 1d0f04c commit 1cfd123

3 files changed

Lines changed: 120 additions & 26 deletions

File tree

packages/devextreme/js/__internal/viz/vector_map/map_layer.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,29 @@ strategiesByType[TYPE_MARKER] = {
415415
},
416416
};
417417

418-
strategiesByGeometry[TYPE_AREA] = function (sample) {
419-
return {
420-
project(projection, coordinates) {
421-
return coordinates[0]
422-
&& coordinates[0][0]
423-
&& coordinates[0][0][0]
424-
&& typeof coordinates[0][0][0][0] === 'number' ? projectMultiPolygon(projection, coordinates) : projectPolygon(projection, coordinates);
425-
},
426-
};
418+
function projectAreaByGeometry(projection, coordinates) {
419+
return coordinates[0]
420+
&& coordinates[0][0]
421+
&& coordinates[0][0][0]
422+
&& typeof coordinates[0][0][0][0] === 'number'
423+
? projectMultiPolygon(projection, coordinates)
424+
: projectPolygon(projection, coordinates);
425+
}
426+
427+
strategiesByGeometry[TYPE_AREA] = function () {
428+
return { project: projectAreaByGeometry };
427429
};
428430

429-
strategiesByGeometry[TYPE_LINE] = function (sample) {
430-
const coordinates = sample.coordinates;
431-
return { project: coordinates[0] && coordinates[0][0] && typeof coordinates[0][0][0] === 'number' ? projectPolygon : projectLineString };
431+
function projectLineByGeometry(projection, coordinates) {
432+
return coordinates[0]
433+
&& coordinates[0][0]
434+
&& typeof coordinates[0][0][0] === 'number'
435+
? projectPolygon(projection, coordinates)
436+
: projectLineString(projection, coordinates);
437+
}
438+
439+
strategiesByGeometry[TYPE_LINE] = function () {
440+
return { project: projectLineByGeometry };
432441
};
433442

434443
strategiesByElementType[TYPE_MARKER] = {

packages/devextreme/testing/tests/DevExpress.viz.vectorMap/mapLayer.strategies.tests.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,30 @@ QUnit.test('Select project strategy by type (polygon/multipolygon)', function(as
101101
QUnit.test('Project', function(assert) {
102102
const projection = {
103103
project: function(coordinates) {
104-
return coordinates + '-proj';
104+
return coordinates * 2;
105+
}
106+
};
107+
const multilineProjection = {
108+
project: function(coordinates) {
109+
return coordinates.map(item => item * 2);
105110
}
106111
};
107112

108113
assert.deepEqual(lineStrategyLineString.project(projection, [
109-
'p1', 'p2', 'p3'
114+
1, 2, 3
110115
]), [
111-
['p1-proj', 'p2-proj', 'p3-proj']
116+
[2, 4, 6]
112117
], 'line linestring');
113-
assert.deepEqual(lineStrategyMultiLineString.project(projection, [
114-
['p1', 'p2'],
115-
['p3', 'p4', 'p5'],
116-
['p6']
117-
]), [
118-
['p1-proj', 'p2-proj'],
119-
['p3-proj', 'p4-proj', 'p5-proj'],
120-
['p6-proj']
121-
], 'line multilinestring');
122-
assert.deepEqual(pointDotStrategy.project(projection, ['p']), 'p-proj', 'point');
118+
assert.deepEqual(lineStrategyMultiLineString.project(multilineProjection, [[
119+
[1, 2],
120+
[3, 4, 5],
121+
[6]
122+
]]), [[
123+
[2, 4],
124+
[6, 8, 10],
125+
[12]
126+
]], 'line multilinestring');
127+
assert.deepEqual(pointDotStrategy.project(projection, [1]), 2, 'point');
123128
});
124129

125130
QUnit.test('Project area label', function(assert) {

packages/devextreme/testing/tests/DevExpress.viz.vectorMap/mapLayer_new.tests.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,90 @@ QUnit.test('Lines (MultiLineString)', function(assert) {
263263
]
264264
}], 'line 2 (complex)');
265265
assert.deepEqual(this.getLine(2).attr.getCall(0).args, [{
266-
points: []
266+
points: [[]]
267267
}], 'line 3 (degenerate)');
268268
});
269269

270+
QUnit.test('Lines (mixed LineString and MultiLineString, MultiLineString first) (T1327745)', function(assert) {
271+
this.createLayer({
272+
dataSource: {
273+
type: 'FeatureCollection',
274+
features: [
275+
{
276+
type: 'Feature',
277+
geometry: {
278+
type: 'MultiLineString',
279+
coordinates: [
280+
[[200, 100], [400, 0], [400, 300]],
281+
[[0, 0], [0, 300], [400, 300], [400, 0]]
282+
]
283+
},
284+
properties: {}
285+
},
286+
{
287+
type: 'Feature',
288+
geometry: {
289+
type: 'LineString',
290+
coordinates: [[100, 200], [300, 300], [400, 0]]
291+
},
292+
properties: {}
293+
}
294+
]
295+
}
296+
});
297+
298+
assert.strictEqual(this.getLine(0).attr.getCall(1).args[0]['class'], 'dxm-line', 'type');
299+
assert.deepEqual(this.getLine(0).attr.getCall(0).args, [{
300+
points: [
301+
[600, 400, 1000, 600, 1000, 0],
302+
[200, 600, 200, 0, 1000, 0, 1000, 600]
303+
]
304+
}], 'line 1 - MultiLineString');
305+
assert.deepEqual(this.getLine(1).attr.getCall(0).args, [{
306+
points: [[400, 200, 800, 0, 1000, 600]]
307+
}], 'line 2 - LineString (no NaN)');
308+
});
309+
310+
QUnit.test('Lines (mixed LineString and MultiLineString, LineString first) (T1327745)', function(assert) {
311+
this.createLayer({
312+
dataSource: {
313+
type: 'FeatureCollection',
314+
features: [
315+
{
316+
type: 'Feature',
317+
geometry: {
318+
type: 'LineString',
319+
coordinates: [[100, 200], [300, 300], [400, 0]]
320+
},
321+
properties: {}
322+
},
323+
{
324+
type: 'Feature',
325+
geometry: {
326+
type: 'MultiLineString',
327+
coordinates: [
328+
[[200, 100], [400, 0], [400, 300]],
329+
[[0, 0], [0, 300], [400, 300], [400, 0]]
330+
]
331+
},
332+
properties: {}
333+
}
334+
]
335+
}
336+
});
337+
338+
assert.strictEqual(this.getLine(0).attr.getCall(1).args[0]['class'], 'dxm-line', 'type');
339+
assert.deepEqual(this.getLine(0).attr.getCall(0).args, [{
340+
points: [[400, 200, 800, 0, 1000, 600]]
341+
}], 'line 1 - LineString');
342+
assert.deepEqual(this.getLine(1).attr.getCall(0).args, [{
343+
points: [
344+
[600, 400, 1000, 600, 1000, 0],
345+
[200, 600, 200, 0, 1000, 0, 1000, 600]
346+
]
347+
}], 'line 2 - MultiLineString (no NaN)');
348+
});
349+
270350
QUnit.test('Lines (simple data source)', function(assert) {
271351
this.createLayer({
272352
dataSource: [

0 commit comments

Comments
 (0)