This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alban Peignier
committed
Jun 25, 2015
1 parent
eaa17ed
commit ef55489
Showing
16 changed files
with
230 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
jQuery -> | ||
if $("#map.route_section").length > 0 and user_geometry? | ||
projWGS84 = new OpenLayers.Projection("EPSG:4326") | ||
proj900913 = new OpenLayers.Projection("EPSG:900913") | ||
wtk_format = new OpenLayers.Format.WKT() | ||
|
||
user_geometry.events.on({ | ||
afterfeaturemodified: (event) -> | ||
wgs84_geometry = event.feature.geometry.transform(proj900913, projWGS84) | ||
wgs84_feature = new OpenLayers.Feature.Vector(wgs84_geometry) | ||
ewtk = "SRID=4326;#{wtk_format.write(wgs84_feature)}" | ||
|
||
$('#route_section_editable_geometry').val(ewtk) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class RouteSectionsController < ChouetteController | ||
|
||
defaults :resource_class => Chouette::RouteSection | ||
|
||
respond_to :html | ||
respond_to :kml, :only => :show | ||
|
||
belongs_to :referential | ||
|
||
def show | ||
@stop_areas = referential.stop_areas.with_geometry | ||
@map = RouteSectionMap.new(resource).with_helpers(self) | ||
show! | ||
end | ||
|
||
def edit | ||
@map = RouteSectionMap.new(resource, true).with_helpers(self) | ||
edit! | ||
end | ||
|
||
private | ||
|
||
def route_section_params | ||
params.require(:route_section).permit(:departure_id, :arrival_id, :editable_geometry) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class RouteSectionMap < ApplicationMap | ||
|
||
attr_reader :route_section | ||
|
||
attr_accessor :editable | ||
alias_method :editable?, :editable | ||
|
||
def initialize(route_section, editable = false) | ||
@route_section = route_section | ||
@editable = editable | ||
end | ||
|
||
def customize_map(map, page) | ||
# layers order seems to matter for ModifyFeature control | ||
route_section.stop_areas.each do |stop_area| | ||
layer = "stop_area_#{stop_area.id}".to_sym | ||
page.assign layer.to_s, kml_layer(stop_area, :styleMap => Design::StopAreasStyleMap.new(helpers).style_map) | ||
page << map.add_layer(layer) | ||
page << map.add_control( hover_control_display_name(layer) ) | ||
end | ||
|
||
geometry_options = {}.tap do |options| | ||
options[:mode] = :editable if editable? | ||
end | ||
geometry_kml_layer = kml_layer(route_section, geometry_options, {}) # , :styleMap => Design::LineStyleMap.new(style: nil).style_map) | ||
|
||
if editable | ||
page.assign :user_geometry, geometry_kml_layer | ||
page << map.add_layer(:user_geometry) | ||
|
||
page.assign :modify_feature, OpenLayers::Control::ModifyFeature.new(:user_geometry, autoActivate: true) | ||
page << map.add_control( :modify_feature ) | ||
else | ||
page << map.add_layer(geometry_kml_layer) | ||
end | ||
|
||
page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds | ||
end | ||
|
||
def bounds | ||
@bounds ||= | ||
if route_section.geometry.present? | ||
route_section.geometry.bounds | ||
elsif route_section.stop_areas.present? | ||
GeoRuby::SimpleFeatures::Point.bounds route_section.stop_areas.collect(&:geometry) | ||
end | ||
end | ||
|
||
def ready? | ||
bounds.present? | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%= semantic_form_for [@referential, @route_section] do |form| %> | ||
<%= form.inputs do %> | ||
<% if @route_section.new_record? %> | ||
<%= form.input :departure, as: :select, collection: @stop_areas, include_blank: false %> | ||
<%= form.input :arrival, as: :select, collection: @stop_areas, include_blank: false %> | ||
<% else %> | ||
<p> | ||
<label><%= @route_section.human_attribute_name("departure") %>: </label> | ||
<%= @route_section.departure.name %> | ||
</p> | ||
<p> | ||
<label><%= @route_section.human_attribute_name("arrival") %>: </label> | ||
<%= @route_section.arrival.name %> | ||
</p> | ||
<%= form.input :editable_geometry, as: :hidden %> | ||
<% end %> | ||
<% end %> | ||
<%= form.actions do %> | ||
<%= form.action :submit, :as => :button %> | ||
<%= form.action :cancel, :as => :link %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= title_tag t('route_sections.edit.title') %> | ||
<%= @map.to_html %> | ||
<%= render "form" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= title_tag t('route_sections.index.title') %> | ||
|
||
<div id="route_sections"> | ||
|
||
</div> | ||
|
||
<% content_for :sidebar do %> | ||
<ul class="actions"> | ||
<li><%= link_to t('route_sections.actions.new'), new_referential_route_section_path(@referential), :class => "add" %></li> | ||
</ul> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= title_tag t('route_sections.new.title') %> | ||
|
||
<%= render "form" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= title_tag t('route_sections.new.title') %> | ||
<%= render "form" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<%= title_tag t('route_sections.show.title') %> | ||
|
||
<div class="route_section"> | ||
<%= @map.to_html %> | ||
|
||
<div class="summary"> | ||
<p> | ||
<label><%= @route_section.human_attribute_name("departure") %>: </label> | ||
<%= @route_section.departure.name %> | ||
</p> | ||
<p> | ||
<label><%= @route_section.human_attribute_name("arrival") %>: </label> | ||
<%= @route_section.arrival.name %> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<% content_for :sidebar do %> | ||
<ul class="actions"> | ||
<li><%= link_to t('route_sections.actions.new'), new_referential_route_section_path(@referential), :class => "add" %></li> | ||
<li><%= link_to t('route_sections.actions.edit'), edit_referential_route_section_path(@referential, @route_section), :class => "edit" %></li> | ||
<li><%= link_to t('route_sections.actions.destroy'), referential_route_section_path(@referential, @route_section), :method => :delete, :data => {:confirm => t('route_sections.actions.destroy_confirm')}, :class => "remove" %></li> | ||
</ul> | ||
<%= creation_tag(@route_section) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<kml xmlns="http://www.opengis.net/kml/2.2"> | ||
<Document> | ||
<Placemark id="route-section-<%= @route_section.id %>"> | ||
<%= @route_section.geometry(params[:mode]).kml_representation.html_safe %> | ||
</Placemark> | ||
</Document> | ||
</kml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ | |
end | ||
resources :clean_ups | ||
|
||
resources :route_sections | ||
end | ||
root :to => "referentials#index" | ||
|
||
|
9 changes: 7 additions & 2 deletions
9
db/migrate/20150529134410_create_route_sections.ninoxe_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
# This migration comes from ninoxe_engine (originally 20150529132301) | ||
class CreateRouteSections < ActiveRecord::Migration | ||
def change | ||
create_table :route_sections do |t| | ||
t.belongs_to :departure | ||
t.belongs_to :arrival | ||
|
||
t.line_string :geometry | ||
t.line_string :input_geometry, srid: 4326 | ||
t.line_string :processed_geometry, srid: 4326 | ||
|
||
t.string :objectid, null: false | ||
t.integer :object_version | ||
t.datetime :creation_time | ||
t.string :creator_id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters