diff options
| author | Marc Florisson | 2013-05-16 15:45:23 +0200 |
|---|---|---|
| committer | Marc Florisson | 2013-05-16 15:45:23 +0200 |
| commit | 74fa1a9551e1bd6eedabf88a40e5ebc6bed21645 (patch) | |
| tree | 9480fac78ce2650c3f256e25e694e18c941c9091 /app/maps | |
| parent | 629ebdfafc4ac8fa0bc65a1dd93b1e21b985d162 (diff) | |
| parent | ecec5d5a081c567444d6fc843d06ba02912958db (diff) | |
| download | chouette-core-74fa1a9551e1bd6eedabf88a40e5ebc6bed21645.tar.bz2 | |
merge
Diffstat (limited to 'app/maps')
| -rw-r--r-- | app/maps/access_link_map.rb | 37 | ||||
| -rw-r--r-- | app/maps/access_point_map.rb | 66 | ||||
| -rw-r--r-- | app/maps/application_map.rb | 6 | ||||
| -rw-r--r-- | app/maps/connection_link_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/group_of_line_map.rb | 34 | ||||
| -rw-r--r-- | app/maps/stop_area_map.rb | 35 | ||||
| -rw-r--r-- | app/maps/style_map/access_link_style_map.rb | 43 | ||||
| -rw-r--r-- | app/maps/style_map/access_points_style_map.rb | 58 | ||||
| -rw-r--r-- | app/maps/style_map/edit_access_point_style_map.rb | 46 | ||||
| -rw-r--r-- | app/maps/style_map/stop_areas_style_map.rb | 26 |
10 files changed, 336 insertions, 17 deletions
diff --git a/app/maps/access_link_map.rb b/app/maps/access_link_map.rb new file mode 100644 index 000000000..daf49738a --- /dev/null +++ b/app/maps/access_link_map.rb @@ -0,0 +1,37 @@ + +class AccessLinkMap < ApplicationMap + + attr_reader :access_link, :access_link_style + + def initialize(access_link, access_link_style = nil) + @access_link = access_link + @access_link_style = access_link_style + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + page << map.add_layer(google_satellite) + + page.assign "access_points_layer", kml_layer([access_link.referential, access_link.access_point], :styleMap => StyleMap::AccessPointsStyleMap.new(helpers).style_map) + page << map.add_layer(:access_points_layer) + page.assign "stop_areas_layer", kml_layer([access_link.referential, access_link.stop_area], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) + page << map.add_layer(:stop_areas_layer) + page << map.add_layer( kml_layer([access_link.referential, access_link.access_point, access_link], :styleMap => StyleMap::AccessLinkStyleMap.new(helpers).style_map)) + page << map.add_control( hover_control_display_name([:access_points_layer,:stop_areas_layer]) ) + page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds + end + end + + def ready? + Chouette::StopArea.bounds.present? + end + + def bounds + @bounds ||= GeoRuby::SimpleFeatures::Point.bounds([access_link.stop_area.geometry,access_link.access_point.geometry]) + end + +end diff --git a/app/maps/access_point_map.rb b/app/maps/access_point_map.rb new file mode 100644 index 000000000..bf763e6c6 --- /dev/null +++ b/app/maps/access_point_map.rb @@ -0,0 +1,66 @@ +class AccessPointMap < ApplicationMap + + attr_reader :access_point + + attr_accessor :editable + alias_method :editable?, :editable + + def initialize(access_point) + @access_point = access_point + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + page << map.add_layer(google_satellite) + + page.assign "parent_layer", kml_layer(access_point.stop_area, :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) + page << map.add_layer(:parent_layer) + page.assign "edit_access_point_layer", kml_layer(access_point, { :default => editable? }, :style_map => StyleMap::EditAccessPointStyleMap.new(helpers).style_map) + page << map.add_layer(:edit_access_point_layer) + + + if editable? + page.assign "referential_projection", projection_type.present? ? projection("EPSG:" + projection_type) : JsVar.new("undefined") + # TODO virer ce code inline + page << <<EOF + edit_access_point_layer.events.on({ + 'afterfeaturemodified': function(event) { + geometry = event.feature.geometry.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); + $('#access_point_longitude').val(geometry.x); + $('#access_point_latitude').val(geometry.y); + + if(referential_projection != undefined) + { + projection_geometry = event.feature.geometry.clone().transform(new OpenLayers.Projection("EPSG:900913"), referential_projection ); + $('#access_point_x').val(projection_geometry.x); + $('#access_point_y').val(projection_geometry.y); } + } + }); +EOF + page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_access_point_layer, :mode => 8, :autoActivate => true)) + + else + page << map.add_control( hover_control_display_name(:parent_layer) ) + end + + page << map.set_center(center.to_google.to_openlayers, 16, false, true) + end + end + + def projection_type + access_point.referential.projection_type + end + + def ready? + center.present? + end + + def center + access_point.geometry or access_point.default_position + end + +end diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb index 618ca0db2..8e9ce4d57 100644 --- a/app/maps/application_map.rb +++ b/app/maps/application_map.rb @@ -130,12 +130,6 @@ class ApplicationMap } } ) end - def open_layer_path - relative_url_root = Rails.application.config.relative_url_root - return "/assets/openlayers/" unless relative_url_root - "#{relative_url_root}/assets/openlayers/" - end - def kml_layer(url_or_object, options_or_url_options = {}, options = nil) unless options url_options = {} diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb index 98e51e38f..9318ec90f 100644 --- a/app/maps/connection_link_map.rb +++ b/app/maps/connection_link_map.rb @@ -11,7 +11,7 @@ class ConnectionLinkMap < ApplicationMap def customize_map(map, page) page.assign "stop_areas_layer", kml_layer([connection_link.referential, connection_link, :stop_areas], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) page << map.add_layer(:stop_areas_layer) - page << map.add_layer( kml_layer([connection_link.referential, connection_link], :styleMap => StyleMap::ConnectionLinkStyleMap.new.style_map)) + page << map.add_layer( kml_layer([connection_link.referential, connection_link], :styleMap => StyleMap::ConnectionLinkStyleMap.new(helpers).style_map)) page << map.add_control( hover_control_display_name(:stop_areas_layer) ) page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds end diff --git a/app/maps/group_of_line_map.rb b/app/maps/group_of_line_map.rb new file mode 100644 index 000000000..fdd8cac1d --- /dev/null +++ b/app/maps/group_of_line_map.rb @@ -0,0 +1,34 @@ +class GroupOfLineMap < ApplicationMap + + attr_reader :group_of_line, :group_of_line_style + + def initialize(group_of_line, group_of_line_style = nil) + @group_of_line = group_of_line + @group_of_line_style = group_of_line_style + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + page << map.add_layer(google_satellite) + + page.assign "stop_areas_layer", kml_layer([group_of_line.referential, group_of_line], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) + + page << map.add_layer(:stop_areas_layer) + page << map.add_control( hover_control_display_name(:stop_areas_layer) ) + page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds + end + end + + def bounds + @bounds ||= GeoRuby::SimpleFeatures::Point.bounds(group_of_line.stop_areas.collect(&:geometry).compact) + end + + def ready? + Chouette::StopArea.bounds.present? + end + +end diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index a1cae955c..ab254bf73 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -12,13 +12,26 @@ class StopAreaMap < ApplicationMap def customize_map(map, page) page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new(helpers).style_map) page << map.add_layer(:edit_stop_area_layer) + + if stop_area.children.present? + page.assign "children_layer", kml_layer(stop_area, { :children => true }, :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) + page << map.add_layer(:children_layer) + end + if stop_area.routing_stops.present? + page.assign "routing_layer", kml_layer(stop_area, { :routing => true }, :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) + page << map.add_layer(:routing_layer) + page << map.add_control( hover_control_display_name(:routing_layer) ) + page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds + else + page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new(helpers).style_map) + page << map.add_layer(:edit_stop_area_layer) - if editable? - page.assign "referential_projection", projection_type.present? ? projection("EPSG:" + projection_type) : JsVar.new("undefined") - # TODO virer ce code inline - page << <<EOF - edit_stop_area_layer.events.on({ + if editable? + page.assign "referential_projection", projection_type.present? ? projection("EPSG:" + projection_type) : JsVar.new("undefined") + # TODO virer ce code inline + page << <<EOF + edit_stop_area_layer.events.on({ 'afterfeaturemodified': function(event) { geometry = event.feature.geometry.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); $('#stop_area_longitude').val(geometry.x); @@ -32,11 +45,14 @@ class StopAreaMap < ApplicationMap } }); EOF - page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_stop_area_layer, :mode => 8, :autoActivate => true)) + page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_stop_area_layer, :mode => 8, :autoActivate => true)) + elsif stop_area.children.present? + page << map.add_control( hover_control_display_name(:children_layer) ) - end + end page << map.set_center(center.to_google.to_openlayers, 16, false, true) + end end def projection_type @@ -51,4 +67,9 @@ EOF stop_area.geometry or stop_area.default_position end + def bounds + # for ITL only + @bounds ||= GeoRuby::SimpleFeatures::Point.bounds(stop_area.routing_stops.collect(&:geometry).compact) + end + end diff --git a/app/maps/style_map/access_link_style_map.rb b/app/maps/style_map/access_link_style_map.rb new file mode 100644 index 000000000..07ef5952b --- /dev/null +++ b/app/maps/style_map/access_link_style_map.rb @@ -0,0 +1,43 @@ +class StyleMap::AccessLinkStyleMap < StyleMap::GenericStyleMap + attr_accessor :style + + def initialize(helpers,options = {}) + @helpers= helpers + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + end + + def default_style + { + :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -10, + :strokeColor => "#000000", + :strokeOpacity => 1, + :strokeWidth => 3, + :strokeLineCap => "round", + :strokeDashstyle => "solid", + :externalGraphic => @helpers.assets_path_patch( "map/${positionType}.png"), + :graphicWidth => 36, + :graphicHeight => 36, + :graphicOpacity => 1, + :graphicXOffset => -18, + :graphicYOffset => -18, + :display => true + } + end + + def context + context = { + :positionType => :" function(feature) { if (feature.attributes.departure != undefined) { return 'departure'; } else { return 'arrival'; }} " + } + end + + def style_map + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context})) + end + +end + diff --git a/app/maps/style_map/access_points_style_map.rb b/app/maps/style_map/access_points_style_map.rb new file mode 100644 index 000000000..57cf8dfb3 --- /dev/null +++ b/app/maps/style_map/access_points_style_map.rb @@ -0,0 +1,58 @@ +class StyleMap::AccessPointsStyleMap < StyleMap::GenericStyleMap + attr_accessor :style, :context, :temporary + + def default_style + raise "Helpers nil" if @helpers.nil? + {:label => "${label}", + :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -20, + :pointRadius => 1, + :externalGraphic => @helpers.assets_path_patch( "map/access_${accessType}.png"), + :graphicWidth => 25, + :graphicHeight => 25, + :graphicOpacity => 1, + :graphicXOffset => -12.5, + :graphicYOffset => -12.5 } + end + def temporary_style + raise "Helpers nil" if @helpers.nil? + {:label => "${label}", + :fontColor => "darkblue", + :fontSize => "12px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -20, + :pointRadius => 1, + :externalGraphic => @helpers.assets_path_patch( "map/access_${accessType}.png"), + :graphicWidth => 25, + :graphicHeight => 25, + :graphicOpacity => 1, + :graphicXOffset => -12.5, + :graphicYOffset => -12.5 } + end + + def initialize(helpers,options = {}) + @helpers= helpers + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + @temporary = options[:style].present? ? temporary_style.merge(options[:style]) : temporary_style + end + + + def context + { + :label => :" function(feature) {if(feature.layer.map.getZoom() > 13) { return feature.attributes.name;} else {return '';}} ", + :accessType => :" function(feature) { return feature.attributes.access_point_type.toLowerCase();} " + } + end + + def style_map + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), + :temporary => OpenLayers::Style.new(temporary, { :context => context}) ) + end + +end diff --git a/app/maps/style_map/edit_access_point_style_map.rb b/app/maps/style_map/edit_access_point_style_map.rb new file mode 100644 index 000000000..83f9298e8 --- /dev/null +++ b/app/maps/style_map/edit_access_point_style_map.rb @@ -0,0 +1,46 @@ +class StyleMap::EditAccessPointStyleMap < StyleMap::GenericStyleMap + attr_accessor :style + + def default_style + { :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -15, + :pointRadius => 4, + :fillColor => "white", + :fillOpacity => 1, + :strokeColor => "black", + :strokeOpacity => 1, + :strokeWidth => 2 } + end + + def select_style + { :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :pointRadius => 4, + :fillColor => "#86b41d", + :fillOpacity => 1, + :strokeColor => "black", + :strokeOpacity => 1, + :strokeWidth => 2 } + end + + def initialize(helpers, options = {}) + @helpers= helpers + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + end + + def context + { + :label => :" function(feature) {if(feature.layer.map.getZoom() > 13) { return feature.attributes.name;} else {return '';}} " + } + end + + def style_map + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), :select => OpenLayers::Style.new(style.merge( select_style), { :context => context})) + end + +end diff --git a/app/maps/style_map/stop_areas_style_map.rb b/app/maps/style_map/stop_areas_style_map.rb index 398748a22..f23b58136 100644 --- a/app/maps/style_map/stop_areas_style_map.rb +++ b/app/maps/style_map/stop_areas_style_map.rb @@ -1,5 +1,5 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap - attr_accessor :style, :context + attr_accessor :style, :context, :temporary def default_style raise "Helpers nil" if @helpers.nil? @@ -9,7 +9,7 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap :fontWeight => "bold", :labelAlign => "ct", :labelXOffset => 0, - :labelYOffset => -40, + :labelYOffset => -20, :pointRadius => 1, :externalGraphic => @helpers.assets_path_patch( "map/${areaType}.png"), :graphicWidth => 25, @@ -18,10 +18,29 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap :graphicXOffset => -12.5, :graphicYOffset => -12.5 } end + def temporary_style + raise "Helpers nil" if @helpers.nil? + {:label => "${label}", + :fontColor => "darkblue", + :fontSize => "12px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -20, + :pointRadius => 1, + :externalGraphic => @helpers.assets_path_patch( "map/${areaType}.png"), + :graphicWidth => 25, + :graphicHeight => 25, + :graphicOpacity => 1, + :graphicXOffset => -12.5, + :graphicYOffset => -12.5 } + end + def initialize(helpers,options = {}) @helpers= helpers @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + @temporary = options[:style].present? ? temporary_style.merge(options[:style]) : temporary_style end @@ -33,7 +52,8 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap end def style_map - OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}) ) + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), + :temporary => OpenLayers::Style.new(temporary, { :context => context}) ) end end |
