Render/Renderer.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 64.2% 9 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 91.5% 65 / 71 CC 8 SCAR 9.8
CC
8
Cov
89%
new
5.1
render_node
2.0
render_way
2.0
CRAP 2.7
« Render/Renderer/SVG.pm ↑ Summary Render.pm »
1 # Encoding and name #_{
2  
3 =encoding utf8
4 =head1 NAME
5  
6 Geo::OSM::Render::Renderer - Render OpenStreetMap data encaspulated via L<Geo::OSM::Primitive>, possibly stored in a L<Geo::OSM::DBI> database.
7  
8 =cut
9 package Geo::OSM::Render::Renderer;
10 #_}
11 #_{ use …
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #_}
19 4 our $VERSION = 0.01;
20 #_{ Synopsis
21  
22 =head1 SYNOPSIS
23  
24  
25 =cut
26 #_}
27 #_{ Overview
28  
29 =head1 OVERVIEW
30  
31 …
32  
33 =cut
34  
35 #_}
36 #_{ Methods
37  
38 =head1 METHODS
39 =cut
40  
41 2 ▶sub new { #_{
Subroutine new: called CC=5 SCAR=16.2
Pod documented
42 #_{ POD
43  
44 =head2 new
45  
46 my $proj = Geo::OSM::Render::Projection->new(); # Use derived class!
47 my $vp = Geo::OSM::Render::Viewport ->new(); # Use derived class!
48  
49 my $osm_renderer = Geo::OSM::Render::Renderer->new(
50 $proj,
51 $vp
52 );
53  
54  
55 =cut
56  
57 #_}
58  
59 2 my $class = shift;
60  
61 2 my $self = {};
62 2 bless $self, $class;
63  
64 2 ▶ croak "Wrong class $class" unless $self->isa('Geo::OSM::Render::Renderer');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isa("Geo::OSM::Render::Renderer") 0 2 2
65  
66 2 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
67 4 ▶ if ($_[0] -> isa('Geo::OSM::Render::Viewport')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->isa("Geo::OSM::Render::Viewport")) 2 2 4
68 2 $self->{viewport} = shift;
69 2 next;
70 }
71 2 ▶ if ($_[0] -> isa('Geo::OSM::Render::Projection')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->isa("Geo::OSM::Render::Projection")) 2 0 2
72 2 $self->{projection} = shift;
73 2 next;
74 }
75 0 last;
76 }
77  
78 2 return $self;
79  
80 } #_}
81 2 ▶sub render_node { #_{
Subroutine render_node: called CC=2 SCAR=7.1
Pod documented
82  
83 #_{ POD
84  
85 =head2 render_node
86  
87 $osm_svg_renderer->render_node($node);
88  
89 Renders C<< $node>> which must be a L<Geo::OSM::Primitive::Node> (or derived from it)i.
90  
91 =cut
92  
93 #_}
94  
95 2 my $self = shift;
96 2 my $node = shift;
97  
98 2 ▶ croak "$node is not a Node" unless $node->isa('Geo::OSM::Primitive::Node');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Geo::OSM::Primitive::Node") 0 2 2
99  
100 } #_}
101 1 ▶sub render_way { #_{
Subroutine render_way: called CC=2 SCAR=7.1
Pod documented
102  
103 #_{ POD
104  
105 =head2 render_way
106  
107 $osm_svg_renderer->render_way($way);
108  
109 Renders C<< $way>> which must be a L<Geo::OSM::Primitive::Way> (or derived from it)i.
110  
111 =cut
112  
113 #_}
114  
115 1 my $self = shift;
116 1 my $way = shift;
117  
118 1 ▶ croak "$way is not a Way" unless $way->isa('Geo::OSM::Primitive::Way');
Branch: 1 branch
BranchTrueFalseTotal
unless $way->isa("Geo::OSM::Primitive::Way") 0 1 1
119  
120 } #_}
121 9 ▶sub lat_lon_to_map_coordinates { #_{
Subroutine lat_lon_to_map_coordinates: called CC=1 SCAR=0.0
Pod documented
122 #_{ POD
123  
124 =head2 lat_lon_to_map_coordinates
125  
126 my ($map_x, $map_y) = $osm_svg_renderer->lat_lon_to_map_coordinates($lat, $lon);
127  
128 Convert the lattitude/longitude pair C<<$lat>> and C<<$lon>> to map coordinates and return them.
129  
130 =cut
131  
132 #_}
133
134 9 my $self = shift;
135 # my $node = shift;
136 9 my $lat = shift;
137 9 my $lon = shift;
138  
139 # croak "$node is not a node" unless $node->isa('Geo::OSM::Primitive::Node');
140  
141 9 my ($x , $y ) = $self->{projection}->lat_lon_to_x_y($lat , $lon );
142 # my ($x , $y ) = $self->{projection}->lat_lon_to_x_y($node->{lat}, $node->{lon});
143 9 my ($x_map, $y_map) = $self->{viewport }->x_y_to_map_x_y($x, $y);
144  
145 9 return ($x_map, $y_map);
146  
147 } #_}
148 7 ▶sub node_to_map_coordinates { #_{
Subroutine node_to_map_coordinates: called CC=2 SCAR=7.0
Pod documented
149 #_{ POD
150  
151 =head2 node_to_map_coordinates
152  
153 my ($map_x, $map_y) = $osm_svg_renderer->node_to_map_coordinates($node);
154  
155 =cut
156  
157 #_}
158
159 7 my $self = shift;
160 7 my $node = shift;
161  
162 7 ▶ croak "$node is not a node" unless $node->isa('Geo::OSM::Primitive::Node');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Geo::OSM::Primitive::Node") 0 7 7
163  
164 7 return $self->lat_lon_to_map_coordinates($node->lat, $node->lon);
165  
166 # my ($x , $y ) = $self->{projection}->lat_lon_to_x_y($node->{lat}, $node->{lon});
167 # my ($x_map, $y_map) = $self->{viewport }->x_y_to_map_x_y($x, $y);
168  
169 # return ($x_map, $y_map);
170  
171 } #_}
172 #_}
173 #_{ POD: Author
174  
175 =head1 AUTHOR
176  
177 René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
178  
179 =cut
180  
181 #_}
182 #_{ POD: Copyright and License
183  
184 =head1 COPYRIGHT AND LICENSE
185  
186 Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
187  
188 This program is free software; you can redistribute it and/or modify it
189 under the terms of the the Artistic License (2.0). You may obtain a
190 copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0>
191  
192 =cut
193  
194 #_}
195 #_{ POD: Source Code
196  
197 =head1 Source Code
198  
199 The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Geo-OSM-Render >>. Meaningful pull requests are welcome.
200  
201 =cut
202  
203 #_}
204  
205 4 'tq84';
« Render/Renderer/SVG.pm ↑ Summary Render.pm »