Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map: Add location field to ClickEvent type and pass event to onClick #29074

Open
wants to merge 1 commit into
base: 25_1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ const AzureProvider = DynamicProvider.inherit({

_clickActionHandler(e) {
if (e.type === 'click') {
this._fireClickAction({ location: this._normalizeLocation(e.position) });
this._fireClickAction({
location: this._normalizeLocation(e.position),
event: e.originalEvent,
});
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const GoogleProvider = DynamicProvider.inherit({
},

_clickActionHandler(e) {
this._fireClickAction({ location: this._normalizeLocation(e.latLng) });
this._fireClickAction({ location: this._normalizeLocation(e.latLng), event: e.domEvent });
},

updateDimensions() {
Expand Down
6 changes: 5 additions & 1 deletion packages/devextreme/js/ui/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export type MapType = 'hybrid' | 'roadmap' | 'satellite';
* @type object
* @inherits NativeEventInfo
*/
export type ClickEvent = NativeEventInfo<dxMap, MouseEvent | PointerEvent>;
export type ClickEvent = NativeEventInfo<dxMap, MouseEvent | PointerEvent> & {
/** @docid _ui_map_ClickEvent.location */
location: MapLocation;
};

/**
* @docid _ui_map_DisposingEvent
Expand Down Expand Up @@ -133,6 +136,7 @@ export type RouteRemovedEvent = EventInfo<dxMap> & {
};

/**
* @docid
* @public
* @namespace DevExpress.ui
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/devextreme/js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ export default Map;
* @hidden
*/

/**
* @name MapLocation
* @hidden
*/

/**
* @name dxMapOptions.onContentReady
* @hidden true
Expand Down
1 change: 1 addition & 0 deletions packages/devextreme/testing/helpers/forMap/googleMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@
MouseEvent: function(latLng) {
this.stop = function() {};
this.latLng = latLng;
this.domEvent = new MouseEvent({ type: 'click' });
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,24 @@ QUnit.module('basic options', moduleConfig, () => {
QUnit.test('Should add onClick handler with correct args', function(assert) {
const done = assert.async();
let clickFired = 0;
const originalEvent = new PointerEvent({ type: 'click' });

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

clickFired++;
},
onReady: () => {
atlas.clickActionCallback({ type: 'click', position: [88, 88] });
atlas.clickActionCallback({
type: 'click',
position: [88, 88],
originalEvent,
});
assert.strictEqual(clickFired, 1, 'click action fired');

done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,25 @@ QUnit.test('click', function(assert) {
let clicked = 0;
let eventFired = 0;

const clickEvent = $.Event('click');

return new Promise(function(resolve) {
new Map($('#map'), {
const map = new Map($('#map'), {
provider: 'googleStatic',
width: 400,
height: 500,
onClick: function() {
onClick: function(e) {
assert.strictEqual(e.component, map, 'component is passed correctly');
assert.strictEqual(e.element, map.$element(), 'element is passed correctly');
assert.strictEqual(e.event.originalEvent, clickEvent, 'event is passed correctly');
clicked++;
},
onReady: function(e) {
const $element = $(e.element);
$element.dxMap('instance').on('click', function() {
eventFired++;
});
$element.children().trigger('dxclick');
$element.children().trigger(clickEvent);

resolve();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,8 @@ QUnit.test('click', function(assert) {
let clicked = 0;
let eventFired = 0;

let mouseEvent;

const $map = $('#map').dxMap({
provider: 'google',
width: 400,
Expand All @@ -1534,6 +1536,7 @@ QUnit.test('click', function(assert) {
lat: 2,
lng: 10
}, 'correct location passed');
assert.strictEqual(e.event, mouseEvent.domEvent, 'click event is equal to the original event');
clicked++;
},
onReady: function() {
Expand All @@ -1546,7 +1549,8 @@ QUnit.test('click', function(assert) {
});

d.done(function() {
window.google.clickActionCallback(new google.maps.MouseEvent(new google.maps.LatLng(2, 10)));
mouseEvent = new google.maps.MouseEvent(new google.maps.LatLng(2, 10));
window.google.clickActionCallback(mouseEvent);
assert.equal(clicked, 1);
assert.equal(eventFired, 1);
done();
Expand Down
10 changes: 9 additions & 1 deletion packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21076,7 +21076,12 @@ declare module DevExpress.ui {
export type ClickEvent = DevExpress.common.core.events.NativeEventInfo<
dxMap,
MouseEvent | PointerEvent
>;
> & {
/**
* [descr:_ui_map_ClickEvent.location]
*/
location: MapLocation;
};
/**
* [descr:_ui_map_DisposingEvent]
*/
Expand Down Expand Up @@ -31047,6 +31052,9 @@ declare module DevExpress.ui {
*/
selectedExpr?: string | Function;
}
/**
* [descr:MapLocation]
*/
export interface MapLocation {
/**
* [descr:MapLocation.lat]
Expand Down
Loading