Permalink
Browse files

Starting to combine code for polygons and polylines because they shar…

…e the same underlying data structure.
  • Loading branch information...
1 parent 2d32fe9 commit c09d4668bb2727c2d70df4b99e5cddc3c3dba5fd @bamnet committed Aug 4, 2010
Showing with 15 additions and 16 deletions.
  1. +2 −2 app/views/paths/_form.html.erb
  2. +2 −2 app/views/polygons/_form.html.erb
  3. +11 −12 public/javascripts/application.js
@@ -14,7 +14,7 @@
var coords = <%=raw @path.coords.to_json() %>;
$.each(coords, function(index, coord){
- add_point_to_polyline(coord, polyline);
+ add_point_to_polyobject(coord, polyline);
add_edit_marker_to_map(coord, index);
});
@@ -28,7 +28,7 @@
position: next_position
};
add_coord_to_form('path', coord, index, '#coord_data');
- add_point_to_polyline(coord, polyline);
+ add_point_to_polyobject(coord, polyline);
add_edit_marker_to_map(coord, index);
});
<% end %>
@@ -14,7 +14,7 @@
var coords = <%=raw @polygon.coords.to_json() %>;
$.each(coords, function(index, coord){
- add_point_to_polygon(coord, polygon);
+ add_point_to_polyobject(coord, polygon);
add_edit_marker_to_map(coord, index);
});
@@ -28,7 +28,7 @@
position: next_position
};
add_coord_to_form('polygon', coord, index, '#coord_data');
- add_point_to_polygon(coord, polygon);
+ add_point_to_polyobject(coord, polygon);
add_edit_marker_to_map(coord, index);
});
<% end %>
@@ -60,23 +60,22 @@ function add_point_to_map(point, map, options){
return marker;
}
-// Add a coordinate to a polyline for
-// display purposes only. Does NOT
-// effect any data structure we care
-// about.
+// Wraps add_point_to_polyobject
function add_point_to_polyline(point, polyline){
- var position = new google.maps.LatLng(point.latitude, point.longitude);
- polyline.getPath().push(position);
- return position;
+ return add_point_to_polyobject(point, polyline);
}
-// Add a coordinate to a polygon for
-// display purposes only. Does NOT
-// effect any data structure we care
-// about.
+// Wraps add_point_to_polyobject
function add_point_to_polygon(point, polygon){
+ return add_point_to_polyobject(point, polygon);
+}
+
+// Add a coordinate to a polygon or polyline
+// for display purposes only. Does NOT
+// effect any data structure we care about.
+function add_point_to_polyobject(point, polyobject){
var position = new google.maps.LatLng(point.latitude, point.longitude);
- polygon.getPath().push(position);
+ polyobject.getPath().push(position);
return position;
}

0 comments on commit c09d466

Please sign in to comment.