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

Fixed #1470: optimized mousemove with throttling #1556

Merged
merged 1 commit into from
Mar 14, 2017
Merged
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
9 changes: 6 additions & 3 deletions web/client/components/map/leaflet/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var CoordinatesUtils = require('../../../utils/CoordinatesUtils');
var assign = require('object-assign');
var mapUtils = require('../../../utils/MapUtils');

const {throttle} = require('lodash');

require('./SingleClick');
let LeafletMap = React.createClass({
propTypes: {
Expand Down Expand Up @@ -115,9 +117,10 @@ let LeafletMap = React.createClass({
});
}
});
this.map.on('dragstart', () => { this.map.off('mousemove', this.mouseMoveEvent); });
this.map.on('dragend', () => { this.map.on('mousemove', this.mouseMoveEvent); });
this.map.on('mousemove', this.mouseMoveEvent);
const mouseMove = throttle(this.mouseMoveEvent, 500);
this.map.on('dragstart', () => { this.map.off('mousemove', mouseMove); });
this.map.on('dragend', () => { this.map.on('mousemove', mouseMove); });
this.map.on('mousemove', mouseMove);
this.map.on('contextmenu', () => {
if (this.props.onRightClick) {
this.props.onRightClick(event.containerPoint);
Expand Down
46 changes: 24 additions & 22 deletions web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var CoordinatesUtils = require('../../../utils/CoordinatesUtils');
var ConfigUtils = require('../../../utils/ConfigUtils');
var mapUtils = require('../../../utils/MapUtils');

const {isEqual} = require('lodash');
const {isEqual, throttle} = require('lodash');

var OpenlayersMap = React.createClass({
propTypes: {
Expand Down Expand Up @@ -129,27 +129,8 @@ var OpenlayersMap = React.createClass({
});
}
});
map.on('pointermove', (event) => {
if (!event.dragging && event.coordinate) {
let pos = event.coordinate.slice();
let coords = ol.proj.toLonLat(pos, this.props.projection);
let tLng = (( coords[0] / 360) % 1) * 360;
if (tLng < -180) {
tLng = tLng + 360;
} else if (tLng > 180) {
tLng = tLng - 360;
}
this.props.onMouseMove({
y: coords[1] || 0.0,
x: tLng || 0.0,
crs: "EPSG:4326",
pixel: {
x: event.pixel[0],
y: event.pixel[1]
}
});
}
});
const mouseMove = throttle(this.mouseMoveEvent, 500);
map.on('pointermove', mouseMove);

this.updateMapInfoState();
this.setMousePointer(this.props.mousePointer);
Expand Down Expand Up @@ -279,6 +260,27 @@ var OpenlayersMap = React.createClass({
</div>
);
},
mouseMoveEvent(event) {
if (!event.dragging && event.coordinate) {
let pos = event.coordinate.slice();
let coords = ol.proj.toLonLat(pos, this.props.projection);
let tLng = (( coords[0] / 360) % 1) * 360;
if (tLng < -180) {
tLng = tLng + 360;
} else if (tLng > 180) {
tLng = tLng - 360;
}
this.props.onMouseMove({
y: coords[1] || 0.0,
x: tLng || 0.0,
crs: "EPSG:4326",
pixel: {
x: event.pixel[0],
y: event.pixel[1]
}
});
}
},
updateMapInfoState() {
let view = this.map.getView();
let c = this.normalizeCenter(view.getCenter());
Expand Down