1 | # |
---|
2 | # PERL mapweaver module by gary68 |
---|
3 | # |
---|
4 | # |
---|
5 | # |
---|
6 | # |
---|
7 | # Copyright (C) 2011, Gerhard Schwanz |
---|
8 | # |
---|
9 | # This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the |
---|
10 | # Free Software Foundation; either version 3 of the License, or (at your option) any later version. |
---|
11 | # |
---|
12 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
14 | # |
---|
15 | # You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/> |
---|
16 | # |
---|
17 | |
---|
18 | |
---|
19 | package mwNodes ; |
---|
20 | |
---|
21 | use strict ; |
---|
22 | use warnings ; |
---|
23 | |
---|
24 | use OSM::osm 8.21 ; |
---|
25 | |
---|
26 | use mwConfig ; |
---|
27 | use mwFile ; |
---|
28 | use mwRules ; |
---|
29 | use mwMap ; |
---|
30 | use mwMisc ; |
---|
31 | use mwLabel ; |
---|
32 | |
---|
33 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
---|
34 | |
---|
35 | require Exporter ; |
---|
36 | |
---|
37 | @ISA = qw ( Exporter AutoLoader ) ; |
---|
38 | |
---|
39 | @EXPORT = qw ( processNodes |
---|
40 | createPoiDirectory |
---|
41 | ) ; |
---|
42 | |
---|
43 | |
---|
44 | sub processNodes { |
---|
45 | |
---|
46 | print "drawing nodes...\n" ; |
---|
47 | |
---|
48 | my $lonRef; my $latRef; my $tagRef ; |
---|
49 | ($lonRef, $latRef, $tagRef) = getNodePointers () ; |
---|
50 | |
---|
51 | foreach my $nodeId (keys %$lonRef) { |
---|
52 | my @tags = @{ $$tagRef{$nodeId} } ; |
---|
53 | my $tagsString = "" ; |
---|
54 | |
---|
55 | my $ruleRef = getNodeRule (\@tags) ; |
---|
56 | if (defined $ruleRef) { |
---|
57 | |
---|
58 | # draw disc first ! |
---|
59 | if (grep /yes/, $$ruleRef{'disc'}) { |
---|
60 | my $svgString = "" ; |
---|
61 | if ( $$ruleRef{'discsvgstring'} ne "" ) { |
---|
62 | $svgString = $$ruleRef{'discsvgstring'} ; |
---|
63 | } |
---|
64 | else { |
---|
65 | $svgString = "fill=\"$$ruleRef{'disccolor'}\" stroke=\"none\" fill-opacity=\"$$ruleRef{'discopacity'}\"" ; |
---|
66 | } |
---|
67 | drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'discradius'}, 1, $svgString, 'nodes') ; |
---|
68 | } |
---|
69 | |
---|
70 | if (grep /yes/, $$ruleRef{'circle'}) { |
---|
71 | my $svgString = "" ; |
---|
72 | if ( $$ruleRef{'circlesvgstring'} ne "" ) { |
---|
73 | $svgString = $$ruleRef{'circlesvgstring'} ; |
---|
74 | } |
---|
75 | else { |
---|
76 | $svgString = "fill=\"none\" stroke=\"$$ruleRef{'circlecolor'}\" stroke-width=\"$$ruleRef{'circlethickness'}\"" ; |
---|
77 | } |
---|
78 | drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'circleradius'}, 1, $svgString, 'nodes') ; |
---|
79 | } |
---|
80 | |
---|
81 | if ( ($$ruleRef{'size'} > 0) and ($$ruleRef{'icon'} eq "none") ) { |
---|
82 | my $svgString = "" ; |
---|
83 | if ( $$ruleRef{'svgstring'} ne "" ) { |
---|
84 | $svgString = $$ruleRef{'svgstring'} ; |
---|
85 | } |
---|
86 | else { |
---|
87 | $svgString = "fill=\"$$ruleRef{'color'}\"" ; |
---|
88 | } |
---|
89 | |
---|
90 | if ( $$ruleRef{'shape'} eq "circle") { |
---|
91 | drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ; |
---|
92 | } |
---|
93 | elsif ( $$ruleRef{'shape'} eq "square") { |
---|
94 | drawSquare ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ; |
---|
95 | } |
---|
96 | elsif ( $$ruleRef{'shape'} eq "triangle") { |
---|
97 | drawTriangle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ; |
---|
98 | } |
---|
99 | elsif ( $$ruleRef{'shape'} eq "diamond") { |
---|
100 | drawDiamond ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | if ( ($$ruleRef{'label'} ne "none") or ($$ruleRef{'icon'} ne "none") ) { |
---|
105 | my ($labelText, $ref) = createLabel (\@tags, $$ruleRef{'label'}, $$lonRef{$nodeId}, $$latRef{$nodeId}) ; |
---|
106 | $labelText = labelTransform ($labelText, $$ruleRef{'labeltransform'}) ; |
---|
107 | my $labelSize = $$ruleRef{'labelsize'} ; |
---|
108 | my $labelColor = $$ruleRef{'labelcolor'} ; |
---|
109 | my $labelFont = $$ruleRef{'labelfont'} ; |
---|
110 | my $labelFontFamily = $$ruleRef{'labelfontfamily'} ; |
---|
111 | my $labelBold = $$ruleRef{'labelbold'} ; |
---|
112 | my $labelItalic = $$ruleRef{'labelitalic'} ; |
---|
113 | my $labelHalo = $$ruleRef{'labelhalo'} ; |
---|
114 | my $labelHaloColor = $$ruleRef{'labelhalocolor'} ; |
---|
115 | my $icon = $$ruleRef{'icon'} ; |
---|
116 | my $iconSize = $$ruleRef{'iconsize'} ; |
---|
117 | |
---|
118 | my $svgText = createTextSVG ( $labelFontFamily, $labelFont, $labelBold, $labelItalic, $labelSize, $labelColor, $labelHalo, $labelHaloColor) ; |
---|
119 | |
---|
120 | placeLabelAndIcon($$lonRef{$nodeId}, $$latRef{$nodeId}, 0, $$ruleRef{'size'}, $labelText, $svgText, $icon, $iconSize, $iconSize, "nodes") ; |
---|
121 | } |
---|
122 | |
---|
123 | # fill poi directory |
---|
124 | |
---|
125 | my $thing0 = $$ruleRef{'keyvalue'} ; |
---|
126 | my ($thing) = ( $thing0 =~ /.+=(.+)/ ) ; |
---|
127 | |
---|
128 | my $dirName = getValue ("name", $$tagRef{$nodeId} ) ; |
---|
129 | if ( ( cv('poi') eq "1" ) and |
---|
130 | ( defined $dirName ) and |
---|
131 | ( $$ruleRef{'direxclude'} eq "no") |
---|
132 | ) { |
---|
133 | $dirName .= " ($thing)" ; |
---|
134 | if ( cv('grid') > 0) { |
---|
135 | my $sq = gridSquare($$lonRef{$nodeId}, $$latRef{$nodeId}, cv('grid')) ; |
---|
136 | if (defined $sq) { |
---|
137 | addToPoiHash ($dirName, $sq) ; |
---|
138 | } |
---|
139 | } |
---|
140 | else { |
---|
141 | # $poiHash{$dirName} = 1 ; |
---|
142 | addToPoiHash ($dirName, undef) ; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | } # defined ruleref |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | |
---|
152 | # ------------------------------------------------------------------------------------ |
---|
153 | |
---|
154 | sub createPoiDirectory { |
---|
155 | my $poiName ; |
---|
156 | my $poiFile ; |
---|
157 | $poiName = cv ('out') ; |
---|
158 | $poiName =~ s/\.svg/\_pois.txt/ ; |
---|
159 | setConfigValue("poiname", $poiName) ; |
---|
160 | print "creating poi file $poiName ...\n" ; |
---|
161 | open ($poiFile, ">", $poiName) or die ("can't open poi file $poiName\n") ; |
---|
162 | |
---|
163 | my $ref = getPoiHash() ; |
---|
164 | my %poiHash = %$ref ; |
---|
165 | |
---|
166 | if ( cv('grid') eq "0") { |
---|
167 | foreach my $poi (sort keys %poiHash) { |
---|
168 | $poi = replaceHTMLCode ( $poi ) ; |
---|
169 | print $poiFile "$poi\n" ; |
---|
170 | } |
---|
171 | } |
---|
172 | else { |
---|
173 | foreach my $poi (sort keys %poiHash) { |
---|
174 | $poi = replaceHTMLCode ( $poi ) ; |
---|
175 | print $poiFile "$poi\t" ; |
---|
176 | foreach my $square (sort keys %{$poiHash{$poi}}) { |
---|
177 | print $poiFile "$square " ; |
---|
178 | } |
---|
179 | print $poiFile "\n" ; |
---|
180 | } |
---|
181 | } |
---|
182 | close ($poiFile) ; |
---|
183 | } |
---|
184 | |
---|
185 | 1 ; |
---|
186 | |
---|
187 | |
---|