I have a pan control that look like this:
Pretty standard Google Mapsish controls, IMO.
When the user clicks in the top 3rd of the control, it should pan up (deltaY = +1); right third means it should pan east (deltaX = -1); Down is deltaY = -1, and West is deltaX = +1. The control is 50px, square. I have working code, but I believe it can be written much more elegantly than this using a single (if discontinuos) mathematical function. As always, I appreciate your feedback.
$(control).click(function (evt) {
var clickPointX = (evt.layerX || evt.offsetX),
clickPointY = (evt.layerY || evt.offsetY),
deltaX,
deltaY;
// control is 50x50 px.
// Click in the top third, get a positive 'Y' value.
// Click in the left third, get a positive 'X' value.
// Click in the middle, get zero.
if (clickPointX < 16) {
deltaX = +1;
} else if (clickPointX > 34) {
deltaX = -1;
} else {
deltaX = 0;
}
if (clickPointY < 16) {
deltaY = +1;
} else if (clickPointY > 34) {
deltaY = -1;
} else {
deltaY = 0;
}
map.panDirection(deltaX, deltaY);
});