Skip to content

Commit 54e236e

Browse files
authored
Map: Support custom route modes
1 parent f926e57 commit 54e236e

File tree

8 files changed

+253
-12
lines changed

8 files changed

+253
-12
lines changed

packages/devextreme/js/__internal/ui/map/m_provider.dynamic.azure.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ class AzureProvider extends DynamicProvider {
4646
driving: 'car',
4747
walking: 'pedestrian',
4848
};
49-
return movementTypes[type] || movementTypes.driving;
49+
50+
if (!type) {
51+
return movementTypes.driving;
52+
}
53+
54+
return movementTypes[type] ?? type;
5055
}
5156

5257
_resolveLocation(location) {

packages/devextreme/js/__internal/ui/map/m_provider.dynamic.bing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class BingProvider extends DynamicProvider {
4747
}
4848

4949
_movementMode(type) {
50-
const movementTypes = {
51-
driving: Microsoft.Maps.Directions.RouteMode.driving,
52-
walking: Microsoft.Maps.Directions.RouteMode.walking,
53-
};
54-
return movementTypes[type] || movementTypes.driving;
50+
if (!type) {
51+
return Microsoft.Maps.Directions.RouteMode.driving;
52+
}
53+
54+
return Microsoft.Maps.Directions.RouteMode[type];
5555
}
5656

5757
_resolveLocation(location) {

packages/devextreme/js/__internal/ui/map/m_provider.dynamic.google.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ class GoogleProvider extends DynamicProvider {
100100
driving: google.maps.TravelMode.DRIVING,
101101
walking: google.maps.TravelMode.WALKING,
102102
};
103-
return movementTypes[type] || movementTypes.driving;
103+
104+
if (!type) {
105+
return movementTypes.driving;
106+
}
107+
108+
return movementTypes[type] ?? type;
104109
}
105110

106111
_resolveLocation(location) {

packages/devextreme/testing/helpers/forMap/bingMock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Microsoft.Maps = {
5050
},
5151
RouteMode: {
5252
driving: 1,
53-
walking: 2
53+
walking: 2,
54+
transit: 'transit',
5455
},
5556
Waypoint: function(options) {
5657
this.clear = function() {};// ()

packages/devextreme/testing/helpers/forMap/googleMock.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@
6161
TERRAIN: 4
6262
},
6363
TravelMode: {
64-
BICYCLING: 1,
65-
DRIVING: 2,
66-
TRANSIT: 3,
67-
WALKING: 4
64+
DRIVING: 1,
65+
WALKING: 2,
6866
},
6967
DirectionsStatus: {
7068
INVALID_REQUEST: 1,

packages/devextreme/testing/tests/DevExpress.ui.widgets/mapParts/azureTests.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import 'ui/map';
1010

1111
const MARKER_CLASS = 'dx-map-marker';
1212

13+
const getMovementMode = (map, type) => {
14+
return map._provider._movementMode(type);
15+
};
16+
1317
const prepareTestingAzureProvider = () => {
1418
atlas.mapResized = false;
1519
atlas.mapDisposed = false;
@@ -972,4 +976,66 @@ QUnit.module('Routes', moduleConfig, () => {
972976
}
973977
});
974978
});
979+
980+
[
981+
{
982+
routeMode: 'driving',
983+
expectedTravelMode: 'car',
984+
},
985+
{
986+
routeMode: 'walking',
987+
expectedTravelMode: 'pedestrian',
988+
}
989+
].forEach(({ routeMode, expectedTravelMode }) => {
990+
QUnit.test(`Provider should use ${expectedTravelMode} travelMode if route mode=${routeMode}`, function(assert) {
991+
const done = assert.async();
992+
993+
const map = $('#map').dxMap({
994+
provider: 'azure',
995+
onReady: () => {
996+
const travelMode = getMovementMode(map, routeMode);
997+
998+
assert.strictEqual(travelMode, expectedTravelMode);
999+
1000+
done();
1001+
}
1002+
}).dxMap('instance');
1003+
});
1004+
});
1005+
1006+
[
1007+
{ mode: undefined, scenario: 'undefined' },
1008+
{ mode: '', scenario: 'empty string' },
1009+
].forEach(({ mode, scenario }) => {
1010+
QUnit.test(`Provider should use car travelMode if route mode is ${scenario}`, function(assert) {
1011+
const done = assert.async();
1012+
1013+
const map = $('#map').dxMap({
1014+
provider: 'azure',
1015+
onReady: () => {
1016+
const travelMode = getMovementMode(map, mode);
1017+
1018+
assert.strictEqual(travelMode, 'car');
1019+
1020+
done();
1021+
}
1022+
}).dxMap('instance');
1023+
});
1024+
});
1025+
1026+
QUnit.test('Provider should use route mode as a travelMode without changes if it is not driving or walking mode', function(assert) {
1027+
const done = assert.async();
1028+
const customRouteMode = 'truck';
1029+
1030+
const map = $('#map').dxMap({
1031+
provider: 'azure',
1032+
onReady: () => {
1033+
const travelMode = getMovementMode(map, customRouteMode);
1034+
1035+
assert.strictEqual(travelMode, customRouteMode);
1036+
1037+
done();
1038+
}
1039+
}).dxMap('instance');
1040+
});
9751041
});

packages/devextreme/testing/tests/DevExpress.ui.widgets/mapParts/bingTests.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,89 @@ QUnit.test('routes', function(assert) {
11031103
});
11041104
});
11051105

