Skip to content

Commit 8a1139e

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
Map: Add location field to ClickEvent type and pass event to onClick (#29074)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 7f65035 commit 8a1139e

File tree

9 files changed

+40
-14
lines changed

9 files changed

+40
-14
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ const AzureProvider = DynamicProvider.inherit({
195195

196196
_clickActionHandler(e) {
197197
if (e.type === 'click') {
198-
this._fireClickAction({ location: this._normalizeLocation(e.position) });
198+
this._fireClickAction({
199+
location: this._normalizeLocation(e.position),
200+
event: e.originalEvent,
201+
});
199202
}
200203
},
201204

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const GoogleProvider = DynamicProvider.inherit({
228228
},
229229

230230
_clickActionHandler(e) {
231-
this._fireClickAction({ location: this._normalizeLocation(e.latLng) });
231+
this._fireClickAction({ location: this._normalizeLocation(e.latLng), event: e.domEvent });
232232
},
233233

234234
updateDimensions() {

packages/devextreme/js/ui/map.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export type MapType = 'hybrid' | 'roadmap' | 'satellite';
2626
* @type object
2727
* @inherits NativeEventInfo
2828
*/
29-
export type ClickEvent = NativeEventInfo<dxMap, MouseEvent | PointerEvent>;
29+
export type ClickEvent = NativeEventInfo<dxMap, MouseEvent | PointerEvent> & {
30+
/** @docid _ui_map_ClickEvent.location */
31+
location: MapLocation;
32+
};
3033

3134
/**
3235
* @docid _ui_map_DisposingEvent
@@ -133,6 +136,7 @@ export type RouteRemovedEvent = EventInfo<dxMap> & {
133136
};
134137

135138
/**
139+
* @docid
136140
* @public
137141
* @namespace DevExpress.ui
138142
*/

packages/devextreme/js/ui/map.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ export default Map;
4848
* @hidden
4949
*/
5050

51-
/**
52-
* @name MapLocation
53-
* @hidden
54-
*/
55-
5651
/**
5752
* @name dxMapOptions.onContentReady
5853
* @hidden true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@
397397
MouseEvent: function(latLng) {
398398
this.stop = function() {};
399399
this.latLng = latLng;
400+
this.domEvent = new MouseEvent({ type: 'click' });
400401
}
401402
}
402403
};

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,24 @@ QUnit.module('basic options', moduleConfig, () => {
466466
QUnit.test('Should add onClick handler with correct args', function(assert) {
467467
const done = assert.async();
468468
let clickFired = 0;
469+
const originalEvent = new PointerEvent({ type: 'click' });
469470

470471
const map = $('#map').dxMap({
471472
provider: 'azure',
472473
onClick: (e) => {
473474
assert.strictEqual(e.component, map, 'click event includes component instance');
474475
assert.strictEqual($(e.element).is($('#map')), true, 'click event includes root element');
475476
assert.deepEqual(e.location, { lat: 88, lng: 88 }, 'click event includes correct location');
477+
assert.deepEqual(e.event, originalEvent, 'click event is equal to passed originalEvent');
476478

477479
clickFired++;
478480
},
479481
onReady: () => {
480-
atlas.clickActionCallback({ type: 'click', position: [88, 88] });
482+
atlas.clickActionCallback({
483+
type: 'click',
484+
position: [88, 88],
485+
originalEvent,
486+
});
481487
assert.strictEqual(clickFired, 1, 'click action fired');
482488

483489
done();

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,25 @@ QUnit.test('click', function(assert) {
471471
let clicked = 0;
472472
let eventFired = 0;
473473

474+
const clickEvent = $.Event('click');
475+
474476
return new Promise(function(resolve) {
475-
new Map($('#map'), {
477+
const map = new Map($('#map'), {
476478
provider: 'googleStatic',
477479
width: 400,
478480
height: 500,
479-
onClick: function() {
481+
onClick: function(e) {
482+
assert.strictEqual(e.component, map, 'component is passed correctly');
483+
assert.strictEqual($(e.element).is($('#map')), true, 'click event includes root element');
484+
assert.strictEqual(e.event.originalEvent, clickEvent, 'event is passed correctly');
480485
clicked++;
481486
},
482487
onReady: function(e) {
483488
const $element = $(e.element);
484489
$element.dxMap('instance').on('click', function() {
485490
eventFired++;
486491
});
487-
$element.children().trigger('dxclick');
492+
$element.children().trigger(clickEvent);
488493

489494
resolve();
490495
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,8 @@ QUnit.test('click', function(assert) {
15251525
let clicked = 0;
15261526
let eventFired = 0;
15271527

1528+
let mouseEvent;
1529+
15281530
const $map = $('#map').dxMap({
15291531
provider: 'google',
15301532
width: 400,
@@ -1534,6 +1536,7 @@ QUnit.test('click', function(assert) {
15341536
lat: 2,
15351537
lng: 10
15361538
}, 'correct location passed');
1539+
assert.strictEqual(e.event, mouseEvent.domEvent, 'click event is equal to the original event');
15371540
clicked++;
15381541
},
15391542
onReady: function() {
@@ -1546,7 +1549,8 @@ QUnit.test('click', function(assert) {
15461549
});
15471550

15481551
d.done(function() {
1549-
window.google.clickActionCallback(new google.maps.MouseEvent(new google.maps.LatLng(2, 10)));
1552+
mouseEvent = new google.maps.MouseEvent(new google.maps.LatLng(2, 10));
1553+
window.google.clickActionCallback(mouseEvent);
15501554
assert.equal(clicked, 1);
15511555
assert.equal(eventFired, 1);
15521556
done();

packages/devextreme/ts/dx.all.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21074,7 +21074,12 @@ declare module DevExpress.ui {
2107421074
export type ClickEvent = DevExpress.common.core.events.NativeEventInfo<
2107521075
dxMap,
2107621076
MouseEvent | PointerEvent
21077-
>;
21077+
> & {
21078+
/**
21079+
* [descr:_ui_map_ClickEvent.location]
21080+
*/
21081+
location: MapLocation;
21082+
};
2107821083
/**
2107921084
* [descr:_ui_map_DisposingEvent]
2108021085
*/
@@ -31045,6 +31050,9 @@ declare module DevExpress.ui {
3104531050
*/
3104631051
selectedExpr?: string | Function;
3104731052
}
31053+
/**
31054+
* [descr:MapLocation]
31055+
*/
3104831056
export interface MapLocation {
3104931057
/**
3105031058
* [descr:MapLocation.lat]

0 commit comments

Comments
 (0)