3 #Map types of the map
\r
5 include MappingObject
\r
7 G_NORMAL_MAP = Variable.new("G_NORMAL_MAP")
\r
8 G_SATELLITE_MAP = Variable.new("G_SATELLITE_MAP")
\r
9 G_HYBRID_MAP = Variable.new("G_HYBRID_MAP")
\r
11 attr_accessor :layers, :name, :projection, :options
\r
13 #The options can be any of the GMapType options detailed in the documentation + a <tt>:projection</tt>.
\r
14 def initialize(layers, name, options = {})
\r
17 @projection = options.delete(:projection) || GMercatorProjection.new
\r
22 "new GMapType(#{MappingObject.javascriptify_variable(Array(layers))}, #{MappingObject.javascriptify_variable(projection)}, #{MappingObject.javascriptify_variable(name)}, #{MappingObject.javascriptify_variable(options)})"
\r
26 #Represents a mercator projection for zoom levels 0 to 17 (more than that by passing an argument to the constructor)
\r
27 class GMercatorProjection
\r
28 include MappingObject
\r
32 def initialize(n = nil)
\r
38 return "G_NORMAL_MAP.getProjection()"
\r
40 "new GMercatorProjection(#{@n})"
\r
45 #Abstract Tile layer. Subclasses must implement a get_tile_url method.
\r
47 include MappingObject
\r
49 attr_accessor :opacity, :zoom_range, :copyright, :format
\r
51 #Options are the following, with default values:
\r
52 #:zoom_range (0..17), :copyright ({'prefix' => '', 'copyright_texts' => [""]}), :opacity (1.0), :format ("png")
\r
53 def initialize(options = {})
\r
54 @opacity = options[:opacity] || 1.0
\r
55 @zoom_range = options[:zoom_range] || (0..17)
\r
56 @copyright = options[:copyright] || {'prefix' => '', 'copyright_texts' => [""]}
\r
57 @format = (options[:format] || "png").to_s
\r
61 "addPropertiesToLayer(new GTileLayer(new GCopyrightCollection(\"\"),#{zoom_range.begin},#{zoom_range.end}),#{get_tile_url},function(a,b) {return #{MappingObject.javascriptify_variable(@copyright)};}\n,function() {return #{@opacity};},function(){return #{@format == "png"};})"
\r
64 #for subclasses to implement
\r
69 #Represents a pre tiled layer, taking images directly from a server, without using a server script.
\r
70 class PreTiledLayer < GTileLayer
\r
71 attr_accessor :base_url
\r
73 #Possible options are the same as for the GTileLayer constructor
\r
74 def initialize(base_url,options = {})
\r
76 @base_url = base_url
\r
79 #Returns the code to determine the url to fetch the tile. Follows the convention adopted by the tiler: {base_url}/tile_{b}_{a.x}_{a.y}.{format}
\r
81 "function(a,b) { return '#{@base_url}/tile_' + b + '_' + a.x + '_' + a.y + '.#{format}';}"
\r
85 #Represents a pretiled layer (it actually does not really matter where the tiles come from). Calls an action on the server to get back the tiles. It passes the action arguments x, y (coordinates of the tile) and z (zoom level). It can be used, for example, to return default tiles when the requested tile is not present.
\r
86 class PreTiledLayerFromAction < PreTiledLayer
\r
88 "function(a,b) { return '#{base_url}?x=' + a.x + '&y=' + a.y + '&z=' + b ;}"
\r
92 #Represents a TileLayer where the tiles are generated dynamically from a WMS server (MapServer, GeoServer,...)
\r
93 #You need to include the JavaScript file wms-gs.js for this to work
\r
94 #see http://docs.codehaus.org/display/GEOSDOC/Google+Maps
\r
95 class WMSLayer < GTileLayer
\r
96 attr_accessor :base_url, :layers, :styles, :merc_proj, :use_geographic
\r
98 #Options are the same as with GTileLayer + :styles (""), :merc_proj (:mapserver), :use_geographic (false)
\r
99 def initialize(base_url, layers, options = {})
\r
101 @base_url = base_url.gsub(/\?$/,"") #standardize the url
\r
103 @styles = options[:styles] || ""
\r
104 merc_proj = options[:merc_proj] || :mapserver
\r
105 @merc_proj = if merc_proj == :mapserver
\r
107 elsif merc_proj == :geoserver
\r
112 @use_geographic = options.has_key?(:use_geographic)? options[:use_geographic] : false
\r
121 "addWMSPropertiesToLayer(#{super},#{MappingObject.javascriptify_variable(@base_url)},#{MappingObject.javascriptify_variable(@layers)},#{MappingObject.javascriptify_variable(@styles)},#{MappingObject.javascriptify_variable(format)},#{MappingObject.javascriptify_variable(@merc_proj)},#{MappingObject.javascriptify_variable(@use_geographic)})"
\r