Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improves geodesic travel in features detail page

  • Loading branch information...
commit 754cd02efb4632af48caaf5ebd76e0a546aee3e4 1 parent 1e6a229
@Ferdev Ferdev authored
View
2  Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/Vizzuality/cartodb-rb-client.git
- revision: 8520a91514d432bfab0e1872418450f15b6fc638
+ revision: c20c64388eee8d67c1f8869a964e12ebd1afa4c1
specs:
cartodb-rb-client (0.0.1)
activesupport (= 3.0.5)
View
3  app/controllers/application_controller.rb
@@ -61,7 +61,8 @@ def geolocate_user
private :geolocate_user
def user_latlong
- ::RGeo::Cartesian.simple_factory.point(session[:user_location]['longitude'], session[:user_location]['latitude']) if user_geolocated?
+ ::RGeo::Geographic.simple_mercator_factory.point(session[:user_location]['longitude'], session[:user_location]['latitude']) if user_geolocated?
+ # ::RGeo::Cartesian.simple_factory.point(session[:user_location]['longitude'], session[:user_location]['latitude']) if user_geolocated?
end
private :user_latlong
View
6 app/controllers/features_controller.rb
@@ -27,7 +27,11 @@ def show
itinerary = Feature.itinerary_time_to(@feature, location_point)
@itinerary_time = itinerary[:time]
@itinerary_type = itinerary[:type]
-
+
+ @distance = @feature.the_geom.distance(user_latlong)
+ puts '###############'
+ puts @distance
+ puts '###############'
end
end
View
3  app/views/features/show.html.erb
@@ -12,9 +12,10 @@
var nearest_places = <%= @nearest_places_json %>;
- var userLatLng = null;
+ var userLatLng = null, distance = null;
<% if @user_latlong.present? %>
userLatLng = new google.maps.LatLng(<%= @user_latlong.y %>, <%= @user_latlong.x %>);
+ distance = <%= @distance %>;
<% end %>
</script>
<%= raw include_javascripts :feature %>
View
1  public/javascripts/admin/pages/new.js
@@ -10,7 +10,6 @@
htmlArea = this;
setTimeout(function(){
$('label:not(.visible)').each(function(i,ele){
- console.debug($(ele).attr('for'))
createBubble($(ele).position(),texts[$(ele).attr('for')]);
});
},500);
View
13 public/javascripts/whs/features/show.js
@@ -46,7 +46,6 @@ $(document).ready( function(){
function loadMap() {
- console.debug($("a#zoomin"))
$("a#zoomin").click(function(ev) {
ev.stopPropagation();
ev.preventDefault();
@@ -82,8 +81,6 @@ $(document).ready( function(){
icon: image
});
-
-
$.each(nearest_places, function(index, place){
var image = new google.maps.MarkerImage("/images/marker_" + place['type'] + "_mini.png",
new google.maps.Size(25, 23),
@@ -138,6 +135,10 @@ $(document).ready( function(){
}
function travel(){
+ // if (map.getBounds().contains(latlng) && map.getBounds().contains(userLatLng)) {
+ // return;
+ // };
+
var geodesicPoints = new Array();
with (Math) {
var lat1 = userLatLng.lat() * (PI/180);
@@ -147,8 +148,10 @@ $(document).ready( function(){
var d = 2*asin(sqrt( pow((sin((lat1-lat2)/2)),2) + cos(lat1)*cos(lat2)*pow((sin((lon1-lon2)/2)),2)));
- for (var n = 0 ; n < 151 ; n++ ) {
- var f = (1/150) * n;
+ var steps = distance * 151 / 10015007.480415292;
+
+ for (var n = 0 ; n < steps ; n++ ) {
+ var f = (1/(steps - 1)) * n;
// f = f.toFixed(6);
var A = sin((1-f)*d)/sin(d)
var B = sin(f*d)/sin(d)
Please sign in to comment.
Something went wrong with that request. Please try again.