1106+
[
1107+
{
1108+
mode: 'driving',
1109+
actualMode: 1,
1110+
},
1111+
{
1112+
mode: 'walking',
1113+
actualMode: 2,
1114+
},
1115+
].forEach(({ mode, actualMode }) => {
1116+
QUnit.test(`Route mode should be converted correctly if ${mode} mode is passed`, function(assert) {
1117+
const done = assert.async();
1118+
1119+
$('#map').dxMap({
1120+
provider: 'bing',
1121+
routes: [
1122+
{
1123+
mode,
1124+
locations: [
1125+
[40.737102, -73.990318],
1126+
[40.749825, -73.987963],
1127+
]
1128+
},
1129+
],
1130+
onReady: function() {
1131+
assert.strictEqual(window.Microsoft.directionsOptions.routeMode, actualMode, 'direction mode specified correctly');
1132+
1133+
done();
1134+
}
1135+
});
1136+
});
1137+
});
1138+
1139+
QUnit.test('Route mode should be passed without changes if it is not driving or walking mode', function(assert) {
1140+
const done = assert.async();
1141+
const customRouteMode = 'transit';
1142+
1143+
$('#map').dxMap({
1144+
provider: 'bing',
1145+
routes: [
1146+
{
1147+
mode: customRouteMode,
1148+
locations: [
1149+
[40.737102, -73.990318],
1150+
[40.749825, -73.987963],
1151+
]
1152+
},
1153+
],
1154+
onReady: function() {
1155+
assert.strictEqual(window.Microsoft.directionsOptions.routeMode, customRouteMode, 'custom route mode is passed as it is');
1156+
1157+
done();
1158+
}
1159+
});
1160+
});
1161+
1162+
[
1163+
{ mode: undefined, scenario: 'undefined' },
1164+
{ mode: '', scenario: 'empty string' },
1165+
].forEach(({ mode, scenario }) => {
1166+
QUnit.test(`Driving route mode should be used by default if route mode is ${scenario}`, function(assert) {
1167+
const done = assert.async();
1168+
1169+
$('#map').dxMap({
1170+
provider: 'bing',
1171+
routes: [
1172+
{
1173+
mode,
1174+
locations: [
1175+
[40.737102, -73.990318],
1176+
[40.749825, -73.987963],
1177+
]
1178+
},
1179+
],
1180+
onReady: function() {
1181+
assert.strictEqual(window.Microsoft.directionsOptions.routeMode, Microsoft.Maps.Directions.RouteMode.driving, 'default driving direction mode is used');
1182+
1183+
done();
1184+
}
1185+
});
1186+
});
1187+
});
1188+
11061189
QUnit.test('add route', function(assert) {
11071190
const done = assert.async();
11081191
const d = $.Deferred();

packages/devextreme/testing/tests/DevExpress.ui.widgets/mapParts/googleTests.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,89 @@ QUnit.test('routes', function(assert) {
13591359
});
13601360
});
13611361

1362+
[
1363+
{
1364+
mode: 'driving',
1365+
actualMode: 1,
1366+
},
1367+
{
1368+
mode: 'walking',
1369+
actualMode: 2,
1370+
},
1371+
].forEach(({ mode, actualMode }) => {
1372+
QUnit.test(`Route mode should be converted correctly if ${mode} mode is passed`, function(assert) {
1373+
const done = assert.async();
1374+
1375+
$('#map').dxMap({
1376+
provider: 'google',
1377+
routes: [
1378+
{
1379+
mode,
1380+
locations: [
1381+
[40.737102, -73.990318],
1382+
[40.749825, -73.987963],
1383+
]
1384+
},
1385+
],
1386+
onReady: function() {
1387+
assert.strictEqual(window.google.directionTravelMode, actualMode, 'direction mode specified correctly');
1388+
1389+
done();
1390+
}
1391+
});
1392+
});
1393+
});
1394+
1395+
QUnit.test('Route mode should be passed without changes if it is not driving or walking mode', function(assert) {
1396+
const done = assert.async();
1397+
const customRouteMode = 'swiming';
1398+
1399+
$('#map').dxMap({
1400+
provider: 'google',
1401+
routes: [
1402+
{
1403+
mode: customRouteMode,
1404+
locations: [
1405+
[40.737102, -73.990318],
1406+
[40.749825, -73.987963],
1407+
]
1408+
},
1409+
],
1410+
onReady: function() {
1411+
assert.strictEqual(window.google.directionTravelMode, customRouteMode, 'direction mode passes as it is');
1412+
1413+
done();
1414+
}
1415+
});
1416+
});
1417+
1418+
[
1419+
{ mode: undefined, scenario: 'undefined' },
1420+
{ mode: '', scenario: 'empty string' },
1421+
].forEach(({ mode, scenario }) => {
1422+
QUnit.test(`Driving route mode should be used by default if route mode is ${scenario}`, function(assert) {
1423+
const done = assert.async();
1424+
1425+
$('#map').dxMap({
1426+
provider: 'google',
1427+
routes: [
1428+
{
1429+
mode,
1430+
locations: [
1431+
[40.737102, -73.990318],
1432+
[40.749825, -73.987963],
1433+
]
1434+
},
1435+
],
1436+
onReady: function() {
1437+
assert.strictEqual(window.google.directionTravelMode, google.maps.TravelMode.DRIVING, 'default driving direction mode is used');
1438+
1439+
done();
1440+
}
1441+
});
1442+
});
1443+
});
1444+
13621445
QUnit.test('add route', function(assert) {
13631446
const done = assert.async();
13641447
const d = $.Deferred();

0 commit comments

Comments
 (0)