Skip to content

Commit

Permalink
Add lat/lng info to touch events (closes #50)
Browse files Browse the repository at this point in the history
Supported by Miizee.com
  • Loading branch information
petrsloup committed Jun 17, 2015
1 parent 2c37adb commit e67f37a
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,33 @@ weapi.App.prototype.on = function(type, listener) {
e['latitude'] = null;
e['longitude'] = null;

var cartesian = app.camera.camera.
pickEllipsoid(new Cesium.Cartesian2(e.offsetX, e.offsetY));
if (goog.isDefAndNotNull(cartesian)) {
var carto = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian);

var lat = goog.math.toDegrees(carto.latitude),
lng = goog.math.toDegrees(carto.longitude);
e['latlng'] = {'lat': lat, 'lng': lng};
e['latitude'] = lat;
e['longitude'] = lng;
e['altitude'] = carto.height;
e['originalEvent'] = e.getBrowserEvent();
var offsetX = e.offsetX, offsetY = e.offsetY;
if (!goog.isDefAndNotNull(offsetX) || !goog.isDefAndNotNull(offsetY)) {
var origE = e.getBrowserEvent();
var pageX = origE.pageX, pageY = origE.pageY,
touches = origE['touches'];
if (touches && touches[0] && (!pageX || !pageY)) {
pageX = touches[0].pageX;
pageY = touches[0].pageY;
}
var canvasOffset = goog.style.getPageOffset(app.canvas);
offsetX = pageX - canvasOffset.x;
offsetY = pageY - canvasOffset.y;
}
if (goog.isDefAndNotNull(offsetX) && goog.isDefAndNotNull(offsetY)) {
var cartesian = app.camera.camera.
pickEllipsoid(new Cesium.Cartesian2(offsetX, offsetY));
if (goog.isDefAndNotNull(cartesian)) {
var carto = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian);

var lat = goog.math.toDegrees(carto.latitude),
lng = goog.math.toDegrees(carto.longitude);
e['latlng'] = {'lat': lat, 'lng': lng};
e['latitude'] = lat;
e['longitude'] = lng;
e['altitude'] = carto.height;
e['originalEvent'] = e.getBrowserEvent();
}
}

listener(e);
Expand Down

0 comments on commit e67f37a

Please sign in to comment.