mapfish 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING.LESSER +165 -0
- data/README +141 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/generators/mapfish_resource/USAGE +28 -0
- data/generators/mapfish_resource/mapfish_resource_generator.rb +88 -0
- data/generators/mapfish_resource/templates/controller.rb +75 -0
- data/generators/mapfish_resource/templates/functional_test.rb +46 -0
- data/generators/mapfish_resource/templates/helper.rb +2 -0
- data/generators/print_controller/USAGE +16 -0
- data/generators/print_controller/print_controller_generator.rb +39 -0
- data/generators/print_controller/templates/config.yaml +76 -0
- data/generators/print_controller/templates/controller.rb +9 -0
- data/generators/print_controller/templates/functional_test.rb +8 -0
- data/generators/print_controller/templates/helper.rb +2 -0
- data/generators/print_controller/templates/helper_test.rb +4 -0
- data/init.rb +8 -0
- data/install.rb +1 -0
- data/lib/geojson.rb +156 -0
- data/lib/mapfish.rb +1 -0
- data/lib/mapfish_core_extensions/active_record/base.rb +179 -0
- data/lib/mapfish_core_extensions/array.rb +31 -0
- data/lib/print.rb +133 -0
- data/lib/tasks/mapfish_tasks.rake +37 -0
- data/mapfish.gemspec +67 -0
- data/print/print-standalone.jar +0 -0
- data/test/geojson_test.rb +76 -0
- data/uninstall.rb +1 -0
- metadata +114 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
SRID = <%= class_name %>.geometry_column.srid
|
4
|
+
|
5
|
+
# GET /<%= table_name %>
|
6
|
+
def index
|
7
|
+
@<%= table_name %> = <%= class_name %>.find_by_mapfish_filter(params)
|
8
|
+
|
9
|
+
render :json => @<%= table_name %>.to_geojson
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /<%= table_name %>/1
|
13
|
+
def show
|
14
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
15
|
+
|
16
|
+
render :json => [@<%= file_name %>].to_geojson
|
17
|
+
end
|
18
|
+
|
19
|
+
# POST /<%= table_name %>
|
20
|
+
def create
|
21
|
+
@<%= table_name %> = []
|
22
|
+
feature_collection = Geometry.from_geojson(request.raw_post, SRID)
|
23
|
+
if feature_collection.nil?
|
24
|
+
head :bad_request
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
feature_collection.features.each do |feature|
|
29
|
+
if feature.id.is_a? Integer
|
30
|
+
<%= file_name %> = <%= class_name %>.find_by_id(feature.id)
|
31
|
+
end
|
32
|
+
if <%= file_name %>.nil?
|
33
|
+
<%= file_name %> = <%= class_name %>.new()
|
34
|
+
end
|
35
|
+
|
36
|
+
if <%= file_name %>.update_attributes_from_feature(feature)
|
37
|
+
@<%= table_name %> << <%= file_name %>
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
render :json => @<%= table_name %>.to_geojson, :status => :created
|
42
|
+
end
|
43
|
+
|
44
|
+
# PUT /<%= table_name %>/1
|
45
|
+
def update
|
46
|
+
feature = Geometry.from_geojson(request.raw_post, SRID)
|
47
|
+
if feature.nil?
|
48
|
+
head :bad_request
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
52
|
+
if feature.id.is_a? Integer
|
53
|
+
@<%= file_name %> = <%= class_name %>.find_by_id(feature.id)
|
54
|
+
end
|
55
|
+
if @<%= file_name %>.nil?
|
56
|
+
head :not_found
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
if @<%= file_name %>.update_attributes_from_feature(feature)
|
61
|
+
render :json => @<%= file_name %>.to_geojson, :status => :created
|
62
|
+
else
|
63
|
+
head :unprocessable_entity
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# DELETE /<%= table_name %>/1
|
68
|
+
def destroy
|
69
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
70
|
+
@<%= file_name %>.destroy
|
71
|
+
|
72
|
+
head :no_content
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "should get index" do
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert_not_nil assigns(:<%= table_name %>)
|
9
|
+
end
|
10
|
+
|
11
|
+
test "should get new" do
|
12
|
+
get :new
|
13
|
+
assert_response :success
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should create <%= file_name %>" do
|
17
|
+
assert_difference('<%= class_name %>.count') do
|
18
|
+
post :create, :<%= file_name %> => { }
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should show <%= file_name %>" do
|
25
|
+
get :show, :id => <%= table_name %>(:one).to_param
|
26
|
+
assert_response :success
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should get edit" do
|
30
|
+
get :edit, :id => <%= table_name %>(:one).to_param
|
31
|
+
assert_response :success
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should update <%= file_name %>" do
|
35
|
+
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
36
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should destroy <%= file_name %>" do
|
40
|
+
assert_difference('<%= class_name %>.count', -1) do
|
41
|
+
delete :destroy, :id => <%= table_name %>(:one).to_param
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_redirected_to <%= table_name %>_path
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new MapFish print controller. Pass the controller name, either
|
3
|
+
CamelCased or under_scored.
|
4
|
+
|
5
|
+
To create a controller within a module, specify the controller name as a
|
6
|
+
path like 'parent_module/controller_name'.
|
7
|
+
|
8
|
+
This generates a controller class in app/controllers, a sample configuration
|
9
|
+
config/print.yaml, a helper class in app/helpers, a functional
|
10
|
+
test suite in test/functional and a helper test suite in test/unit/helpers.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
`./script/generate controller Print
|
14
|
+
|
15
|
+
Modules Example:
|
16
|
+
`./script/generate controller 'admin/print'`
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class PrintControllerGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
# Check for class naming collisions.
|
5
|
+
m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest"
|
6
|
+
|
7
|
+
# Controller, helper, views, and test directories.
|
8
|
+
m.directory File.join('app/controllers', class_path)
|
9
|
+
m.directory File.join('app/helpers', class_path)
|
10
|
+
m.directory File.join('test/functional', class_path)
|
11
|
+
m.directory File.join('test/unit/helpers', class_path)
|
12
|
+
m.directory File.join('config', class_path)
|
13
|
+
|
14
|
+
# Controller class, functional test, and helper class.
|
15
|
+
m.template 'controller.rb',
|
16
|
+
File.join('app/controllers',
|
17
|
+
class_path,
|
18
|
+
"#{file_name}_controller.rb")
|
19
|
+
|
20
|
+
m.template 'functional_test.rb',
|
21
|
+
File.join('test/functional',
|
22
|
+
class_path,
|
23
|
+
"#{file_name}_controller_test.rb")
|
24
|
+
|
25
|
+
m.template 'helper.rb',
|
26
|
+
File.join('app/helpers',
|
27
|
+
class_path,
|
28
|
+
"#{file_name}_helper.rb")
|
29
|
+
|
30
|
+
m.template 'helper_test.rb',
|
31
|
+
File.join('test/unit/helpers',
|
32
|
+
class_path,
|
33
|
+
"#{file_name}_helper_test.rb")
|
34
|
+
|
35
|
+
# Config file
|
36
|
+
m.template 'config.yaml', File.join('config', "print.yaml")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#===========================================================================
|
2
|
+
# allowed DPIs
|
3
|
+
#===========================================================================
|
4
|
+
dpis:
|
5
|
+
- 254
|
6
|
+
- 190
|
7
|
+
# - 127
|
8
|
+
# - 56
|
9
|
+
|
10
|
+
#===========================================================================
|
11
|
+
# the allowed scales
|
12
|
+
#===========================================================================
|
13
|
+
scales:
|
14
|
+
- 25000
|
15
|
+
- 50000
|
16
|
+
- 100000
|
17
|
+
- 200000
|
18
|
+
- 500000
|
19
|
+
- 1000000
|
20
|
+
- 2000000
|
21
|
+
- 4000000
|
22
|
+
- 8000000
|
23
|
+
- 16000000
|
24
|
+
- 32000000
|
25
|
+
- 64000000
|
26
|
+
|
27
|
+
#===========================================================================
|
28
|
+
# the list of allowed hosts
|
29
|
+
#===========================================================================
|
30
|
+
|
31
|
+
hosts:
|
32
|
+
- !localMatch
|
33
|
+
dummy: true
|
34
|
+
- !ipMatch
|
35
|
+
ip: demo.mapfish.org
|
36
|
+
- !dnsMatch
|
37
|
+
host: labs.metacarta.com
|
38
|
+
port: 80
|
39
|
+
|
40
|
+
|
41
|
+
layouts:
|
42
|
+
#===========================================================================
|
43
|
+
A4 portrait:
|
44
|
+
#===========================================================================
|
45
|
+
mainPage:
|
46
|
+
rotation: true
|
47
|
+
pageSize: A4
|
48
|
+
header:
|
49
|
+
height: 50
|
50
|
+
items:
|
51
|
+
- !text
|
52
|
+
font: Helvetica
|
53
|
+
fontSize: 30
|
54
|
+
align: right
|
55
|
+
text: 'hello first print'
|
56
|
+
items:
|
57
|
+
- !map
|
58
|
+
spacingAfter: 30
|
59
|
+
width: 440
|
60
|
+
height: 483
|
61
|
+
- !text
|
62
|
+
text: 'blablabla'
|
63
|
+
spacingAfter: 30
|
64
|
+
footer:
|
65
|
+
height: 30
|
66
|
+
items:
|
67
|
+
- !columns
|
68
|
+
items:
|
69
|
+
- !text
|
70
|
+
backgroundColor: #FF0000
|
71
|
+
align: left
|
72
|
+
text: little test
|
73
|
+
- !text
|
74
|
+
align: right
|
75
|
+
text: 'Page ${pageNum}'
|
76
|
+
|
data/init.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'geojson'
|
2
|
+
|
3
|
+
# Load CoreExtensions
|
4
|
+
Dir[File.join("#{File.dirname(__FILE__)}", 'lib', 'mapfish_core_extensions', '**', '*.rb')].each do |f|
|
5
|
+
extension_module = f.sub(/(.*)(mapfish_core_extensions.*)\.rb/,'\2').classify.constantize
|
6
|
+
base_module = f.sub(/(.*mapfish_core_extensions.)(.*)\.rb/,'\2').classify.constantize
|
7
|
+
base_module.class_eval { include extension_module }
|
8
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/geojson.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008 Pirmin Kalberer, Sourcepole AG
|
3
|
+
#
|
4
|
+
# This file is part of MapFish Server
|
5
|
+
#
|
6
|
+
# MapFish Server is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# MapFish Server is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with MapFish Server. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'geo_ruby'
|
21
|
+
|
22
|
+
module GeoRuby
|
23
|
+
module SimpleFeatures
|
24
|
+
class Geometry
|
25
|
+
def self.from_geojson(data, srid=DEFAULT_SRID)
|
26
|
+
data ||= {}
|
27
|
+
if data.class==String
|
28
|
+
require 'active_support'
|
29
|
+
data = ActiveSupport::JSON::decode(data)
|
30
|
+
end
|
31
|
+
coords = data['coordinates'] || data[:coordinates]
|
32
|
+
case data['type'] || data[:type]
|
33
|
+
when "Point"
|
34
|
+
Point.from_coordinates(coords, srid)
|
35
|
+
when "LineString"
|
36
|
+
LineString.from_coordinates(coords, srid)
|
37
|
+
when "Polygon"
|
38
|
+
Polygon.from_coordinates(coords, srid)
|
39
|
+
when "MultiPoint"
|
40
|
+
MultiPoint.from_coordinates(coords, srid)
|
41
|
+
when "MultiLineString"
|
42
|
+
MultiLineString.from_coordinates(coords, srid)
|
43
|
+
when "MultiPolygon"
|
44
|
+
MultiPolygon.from_coordinates(coords, srid)
|
45
|
+
when "GeometryCollection"
|
46
|
+
geometriesJson=data['geometries'] || data[:geometries]
|
47
|
+
geometries=geometriesJson.collect { |cur| from_geojson(cur, srid) }
|
48
|
+
GeometryCollection.from_geometries(geometries, srid)
|
49
|
+
when "Feature"
|
50
|
+
geometryJson=data['geometry'] || data[:geometry]
|
51
|
+
properties=data['properties'] || data[:properties]
|
52
|
+
id=data['id'] || data[:id]
|
53
|
+
Feature.new(from_geojson(geometryJson, srid), properties, id)
|
54
|
+
when "FeatureCollection"
|
55
|
+
features=data['features'] || data[:features]
|
56
|
+
FeatureCollection.new(features.collect { |cur| from_geojson(cur, srid) })
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
class Point
|
61
|
+
def to_json(options = nil)
|
62
|
+
{:type => "Point",
|
63
|
+
:coordinates => [self.x, self.y]}.to_json(options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
class LineString
|
67
|
+
def to_json(options = nil)
|
68
|
+
coords = self.points.collect {|point| [point.x, point.y] }
|
69
|
+
{:type => "LineString",
|
70
|
+
:coordinates => coords}.to_json(options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
class Polygon
|
74
|
+
def to_json(options = nil)
|
75
|
+
coords = self.collect {|ring| ring.points.collect {|point| [point.x, point.y] } }
|
76
|
+
{:type => "Polygon",
|
77
|
+
:coordinates => coords}.to_json(options)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
class MultiPoint
|
81
|
+
def to_json(options = nil)
|
82
|
+
coords = self.geometries.collect {|geom| [geom.x, geom.y] }
|
83
|
+
{:type => "MultiPoint",
|
84
|
+
:coordinates => coords}.to_json(options)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
class MultiLineString
|
88
|
+
def to_json(options = nil)
|
89
|
+
coords = self.geometries.collect {|geom| geom.points.collect {|point| [point.x, point.y] } }
|
90
|
+
{:type => "MultiLineString",
|
91
|
+
:coordinates => coords}.to_json(options)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
class MultiPolygon
|
95
|
+
def to_json(options = nil)
|
96
|
+
coords = self.geometries.collect {|geom| geom.collect {|ring| ring.points.collect {|point| [point.x, point.y] } } }
|
97
|
+
{:type => "MultiPolygon",
|
98
|
+
:coordinates => coords}.to_json(options)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
class GeometryCollection
|
102
|
+
def to_json(options = nil)
|
103
|
+
{:type => "GeometryCollection",
|
104
|
+
:geometries => self.geometries}.to_json(options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class Feature
|
109
|
+
attr_accessor :geometry
|
110
|
+
attr_accessor :properties
|
111
|
+
attr_accessor :id
|
112
|
+
|
113
|
+
def initialize(geometry, properties={}, id=nil)
|
114
|
+
@geometry=geometry
|
115
|
+
@properties=properties
|
116
|
+
@id=id
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_json(options = nil)
|
120
|
+
result={:type=>"Feature",
|
121
|
+
:geometry=>@geometry,
|
122
|
+
:properties=>@properties}
|
123
|
+
result[:id]=@id if @id!=nil
|
124
|
+
return result.to_json(options)
|
125
|
+
end
|
126
|
+
|
127
|
+
def ==(other)
|
128
|
+
if other.class != self.class
|
129
|
+
false
|
130
|
+
else
|
131
|
+
@geometry==other.geometry and @properties==other.properties and @id==other.id
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class FeatureCollection
|
137
|
+
attr_accessor :features
|
138
|
+
def initialize(features=[])
|
139
|
+
@features=features
|
140
|
+
end
|
141
|
+
|
142
|
+
def to_json(options = nil)
|
143
|
+
{:type=>"FeatureCollection",
|
144
|
+
:features=>@features}.to_json(options)
|
145
|
+
end
|
146
|
+
|
147
|
+
def ==(other)
|
148
|
+
if other.class != self.class
|
149
|
+
false
|
150
|
+
else
|
151
|
+
@features==other.features
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|