SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

scatterplot brush #124

Closed SymbolixAU closed 5 years ago

SymbolixAU commented 5 years ago

https://github.com/uber/deck.gl/tree/master/examples/website/brushing/scatterplot-brushing-layer

Similar to Arch Brush #23

TODO

SymbolixAU commented 5 years ago

PR #126

SymbolixAU commented 5 years ago

I think returning 'hovered' points to R session will be tricky. The function to calculate if a point is in range is performed on the GPU, and we can't access this from javascript. I tried writing my own version, but on 57,757 points (mapdeck::roads ) it bogs down

function distance_between_coordinates(lat1, lon1, lat2, lon2) {
  var p = 0.017453292519943295;    // Math.PI / 180
  var c = Math.cos;
  var a = 0.5 - c((lat2 - lat1) * p)/2 +
          c(lat1 * p) * c(lat2 * p) *
          (1 - c((lon2 - lon1) * p))/2;

  return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
}

function is_point_in_range(point_lat, point_lon, mouse_lat, mouse_lon, range) {
  return (distance_between_coordinates(point_lat, point_lon, mouse_lat, mouse_lon) <= range);
}