Compare commits

..

1 Commits

Author SHA1 Message Date
5e9af49939 Partial refactor 2022-07-28 11:32:59 +01:00
17 changed files with 3591 additions and 5485 deletions

165
mw.pl Normal file → Executable file
View File

@ -1,8 +1,5 @@
# #
# PERL mapweaver by gary68 # PERL mapweaver by gary68 & atlas48
#
#
#
# #
# Copyright(C)2011, Gerhard Schwanz # Copyright(C)2011, Gerhard Schwanz
# #
@ -15,72 +12,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/> # You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
# #
# 0.03 20110614 -help
# 0.03 20110614 square for nodes
# 0.03 print prg name and version
# 0.03 ruler
# 0.04 ruler positions; ruler background; disc opacity correction; -debug; -verbose
# 0.04 scale, colors and positions; header/footer
# 0.04 triangle and diamond for nodes; labels and icons for nodes
# 0.05 categories for config values
# 0.06 drawArea; area rules; extended help, added valid object properties
# 0.07 way labels; minsizearea implemented;
# 0.08 added coastlines; problems with completeObjects! use option -cie
# 0.09 oneways
# 0.10 pagenumbers; rectangles; comments and empty lines in rule file; config in rule file
# 0.10 coast lines fixed; auto bridge implemented
# 0.11 area icons / patterns added; time; street directory; poi directory; pdf directoriy
# 0.12 way shields
# 0.13 routes, not yet working...
# 0.14 route work
# 0.15 routes working now - finetuning needed; bgbolor implemented; multipolygons
# 0.16 size check for multipolygon areas; scale rule sizes (x:y)
# 0.17 -forcenodes; projection in footer
# 0.18 direxclude options and rule properties
# 0.19 pagenumber bug solved
# 0.20 legend
# 0.21 legend in separate file
# 0.22 help texts for object properties in rule file
# 0.23 latex string sanitize
# 0.24 labels for areas
# 0.25 labels for multipolygons
# 0.26 fix directory bugs
# 0.27 way name substitution, if name is too long for way. incl. legend for map
# 0.28 oceancolor bug fixed
# 0.29 fonts/families
# 0.30 -wns=5 now possible; way name substitutions in separate file
# 0.31 getXXXrule bug fixed; wnsunique
# 0.32 -targetSize
# 0.33 -onewayautosize
# 0.34 pbf support; halo; label transform; bold print of labels
# 0.35 svg text creation bug fixed
# 0.36 font size error wns corrected; box occupy; new place management
# 0.37 -dirprg program to create directory; gpx support
# 0.38 -gpxcolor; -gpxsize
# 0.39 parameter bug dirprg fixed; sanitize bug fixed
# 0.40 draw only items inside drawing area; check for undefined relation nodes, reduce errors
# 0.41 fixed icon space occupy error; eliminated labels drawn outside map area
# 0.42 fixed error with area label svg string
# 0.43 check if areas (simple ways) are closed before drawing
# 0.44 overpass options added
# 0.45 utf-8 encoding error solved for overpass data
# 0.46 out parameter fixed
# 0.47 added srtm option
# 0.48 shield error corrected
# TODO # TODO
# -different tempfilenames # -different tempfilenames
my $version = "0.48"; my $version = "0.48";
my $programName = "mapweaver"; my $programName = "mapweaver";
use strict ; use strict; use warnings;
use warnings ;
use OSM::osm; use OSM::osm;
use mwConfig; use mwConfig;
use mwMap; use mwMap;
use mwRules; use mwRules;
@ -95,90 +35,53 @@ use mwGPX ;
my $time0 = time(); my $time0 = time();
print "\n$programName $version by gary68\n\n"; print "\n$programName $version by gary68\n\n";
initConfig() ; initConfig;
getProgramOptions;
getProgramOptions() ; readConfigFile cv('ini');
readConfigFile( cv('ini') ) ; if(cv('help')eq "1"){ printConfigDescriptions;
printValidObjectProperties;
if ( cv('help') eq "1" ) { die "quit after help output\n";
printConfigDescriptions() ;
printValidObjectProperties() ;
die ("quit after help output\n") ;
} }
printConfig if cv('verbose');
readRules;
if ( cv('verbose') eq "1" ) { if(cv('debug')eq "1"){ printNodeRules;
printConfig() ; printWayRules;
printAreaRules;
printRouteRules;
} }
readFile;
readRules() ;
if ( cv('debug') eq "1" ) {
printNodeRules() ;
printWayRules() ;
printAreaRules() ;
printRouteRules() ;
}
readFile() ;
my $renderTime0 = time(); my $renderTime0 = time();
adaptRuleSizes;
adaptRuleSizes() ; unless(cv('multionly')){ processNodes;
createPoiDirectory()if cv('poi');
if ( cv('multionly') eq "0" ) { initOneways;
processWays;
processNodes() ; createDirectory if cv('dir');
createDirPdf if cv('dirpdf');
if ( cv('poi') eq "1") { processRoutes;
createPoiDirectory() ;
} }
processMultipolygons;
createLegend if cv('legend');
processPageNumbers if cv('pagenumbers');
processRectanglesif if cv('rectangles');
boxDrawOccupiedAreas if cv('test');
processGPXFile if cv('gpx');
initOneways() ; writeMap;
processWays() ;
if ( cv('dir') eq "1") {
createDirectory() ;
}
if ( cv('dirpdf') eq "1") {
createDirPdf() ;
}
processRoutes() ;
} # multionly
processMultipolygons() ;
if ( cv('legend') ne "0" ) { createLegend() ; }
if ( cv('pagenumbers') ne "" ) { processPageNumbers() ; }
if ( cv('rectangles') ne "" ) { processRectangles() ; }
if ( cv ('test') eq "1") {
boxDrawOccupiedAreas() ;
}
if ( cv ('gpx') ne "") {
processGPXFile() ;
}
writeMap() ;
my $renderTime1 = time(); my $renderTime1 = time();
my($paper, $x, $y)= fitsPaper();
my ($paper, $x, $y) = fitsPaper () ; $x = int ($x*10) / 10 ; $y = int ($y*10) / 10 ; $x = int($x*10)/10;
$y = int($y*10)/10;
print "map($x cm x $y cm)fits paper $paper\n\n"; print "map($x cm x $y cm)fits paper $paper\n\n";
my $time1 = time(); my $time1 = time();
print "\nrender time(excluding all file operations)", stringTimeSpent($renderTime1-$renderTime0), "\n"; print "\nrender time(excluding all file operations)", stringTimeSpent($renderTime1-$renderTime0), "\n";
print "\n$programName finished after ", stringTimeSpent($time1-$time0), "\n\n"; print "\n$programName finished after ", stringTimeSpent($time1-$time0), "\n\n";

View File

@ -1,9 +1,6 @@
# #
# PERL mapweaver module by gary68 # PERL mapweaver module by gary68
# #
#
#
#
# Copyright(C)2011, Gerhard Schwanz # Copyright(C)2011, Gerhard Schwanz
# #
# 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 # 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
@ -17,11 +14,8 @@
package mwCoastLines; package mwCoastLines;
use strict; use warnings;
use strict ; use Math::Polygon; use List::Util qw[min max];
use warnings ;
use Math::Polygon ;
use List::Util qw[min max] ;
use mwMap; use mwMap;
use mwFile; use mwFile;
@ -39,8 +33,7 @@ require Exporter ;
); );
sub nearestPoint { sub nearestPoint{#
#
# accepts x/y coordinates and returns nearest point on border of map to complete cut coast ways # accepts x/y coordinates and returns nearest point on border of map to complete cut coast ways
# #
my $ref = shift; my $ref = shift;
@ -55,30 +48,21 @@ sub nearestPoint {
$xn = $xmax; $xn = $xmax;
$yn = $y; $yn = $y;
$min = abs($xmax-$x); $min = abs($xmax-$x);
} } if(abs($ymax-$y)<$min){# bottom
if ( abs ($ymax-$y) < $min) { # bottom
$xn = $x; $xn = $x;
$yn = $ymax; $yn = $ymax;
$min = abs($ymax-$y); $min = abs($ymax-$y);
} } if(abs($x)<$min){# left
if ( abs ($x) < $min) { # left
$xn = 0; $xn = 0;
$yn = $y; $yn = $y;
$min = abs($x); $min = abs($x);
} } if(abs($y)< $min){# top
if ( abs ($y) < $min) { # top
$xn = $x; $xn = $x;
$yn = 0; $yn = 0;
} } # print " NP: final $xn $yn\n";
# print " NP: final $xn $yn\n" ;
my @a =($xn, $yn); my @a =($xn, $yn);
return (\@a) ; return \@a;
} }sub nextPointOnBorder{#
sub nextPointOnBorder {
#
# accepts x/y coordinates and returns next point on border - to complete coast rings with other polygons and corner points # accepts x/y coordinates and returns next point on border - to complete coast rings with other polygons and corner points
# hints if returned point is a corner # hints if returned point is a corner
# #
@ -88,161 +72,83 @@ sub nextPointOnBorder {
my $corner = 0; my $corner = 0;
my($xmax, $ymax)= getDimensions(); my($xmax, $ymax)= getDimensions();
if($x == $xmax){# right border if($x == $xmax){# right border
if ($y < $ymax) { if($y < $ymax){ $xn = $xmax; $yn = $y + 1;
$xn = $xmax ; $yn = $y + 1 ; } else{ $xn = $xmax - 1; $yn = $ymax;
} }} else{ if($x == 0){# left border
else { if($y > 0){ $xn = 0; $yn = $y - 1;
$xn = $xmax - 1 ; $yn = $ymax ; } else{ $xn = 1; $yn = 0;
} } } else{ if($y == $ymax){# bottom border
} if($x > 0){ $xn = $x - 1; $yn = $ymax;
else { } else{ $xn = 0; $yn = $ymax - 1;
if ($x == 0) { # left border } } else{ if($y == 0){# top border
if ($y > 0) { if($x < $xmax){ $xn = $x + 1; $yn = 0;
$xn = 0 ; $yn = $y - 1 ; } else{ $xn = $xmax; $yn = 1;
} } } } }} # print "NPOB: $x, $y --- finito $xn $yn\n";
else {
$xn = 1 ; $yn = 0 ;
}
}
else {
if ($y == $ymax) { # bottom border
if ($x > 0) {
$xn = $x - 1 ; $yn = $ymax ;
}
else {
$xn = 0 ; $yn = $ymax - 1 ;
}
}
else {
if ($y == 0) { # top border
if ($x < $xmax) {
$xn = $x + 1 ; $yn = 0 ;
}
else {
$xn = $xmax ; $yn = 1 ;
}
}
}
}
}
# print "NPOB: $x, $y --- finito $xn $yn\n" ;
if ( ($xn == 0) and ($yn == 0) ) { $corner = 1 ; }
if ( ($xn == 0) and ($yn == $ymax) ) { $corner = 1 ; }
if ( ($xn == $xmax) and ($yn == 0) ) { $corner = 1 ; }
if ( ($xn == $xmax) and ($yn == $ymax) ) { $corner = 1 ; }
if(($xn == 0)and($yn == 0)){$corner = 1;} if(($xn == 0)and($yn == $ymax)){$corner = 1;} if(($xn == $xmax)and($yn == 0)){$corner = 1;} if(($xn == $xmax)and($yn == $ymax)){$corner = 1;}
return($xn, $yn, $corner); return($xn, $yn, $corner);
} }
# --------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------
sub processCoastLines { sub processCoastLines{ print "check and process coastlines...\n";
#
#
#
print "check and process coastlines...\n" ;
my $ref = shift; # ref to all coast ways my $ref = shift; # ref to all coast ways
my @allWays = @$ref; my @allWays = @$ref;
if (cv('debug') eq "1") { if(cv('debug')){
print "COAST: " . scalar(@allWays). " coast ways initially found.\n"; print "COAST: " . scalar(@allWays). " coast ways initially found.\n";
print "COAST: ways: @allWays\n\n"; print "COAST: ways: @allWays\n\n";
} }
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
my($nodesRef, $tagRef)= getWayPointers(); my($nodesRef, $tagRef)= getWayPointers();
# check coast ways. eliminate invisible ways. eliminate points outside map. # check coast ways. eliminate invisible ways. eliminate points outside map.
my @newWays =(); my @newWays =();
foreach my $w ( @allWays ) { foreach my $w(@allWays){ my @nodes = @{$$nodesRef{$w}};
my @nodes = @{ $$nodesRef{ $w } } ;
my $allIn = 1; my $allIn = 1;
my $allOut = 1; my $allOut = 1;
foreach my $n ( @nodes ) { foreach my $n(@nodes){ if(pointInMap($n)){ $allOut = 0;
if ( pointInMap ($n) ) { } else{ $allIn = 0;
$allOut = 0 ; } }
} if($allIn){ # use way as it is
else {
$allIn = 0 ;
}
}
if ( $allIn ) {
# use way as it is
push @newWays, $w; push @newWays, $w;
if ( cv ('debug') eq "1" ) { print "COAST: way $w will be used unmodified.\n" ; } print "COAST: way $w will be used unmodified.\n" if cv('debug');
} } elsif($allOut){ # do nothing
elsif ( $allOut) { print "COAST: way $w will NOT be used. outside map.\n" if cv('debug');} } else{ # eliminate all outside nodes at start and end of way, then use new way
# do nothing
if ( cv ('debug') eq "1" ) { print "COAST: way $w will NOT be used. outside map.\n" ; }
}
else {
# eliminate all outside nodes at start and end of way, then use new way
# eliminate outsides at start # eliminate outsides at start
while ( (scalar @nodes >= 1) and ( ! pointInMap ($nodes[0]) ) ) { shift @nodes while((scalar(@nodes)>= 1)and not pointInMap($nodes[0]));
shift @nodes ;
}
# eliminate outsides at end # eliminate outsides at end
while ( (scalar @nodes >= 1) and ( ! pointInMap ($nodes[-1]) ) ) { while((scalar @nodes >= 1)and not pointInMap($nodes[-1])){ pop @nodes;
pop @nodes ;
} }
if(scalar @nodes >= 2){ @{$$nodesRef{$w}}= @nodes;
if ( scalar @nodes >= 2 ) {
@{ $$nodesRef{$w}} = @nodes ;
push @newWays, $w; push @newWays, $w;
if ( cv ('debug') eq "1" ) { print "COAST: modified way $w will be used.\n" ; } if(cv('debug')eq "1"){print "COAST: modified way $w will be used.\n";} } else{ if(cv('debug')eq "1"){print "COAST: way $w too short now.\n";} } }
} }
else {
if ( cv ('debug') eq "1" ) { print "COAST: way $w too short now.\n" ; }
}
}
}
@allWays = @newWays; @allWays = @newWays;
if(cv('debug')eq "1"){ if(cv('debug')eq "1"){
print "\nCOAST: " . scalar(@allWays). " coast ways will be used.\n"; print "\nCOAST: " . scalar(@allWays). " coast ways will be used.\n";
print "COAST: ways: @allWays\n\n"; print "COAST: ways: @allWays\n\n";
} }
if(scalar @allWays > 0){ # build rings
if (scalar @allWays > 0) {
# build rings
my($refWays, $refNodes)= buildRings(\@allWays, 0); my($refWays, $refNodes)= buildRings(\@allWays, 0);
my @ringNodes = @$refNodes; # contains all nodes of rings // array of arrays ! my @ringNodes = @$refNodes; # contains all nodes of rings // array of arrays !
if (cv('debug') eq "1") { print "COAST: " . scalar (@ringNodes) . " rings found.\n" ; } print "COAST: " . scalar(@ringNodes). " rings found.\n" if cv('debug');
# convert rings to coordinate system # convert rings to coordinate system
my @ringCoordsOpen =(); my @ringCoordsClosed =(); my @ringCoordsOpen =(); my @ringCoordsClosed =();
for (my $i=0; $i<=$#ringNodes; $i++) { for(my $i=0; $i<=$#ringNodes; $i++){ # print "COAST: initial ring $i\n";
# print "COAST: initial ring $i\n" ;
my @actualCoords =(); my @actualCoords =();
foreach my $node (@{$ringNodes[$i]}) { foreach my $node(@{$ringNodes[$i]}){ push @actualCoords, [convert($$lonRef{$node}, $$latRef{$node})];
push @actualCoords, [convert ($$lonRef{$node}, $$latRef{$node})] ; } if(${$ringNodes[$i]}[0] == ${$ringNodes[$i]}[-1]){ push @ringCoordsClosed, [@actualCoords]; # islands
} } else{ push @ringCoordsOpen, [@actualCoords];
if (${$ringNodes[$i]}[0] == ${$ringNodes[$i]}[-1]) { } # printRingCoords(\@actualCoords);
push @ringCoordsClosed, [@actualCoords] ; # islands
}
else {
push @ringCoordsOpen, [@actualCoords] ;
}
# printRingCoords (\@actualCoords) ;
my $num = scalar @actualCoords; my $num = scalar @actualCoords;
if (cv('debug') eq "1") { print "COAST: initial ring $i - $actualCoords[0]->[0],$actualCoords[0]->[1] -->> $actualCoords[-1]->[0],$actualCoords[-1]->[1] nodes: $num\n" ; } print "COAST: initial ring $i - $actualCoords[0]->[0],$actualCoords[0]->[1] -->> $actualCoords[-1]->[0],$actualCoords[-1]->[1] nodes: $num\n" if cv('debug');
} }
if(cv('debug')eq "1"){print "COAST: add points on border...\n";} foreach my $ring(@ringCoordsOpen){ # print "COAST: ring $ring with border nodes\n";
if (cv('debug') eq "1") { print "COAST: add points on border...\n" ; }
foreach my $ring (@ringCoordsOpen) {
# print "COAST: ring $ring with border nodes\n" ;
# add first point on border # add first point on border
my $ref = nearestPoint($ring->[0]); my $ref = nearestPoint($ring->[0]);
my @a = @$ref; my @a = @$ref;
@ -253,15 +159,14 @@ sub processCoastLines {
push @$ring, [@a]; push @$ring, [@a];
# printRingCoords($ring); # printRingCoords($ring);
} }
my @islandRings = @ringCoordsClosed; my @islandRings = @ringCoordsClosed;
if (cv('debug') eq "1") { print "COAST: " . scalar (@islandRings) . " islands found.\n" ; } print "COAST: " . scalar(@islandRings). " islands found.\n" if cv('debug');
@ringCoordsClosed =(); @ringCoordsClosed =();
# process ringCoordsOpen # process ringCoordsOpen
# add other rings, corners... # add other rings, corners...
while(scalar @ringCoordsOpen > 0){# as long as there are open rings while(scalar @ringCoordsOpen > 0){# as long as there are open rings
if (cv('debug') eq "1") { print "COAST: building ring...\n" ; } print "COAST: building ring...\n" if(cv('debug');
my $ref = shift @ringCoordsOpen; # get start ring my $ref = shift @ringCoordsOpen; # get start ring
my @actualRing = @$ref; my @actualRing = @$ref;
@ -272,7 +177,7 @@ sub processCoastLines {
my $actualStartX = $actualRing[0]->[0]; my $actualStartX = $actualRing[0]->[0];
my $actualStartY = $actualRing[0]->[1]; my $actualStartY = $actualRing[0]->[1];
if (cv('debug') eq "1") { print "COAST: actual and actualStart $actualX, $actualY - $actualStartX, $actualStartY\n" ; } print "COAST: actual and actualStart $actualX, $actualY - $actualStartX, $actualStartY\n" if cv('debug');
my $corner; my $corner;
while(!$closed){# as long as this ring is not closed while(!$closed){# as long as this ring is not closed
@ -280,19 +185,12 @@ sub processCoastLines {
# print " actual $actualX, $actualY\n"; # print " actual $actualX, $actualY\n";
my $startFromOtherPolygon = -1; my $startFromOtherPolygon = -1;
# find matching ring if there is another ring # find matching ring if there is another ring
if (scalar @ringCoordsOpen > 0) { if(scalar(@ringCoordsOpen)> 0){ for(my $i=0; $i <= $#ringCoordsOpen; $i++){ my @test = @{$ringCoordsOpen[$i]};
for (my $i=0; $i <= $#ringCoordsOpen; $i++) {
my @test = @{$ringCoordsOpen[$i]} ;
# print " test ring $i: ", $test[0]->[0], " " , $test[0]->[1] , "\n"; # print " test ring $i: ", $test[0]->[0], " " , $test[0]->[1] , "\n";
if ( ($actualX == $test[0]->[0]) and ($actualY == $test[0]->[1]) ) { if(($actualX == $test[0]->[0])and($actualY == $test[0]->[1])){ $startFromOtherPolygon = $i;
$startFromOtherPolygon = $i ; print "COAST: matching start other polygon found i= $i\n" if cv('debug');
if (cv('debug') eq "1") { print "COAST: matching start other polygon found i= $i\n" ; } } } } # process matching polygon, if present
} if($startFromOtherPolygon != -1){# start from other polygon{ # append nodes
}
}
# process matching polygon, if present
if ($startFromOtherPolygon != -1) { # start from other polygon {
# append nodes
# print "ARRAY TO PUSH: @{$ringCoordsOpen[$startFromOtherPolygon]}\n"; # print "ARRAY TO PUSH: @{$ringCoordsOpen[$startFromOtherPolygon]}\n";
push @actualRing, @{$ringCoordsOpen[$startFromOtherPolygon]}; push @actualRing, @{$ringCoordsOpen[$startFromOtherPolygon]};
# set actual # set actual
@ -300,118 +198,72 @@ sub processCoastLines {
$actualY = $actualRing[-1]->[1]; $actualY = $actualRing[-1]->[1];
# drop p2 from opens # drop p2 from opens
splice @ringCoordsOpen, $startFromOtherPolygon, 1; splice @ringCoordsOpen, $startFromOtherPolygon, 1;
if (cv('debug') eq "1") { print "COAST: openring $startFromOtherPolygon added to actual ring\n" ; } print "COAST: openring $startFromOtherPolygon added to actual ring\n" if cv('debug');
} } else{ if($corner){# add corner to actual ring
else {
if ($corner) { # add corner to actual ring
push @actualRing, [$actualX, $actualY]; push @actualRing, [$actualX, $actualY];
if (cv('debug') eq "1") { print "COAST: corner $actualX, $actualY added to actual ring\n" ; } print "COAST: corner $actualX, $actualY added to actual ring\n" if cv('debug');
} } } # check if closed
} if(($actualX == $actualStartX)and($actualY == $actualStartY)){ $closed = 1;
# check if closed
if ( ($actualX == $actualStartX) and ($actualY == $actualStartY) ) {
$closed = 1 ;
push @actualRing, [$actualX, $actualY]; push @actualRing, [$actualX, $actualY];
push @ringCoordsClosed, [@actualRing]; push @ringCoordsClosed, [@actualRing];
if (cv('debug') eq "1") { print "COAST: ring now closed and moved to closed rings.\n" ; } print "COAST: ring now closed and moved to closed rings.\n" if cv('debug');
} } }# !closed
} # !closed
}# open rings }# open rings
my $color = cv('oceancolor'); my $color = cv('oceancolor');
# build islandRings polygons # build islandRings polygons
if (cv('debug') eq "1") { print "OCEAN: building island polygons\n" ; } print "OCEAN: building island polygons\n" if cv('debug');
my @islandPolygons =(); my @islandPolygons =();
if (scalar @islandRings > 0) { if(scalar @islandRings > 0){ for(my $i=0; $i<=$#islandRings; $i++){ my @poly =();
for (my $i=0; $i<=$#islandRings; $i++) { foreach my $node(@{$islandRings[$i]}){ push @poly, [$node->[0], $node->[1]];
my @poly = () ; } my($p)= Math::Polygon->new(@poly);
foreach my $node ( @{$islandRings[$i]} ) {
push @poly, [$node->[0], $node->[1]] ;
}
my ($p) = Math::Polygon->new(@poly) ;
$islandPolygons[$i] = $p; $islandPolygons[$i] = $p;
} } }
}
# build ocean ring polygons # build ocean ring polygons
if (cv('debug') eq "1") { print "OCEAN: building ocean polygons\n" ; } if(cv('debug')eq "1"){print "OCEAN: building ocean polygons\n";} my @oceanPolygons =();
my @oceanPolygons = () ; if(scalar(@ringCoordsClosed)> 0){ for(my $i=0; $i<=$#ringCoordsClosed; $i++){ my @poly =();
if (scalar @ringCoordsClosed > 0) { foreach my $node(@{$ringCoordsClosed[$i]}){ push @poly, [$node->[0], $node->[1]];
for (my $i=0; $i<=$#ringCoordsClosed; $i++) { } my($p)= Math::Polygon->new(@poly);
my @poly = () ;
foreach my $node ( @{$ringCoordsClosed[$i]} ) {
push @poly, [$node->[0], $node->[1]] ;
}
my ($p) = Math::Polygon->new(@poly) ;
$oceanPolygons[$i] = $p; $oceanPolygons[$i] = $p;
} } } else{ if(scalar(@islandRings)> 0){ if(cv('debug')eq "1"){print "OCEAN: build ocean rect\n";} my @ocean =();
}
else {
if (scalar @islandRings > 0) {
if (cv('debug') eq "1") { print "OCEAN: build ocean rect\n" ; }
my @ocean = () ;
my($x, $y)= getDimensions(); my($x, $y)= getDimensions();
push @ocean, [0,0], [$x,0], [$x,$y], [0,$y], [0,0]; push @ocean, [0,0], [$x,0], [$x,$y], [0,$y], [0,0];
push @ringCoordsClosed, [@ocean]; push @ringCoordsClosed, [@ocean];
my($p)= Math::Polygon->new(@ocean); my($p)= Math::Polygon->new(@ocean);
push @oceanPolygons, $p; push @oceanPolygons, $p;
} } }
}
# finally create pathes for SVG # finally create pathes for SVG
for (my $i=0; $i<=$#ringCoordsClosed; $i++) { for(my $i=0; $i<=$#ringCoordsClosed; $i++){ # foreach my $ring(@ringCoordsClosed){ my @ring = @{$ringCoordsClosed[$i]};
# foreach my $ring (@ringCoordsClosed) {
my @ring = @{$ringCoordsClosed[$i]} ;
my @array =(); my @array =();
my @coords =(); my @coords =();
foreach my $c (@ring) { foreach my $c(@ring){ push @coords, $c->[0], $c->[1];
push @coords, $c->[0], $c->[1] ; } push @array, [@coords];
} if(scalar @islandRings > 0){ for(my $j=0; $j<=$#islandRings; $j++){ # island in ring? 1:1 and coast on border?
push @array, [@coords] ; # if(isIn($islandPolygons[$j], $oceanPolygons[$i])== 1){ if((isIn($islandPolygons[$j], $oceanPolygons[$i])== 1)or
if (scalar @islandRings > 0) { ((scalar @islandRings == 1)and(scalar @ringCoordsClosed == 1))){ if(cv('debug')eq "1"){print "OCEAN: island $j in ocean $i\n";} my @coords =();
for (my $j=0; $j<=$#islandRings; $j++) { foreach my $c(@{$islandRings[$j]}){ push @coords, $c->[0], $c->[1];
# island in ring? 1:1 and coast on border? } push @array, [@coords];
# if (isIn ($islandPolygons[$j], $oceanPolygons[$i]) == 1) { } } }
if ( (isIn ($islandPolygons[$j], $oceanPolygons[$i]) == 1) or
( (scalar @islandRings == 1) and (scalar @ringCoordsClosed == 1) ) ) {
if (cv('debug') eq "1") { print "OCEAN: island $j in ocean $i\n" ; }
my @coords = () ;
foreach my $c (@{$islandRings[$j]}) {
push @coords, $c->[0], $c->[1] ;
}
push @array, [@coords] ;
}
}
}
# drawAreaOcean($color, \@array); # drawAreaOcean($color, \@array);
my $svgText = "fill=\"$color\" "; my $svgText = "fill=\"$color\" ";
drawArea($svgText, "none", \@array, 0, "base"); drawArea($svgText, "none", \@array, 0, "base");
} }}}
} sub pointInMap{ my($n)= shift;
}
sub pointInMap {
my ($n) = shift ;
my($sizeX, $sizeY)= getDimensions(); my($sizeX, $sizeY)= getDimensions();
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
my($x, $y)= convert($$lonRef{$n}, $$latRef{$n}); my($x, $y)= convert($$lonRef{$n}, $$latRef{$n});
my $ok = 0; my $ok = 0;
if ( if(($x >= 0)and
( $x >= 0 ) and
($x <= $sizeX)and ($x <= $sizeX)and
($y >= 0)and ($y >= 0)and
( $y <= $sizeY ) ) { ($y <= $sizeY)){ $ok = 1;
$ok = 1 ; } return $ok;
} }
return $ok ;
}
1; 1;

View File

@ -1,9 +1,6 @@
# #
# PERL mapweaver module by gary68 # PERL mapweaver module by gary68
# #
#
#
#
# Copyright(C)2011, Gerhard Schwanz # Copyright(C)2011, Gerhard Schwanz
# #
# 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 # 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
@ -21,7 +18,6 @@ package mwConfig ;
use strict; use strict;
use warnings; use warnings;
use Getopt::Long; use Getopt::Long;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
@ -198,71 +194,37 @@ my %explanation = () ;
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
sub initConfig { sub initConfig{ # set initial values according to program internal values from array @initial
foreach my $kv(@initial){ $cv{lc($kv->[0])}= $kv->[1];
# set initial values according to program internal values from array @initial
foreach my $kv (@initial) {
$cv{ lc( $kv->[0] ) } = $kv->[1] ;
$explanation{lc($kv->[0])}= $kv->[2]; $explanation{lc($kv->[0])}= $kv->[2];
} }}
}
sub setConfigValue {
# allows any module to change a certain k/v pair
sub setConfigValue{ # allows any module to change a certain k/v pair
my($k, $v)= @_; my($k, $v)= @_;
$k = lc($k); $k = lc($k);
$cv{$k}= $v; $cv{$k}= $v;
if ($cv{"verbose"} > 1) { print "config key $k. value changed to $v\n" ; } if($cv{"verbose"}> 1){print "config key $k. value changed to $v\n";}}
} sub cv{ # access a value by key
sub cv {
# access a value by key
my $k = shift; my $k = shift;
$k = lc($k); $k = lc($k);
if ( ! defined $cv{ $k } ) { print "WARNING: requested config key $k not defined!\n" ; } if(! defined $cv{$k}){print "WARNING: requested config key $k not defined!\n";} return($cv{$k});
return ( $cv{ $k } ) ;
} }
sub printConfig{ # print actual config to stdout
sub printConfig {
# print actual config to stdout
print "\nActual configuration\n"; print "\nActual configuration\n";
my %cats =(); my %cats =();
foreach my $e (@initial) { foreach my $e(@initial){ $cats{$e->[3]}= 1;
$cats{ $e->[3] } = 1 ;
} }
foreach my $cat(sort keys %cats){ my @entries =();
foreach my $cat (sort keys %cats) { foreach my $e(@initial){ if($e->[3] eq $cat){ push @entries, $e->[0];
my @entries = () ; } } print "\nCATEGORY $cat\n";
foreach my $e (@initial) {
if ($e->[3] eq $cat) {
push @entries, $e->[0] ;
}
}
print "\nCATEGORY $cat\n" ;
print "--------\n"; print "--------\n";
foreach my $e ( sort { $a cmp $b } @entries ) { foreach my $e(sort{$a cmp $b}@entries){ printf "%-30s %-30s\n", $e, cv($e);
printf "%-30s %-30s\n", $e, cv($e) ; }} print "\n";
} }
} sub readConfigFile{ # read ini file; initial k/v pairs might be changed
print "\n" ;
}
sub readConfigFile {
# read ini file; initial k/v pairs might be changed
my $fileName = shift; my $fileName = shift;
my $lc = 0; my $lc = 0;
@ -270,30 +232,14 @@ sub readConfigFile {
open(my $file, "<", $fileName)or die("ERROR: could not open ini file $fileName\n"); open(my $file, "<", $fileName)or die("ERROR: could not open ini file $fileName\n");
my $line = ""; my $line = "";
while ($line = <$file>) { while($line = <$file>){ $lc++;
$lc ++ ; unless(grep(/^#/, $line)){ my($k, $v)=($line =~ /(.+?)=(.*)/);
if ( ! grep /^#/, $line) { if((! defined $k)or(! defined $v)){ print "WARNING: could not parse config line: $line";
my ($k, $v) = ( $line =~ /(.+?)=(.*)/ ) ; } else{ $k = lc($k);
if ( ( ! defined $k ) or ( ! defined $v ) ) {
print "WARNING: could not parse config line: $line" ;
}
else {
$k = lc ( $k ) ;
$cv{$k}= $v; $cv{$k}= $v;
} } }} close $file;
}
}
close ($file) ;
print "$lc lines read.\n\n"; print "$lc lines read.\n\n";
} }sub getProgramOptions{my $optResult = GetOptions("in=s" => \$cv{'in'}, # the in file, mandatory
# ---------------------------------------------------------------------------------------
sub getProgramOptions {
my $optResult = GetOptions ( "in=s" => \$cv{'in'}, # the in file, mandatory
"overpass" => \$cv{'overpass'}, "overpass" => \$cv{'overpass'},
"near:s" => \$cv{'near'}, "near:s" => \$cv{'near'},
"overpassdistance:i" => \$cv{'overpassdistance'}, "overpassdistance:i" => \$cv{'overpassdistance'},
@ -378,27 +324,14 @@ my $optResult = GetOptions ( "in=s" => \$cv{'in'}, # the in file, mandatory
"cie" => \$cv{'cie'}, # turns debug messages on "cie" => \$cv{'cie'}, # turns debug messages on
"verbose" => \$cv{'verbose'}, # turns twitter on "verbose" => \$cv{'verbose'}, # turns twitter on
"test" => \$cv{'test'}); # test "test" => \$cv{'test'}); # test
} }
sub printConfigDescriptions{ my @texts = @initial;
sub printConfigDescriptions {
my @texts = @initial ;
@texts = sort{$a->[0] cmp $b->[0]}@texts; @texts = sort{$a->[0] cmp $b->[0]}@texts;
print "\nconfig value descriptions\n\n"; print "\nconfig value descriptions\n\n";
printf "%-25s %-50s %-20s\n" , "key" , "description", "default"; printf "%-25s %-50s %-20s\n" , "key" , "description", "default";
foreach my $t (@texts) { foreach my $t(@texts){ my $def = $t->[1];
my $def = $t->[1] ; $def = "<EMPTY>" unless $def;
if ($def eq "") { $def = "<EMPTY>" ; }
printf "%-25s %-50s %-20s\n" , $t->[0] , $t->[2], $def; printf "%-25s %-50s %-20s\n" , $t->[0] , $t->[2], $def;
} } print "\n";
print "\n" ; }1;
}
1 ;

224
mwFile.pm
View File

@ -24,8 +24,8 @@ use warnings ;
use mwConfig; use mwConfig;
use mwMap; use mwMap;
use mwLabel; use mwLabel;
use LWP::Simple ;
use LWP::Simple;
use OSM::osm; use OSM::osm;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
@ -42,11 +42,10 @@ require Exporter ;
my %lon; my %lon;
my %lat; my %lat;
my %memNodeTags ;
my %memNodeTags;
my %memWayNodes; my %memWayNodes;
my %memWayTags; my %memWayTags;
my %memRelationMembers; my %memRelationMembers;
my %memRelationTags; my %memRelationTags;
@ -56,7 +55,6 @@ my $overpassSource3 = "interpreter?data=%28node%28BOTTOM%2CLEFT%2CTOP%2CRIGHT%29
sub readFile{ sub readFile{
my($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1, @nodeTags); my($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1, @nodeTags);
my($wayId, $wayUser, $aRef2, @wayTags, @wayNodes); my($wayId, $wayUser, $aRef2, @wayTags, @wayNodes);
my($relationId, $relationUser, @relationTags, @relationMembers); my($relationId, $relationUser, @relationTags, @relationMembers);
@ -66,40 +64,30 @@ sub readFile {
my $osmName; my $osmName;
if(defined cv('in')){$osmName = cv('in');} if(defined cv('in')){$osmName = cv('in');}
my $clipbbox = ""; my $clipbbox = "";
if(defined cv('clipbbox')){$clipbbox = cv('clipbbox');} if(defined cv('clipbbox')){$clipbbox = cv('clipbbox');}
if(cv('overpass')eq "1"){ if(cv('place')eq ""){die("ERROR: option place not specified.\n");}
if ( cv('overpass') eq "1" ) {
if ( cv('place') eq "" ) { die ("ERROR: option place not specified.\n") ; }
my $overpassNear = cv('near'); my $overpassNear = cv('near');
my $overpassDistance = cv('overpassdistance'); my $overpassDistance = cv('overpassdistance');
my $overpassName = cv('place'); my $overpassName = cv('place');
my $overpassUrl1 = cv('overpassserver'). $overpassSource1; my $overpassUrl1 = cv('overpassserver'). $overpassSource1;
if ( cv('near') eq "" ) { if(cv('near')eq ""){ $overpassUrl1 = cv('overpassserver'). $overpassSource0;
$overpassUrl1 = cv('overpassserver') . $overpassSource0 ;
} }
$overpassUrl1 =~ s/NEAR/$overpassNear/; $overpassUrl1 =~ s/NEAR/$overpassNear/;
$overpassUrl1 =~ s/DIST/$overpassDistance/; $overpassUrl1 =~ s/DIST/$overpassDistance/;
$overpassUrl1 =~ s/NAME/$overpassName/; $overpassUrl1 =~ s/NAME/$overpassName/;
if ( cv('debug') eq "1" ) { print "Overpass Query1: $overpassUrl1 ...\n" ; } if(cv('debug')eq "1"){print "Overpass Query1: $overpassUrl1 ...\n";} print "Send Query 1 to overpass server..\n";
print "Send Query 1 to overpass server..\n" ;
my $result1 = get($overpassUrl1); my $result1 = get($overpassUrl1);
if(! defined $result1){die("ERROR: bad overpass result!\n");} if(! defined $result1){die("ERROR: bad overpass result!\n");}
if(cv('debug')eq "1"){print "\n$result1\n\n";} if(cv('debug')eq "1"){print "\n$result1\n\n";}
# get lon, lat # get lon, lat
my($placeLon)=($result1 =~ /lon=\"([\d\.\-]+)/); my($placeLon)=($result1 =~ /lon=\"([\d\.\-]+)/);
my($placeLat)=($result1 =~ /lat=\"([\d\.\-]+)/); my($placeLat)=($result1 =~ /lat=\"([\d\.\-]+)/);
if((! defined $placeLon)or(! defined $placeLat)){die("ERROR: lon/lat could not be obtained from 1st overpass result.\n");} if((! defined $placeLon)or(! defined $placeLat)){die("ERROR: lon/lat could not be obtained from 1st overpass result.\n");}
print "place $overpassName found:\n"; print "place $overpassName found:\n";
print "lon= $placeLon\n"; print "lon= $placeLon\n";
print "lat= $placeLat\n"; print "lat= $placeLat\n";
@ -119,11 +107,9 @@ sub readFile {
$overpassUrl2 =~ s/BOTTOM/$overBottom/; $overpassUrl2 =~ s/BOTTOM/$overBottom/;
if ( cv('debug') eq "1" ) { print "Overpass Query2: $overpassUrl2\n" ; } if(cv('debug')eq "1"){print "Overpass Query2: $overpassUrl2\n";} print "Send Query 2 to overpass server..\n";
print "Send Query 2 to overpass server..\n" ;
my $result2 = get($overpassUrl2); my $result2 = get($overpassUrl2);
if(! defined $result2){die("ERROR: bad overpass result!\n");} if(! defined $result2){die("ERROR: bad overpass result!\n");}
# save # save
@ -138,11 +124,8 @@ sub readFile {
# setConfigValue('place', ''); # setConfigValue('place', '');
$clipbbox = "$overLeft,$overBottom,$overRight,$overTop"; $clipbbox = "$overLeft,$overBottom,$overRight,$overTop";
if ( cv('debug') eq "1" ) { print "clipbox: $clipbbox\n" ; } if(cv('debug')eq "1"){print "clipbox: $clipbbox\n";}}
} if(grep /\.pbf/, $osmName){ my $newName = $osmName;
if ( grep /\.pbf/, $osmName ) {
my $newName = $osmName ;
$newName =~ s/\.pbf/\.osm/i; $newName =~ s/\.pbf/\.osm/i;
# osmosis # osmosis
@ -154,7 +137,6 @@ sub readFile {
setConfigValue("in", $newName); setConfigValue("in", $newName);
} }
# -place given? look for place and call osmosis # -place given? look for place and call osmosis
my $left; my $left;
@ -163,46 +145,28 @@ sub readFile {
my $bottom; my $bottom;
my $placeFound = 0; my $placeLon; my $placeLat; my $placeFound = 0; my $placeLon; my $placeLat;
if ( ( cv('place') ne "") and (cv('overpass') ne "1" ) ) { if((cv('place')ne "")and(cv('overpass')ne "1")){ my($placeId)=(cv('place')=~ /([\d]+)/);
my ($placeId) = ( cv('place') =~ /([\d]+)/); if(!defined $placeId){$placeId = -999999999;} print "looking for place...\n";
if (!defined $placeId) { $placeId = -999999999 ; }
print "looking for place...\n" ;
my $placeFileName = ""; my $placeFileName = "";
if(cv('placeFile')ne ""){ if(cv('placeFile')ne ""){
$placeFileName = cv('placeFile'); $placeFileName = cv('placeFile');
} else{ $placeFileName = cv('in');
} }
else {
$placeFileName = cv('in') ;
}
openOsmFile($placeFileName); openOsmFile($placeFileName);
($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2(); ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2();
if ($nodeId != -1) { if($nodeId != -1){ @nodeTags = @$aRef1;
@nodeTags = @$aRef1 ; } my $place = cv('place');
} while(($nodeId != -1)and($placeFound == 0)){ my $placeNode = 0; my $placeName = 0;
my $place = cv ('place') ; foreach my $tag(@nodeTags){ if($tag->[0] eq "place"){$placeNode = 1;} if(($tag->[0] eq "name")and(grep /$place/i, $tag->[1])){$placeName = 1;} } if((($placeNode == 1)and($placeName == 1))or($placeId == $nodeId)){ $placeFound = 1;
while ( ($nodeId != -1) and ($placeFound == 0) ) {
my $placeNode = 0 ; my $placeName = 0 ;
foreach my $tag ( @nodeTags ) {
if ($tag->[0] eq "place") { $placeNode = 1 ; }
if ( ($tag->[0] eq "name") and (grep /$place/i, $tag->[1]) ){ $placeName = 1 ; }
}
if ( (($placeNode == 1) and ($placeName == 1)) or ($placeId == $nodeId) ) {
$placeFound = 1 ;
$placeLon = $nodeLon; $placeLon = $nodeLon;
$placeLat = $nodeLat; $placeLat = $nodeLat;
} } ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2();
($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) = getNode2 () ; if($nodeId != -1){ @nodeTags = @$aRef1;
if ($nodeId != -1) { } }
@nodeTags = @$aRef1 ;
}
}
closeOsmFile(); closeOsmFile();
if ($placeFound == 1) { if($placeFound == 1){ print "place $place found at ";
print "place $place found at " ;
print "lon: $placeLon "; print "lon: $placeLon ";
print "lat: $placeLat\n"; print "lat: $placeLat\n";
$left = $placeLon - cv('lonrad')/(111.11 * cos($placeLat / 360 * 3.14 * 2)); $left = $placeLon - cv('lonrad')/(111.11 * cos($placeLat / 360 * 3.14 * 2));
@ -212,41 +176,28 @@ sub readFile {
print "call osmosis...\n"; print "call osmosis...\n";
if ( cv('cie') eq "0" ) { if(cv('cie')eq "0"){ print "OSMOSIS STRING: --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right\n";
print "OSMOSIS STRING: --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right\n" ;
`osmosis --read-xml $osmName --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --write-xml ./temp.osm`; `osmosis --read-xml $osmName --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --write-xml ./temp.osm`;
} } else{ print "OSMOSIS STRING: --bounding-box clipIncompleteEntities=yes bottom=$bottom top=$top left=$left right=$right\n";
else {
print "OSMOSIS STRING: --bounding-box clipIncompleteEntities=yes bottom=$bottom top=$top left=$left right=$right\n" ;
`osmosis --read-xml $osmName --bounding-box clipIncompleteEntities=yes bottom=$bottom top=$top left=$left right=$right --write-xml ./temp.osm`; `osmosis --read-xml $osmName --bounding-box clipIncompleteEntities=yes bottom=$bottom top=$top left=$left right=$right --write-xml ./temp.osm`;
} }
print "osmosis done.\n"; print "osmosis done.\n";
$osmName = "./temp.osm"; $osmName = "./temp.osm";
$clipbbox = "$left,$bottom,$right,$top"; $clipbbox = "$left,$bottom,$right,$top";
} } else{ print "ERROR: place $place not found.\n";
else {
print "ERROR: place $place not found.\n" ;
die(); die();
} }}
}
my $srtmFileName = cv('srtm'); my $srtmFileName = cv('srtm');
if($srtmFileName ne ""){ if($srtmFileName ne ""){
my $cmdX = "osmosis --read-xml $osmName --rx file=\"$srtmFileName\" --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --merge --write-xml file=\"./temp2.osm\""; my $cmdX = "osmosis --read-xml $osmName --rx file=\"$srtmFileName\" --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --merge --write-xml file=\"./temp2.osm\"";
my $cmdP = "osmosis --read-xml $osmName --read-pbf file=\"$srtmFileName\" --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --merge --write-xml file=\"./temp2.osm\""; my $cmdP = "osmosis --read-xml $osmName --read-pbf file=\"$srtmFileName\" --bounding-box completeWays=yes completeRelations=yes bottom=$bottom top=$top left=$left right=$right --merge --write-xml file=\"./temp2.osm\"";
my $cmd = ""; my $cmd = "";
if (grep /\.pbf/, $srtmFileName) { if(grep /\.pbf/, $srtmFileName){ $cmd = $cmdP;
$cmd = $cmdP ; } else{ $cmd = $cmdX;
} }
else {
$cmd = $cmdX ;
}
print "call osmosis to merge SRTM data...\n$cmd\n"; print "call osmosis to merge SRTM data...\n$cmd\n";
`$cmd`; `$cmd`;
@ -254,146 +205,90 @@ sub readFile {
$osmName = "temp2.osm"; $osmName = "temp2.osm";
} }
# STORE DATA # STORE DATA
my $nr = 0; my $wr = 0; my $rr = 0; my $nr = 0; my $wr = 0; my $rr = 0;
print "reading osm file...\n"; print "reading osm file...\n";
openOsmFile($osmName); openOsmFile($osmName);
($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2(); ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2();
if ($nodeId != -1) { if($nodeId != -1){ @nodeTags = @$aRef1;
@nodeTags = @$aRef1 ; } while($nodeId != -1){ $nr++;
}
while ($nodeId != -1) {
$nr++ ;
$lon{$nodeId}= $nodeLon; $lat{$nodeId}= $nodeLat; $lon{$nodeId}= $nodeLon; $lat{$nodeId}= $nodeLat;
@{$memNodeTags{$nodeId}}= @nodeTags; @{$memNodeTags{$nodeId}}= @nodeTags;
($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2(); ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1)= getNode2();
if ($nodeId != -1) { if($nodeId != -1){ @nodeTags = @$aRef1;
@nodeTags = @$aRef1 ; }}
}
}
($wayId, $wayUser, $aRef1, $aRef2)= getWay2(); ($wayId, $wayUser, $aRef1, $aRef2)= getWay2();
if ($wayId != -1) { if($wayId != -1){ @wayNodes = @$aRef1;
@wayNodes = @$aRef1 ;
@wayTags = @$aRef2; @wayTags = @$aRef2;
} } while($wayId != -1){ $wr++;
while ($wayId != -1) { if(scalar(@wayNodes)> 1){ @{$memWayTags{$wayId}}= @wayTags;
$wr++ ;
if (scalar (@wayNodes) > 1) {
@{$memWayTags{$wayId}} = @wayTags ;
@{$memWayNodes{$wayId}}= @wayNodes; @{$memWayNodes{$wayId}}= @wayNodes;
foreach my $node (@wayNodes) { foreach my $node(@wayNodes){ if(!defined $lon{$node}){ print " ERROR: way $wayId references node $node, which is not present!\n";
if (!defined $lon{$node}) { } } } else{ $invalidWays{$wayId}= 1;
print " ERROR: way $wayId references node $node, which is not present!\n" ;
} }
}
}
else {
$invalidWays{$wayId} = 1 ;
}
($wayId, $wayUser, $aRef1, $aRef2)= getWay2(); ($wayId, $wayUser, $aRef1, $aRef2)= getWay2();
if ($wayId != -1) { if($wayId != -1){ @wayNodes = @$aRef1;
@wayNodes = @$aRef1 ;
@wayTags = @$aRef2; @wayTags = @$aRef2;
} }}
}
($relationId, $relationUser, $aRef1, $aRef2)= getRelation(); ($relationId, $relationUser, $aRef1, $aRef2)= getRelation();
if ($relationId != -1) { if($relationId != -1){ @relationMembers = @$aRef1;
@relationMembers = @$aRef1 ;
@relationTags = @$aRef2; @relationTags = @$aRef2;
} }
while($relationId != -1){ $rr++;
while ($relationId != -1) {
$rr++ ;
@{$memRelationTags{$relationId}}= @relationTags; @{$memRelationTags{$relationId}}= @relationTags;
@{$memRelationMembers{$relationId}}= @relationMembers; @{$memRelationMembers{$relationId}}= @relationMembers;
foreach my $member (@relationMembers) { foreach my $member(@relationMembers){ if(($member->[0] eq "node")and(!defined $lon{$member->[1]})){ print " ERROR: relation $relationId references node $member->[1] which is not present!\n";
if ( ($member->[0] eq "node") and (!defined $lon{$member->[1]}) ) { } if(($member->[0] eq "way")and(!defined $memWayNodes{$member->[1]})and(!defined $invalidWays{$member->[1]})){ print " ERROR: relation $relationId references way $member->[1] which is not present or invalid!\n";
print " ERROR: relation $relationId references node $member->[1] which is not present!\n" ; } }
}
if ( ($member->[0] eq "way") and (!defined $memWayNodes{$member->[1]} ) and (!defined $invalidWays{$member->[1]}) ) {
print " ERROR: relation $relationId references way $member->[1] which is not present or invalid!\n" ;
}
}
#next #next
($relationId, $relationUser, $aRef1, $aRef2)= getRelation(); ($relationId, $relationUser, $aRef1, $aRef2)= getRelation();
if ($relationId != -1) { if($relationId != -1){ @relationMembers = @$aRef1;
@relationMembers = @$aRef1 ;
@relationTags = @$aRef2; @relationTags = @$aRef2;
} }}
}
closeOsmFile(); closeOsmFile();
print "read: $nr nodes, $wr ways and $rr relations.\n\n"; print "read: $nr nodes, $wr ways and $rr relations.\n\n";
# calc area of pic and init graphics # calc area of pic and init graphics
my $lonMin = 999; my $lonMax = -999; my $latMin = 999; my $latMax = -999; my $lonMin = 999; my $lonMax = -999; my $latMin = 999; my $latMax = -999;
foreach my $key (keys %lon) { foreach my $key(keys %lon){ if($lon{$key}> $lonMax){$lonMax = $lon{$key};} if($lon{$key}< $lonMin){$lonMin = $lon{$key};} if($lat{$key}> $latMax){$latMax = $lat{$key};} if($lat{$key}< $latMin){$latMin = $lat{$key};}}
if ($lon{$key} > $lonMax) { $lonMax = $lon{$key} ; }
if ($lon{$key} < $lonMin) { $lonMin = $lon{$key} ; }
if ($lat{$key} > $latMax) { $latMax = $lat{$key} ; }
if ($lat{$key} < $latMin) { $latMin = $lat{$key} ; }
}
# clip picture if desired # clip picture if desired
if ($clipbbox ne "") { if($clipbbox ne ""){ my($bbLeft, $bbBottom, $bbRight, $bbTop)=($clipbbox =~ /([\d\-\.]+),([\d\-\.]+),([\d\-\.]+),([\d\-\.]+)/);
my ($bbLeft, $bbBottom, $bbRight, $bbTop) = ($clipbbox =~ /([\d\-\.]+),([\d\-\.]+),([\d\-\.]+),([\d\-\.]+)/ ) ;
# print "$bbLeft, $bbBottom, $bbRight, $bbTop\n"; # print "$bbLeft, $bbBottom, $bbRight, $bbTop\n";
if (($bbLeft > $lonMax) or ($bbLeft < $lonMin)) { print "WARNING -clipbox left parameter outside data.\n" ; } if(($bbLeft > $lonMax)or($bbLeft < $lonMin)){print "WARNING -clipbox left parameter outside data.\n";} if(($bbRight > $lonMax)or($bbRight < $lonMin)){print "WARNING -clipbox right parameter outside data.\n";} if(($bbBottom > $latMax)or($bbBottom < $latMin)){print "WARNING -clipbox bottom parameter outside data.\n";} if(($bbTop > $latMax)or($bbTop < $latMin)){print "WARNING -clipbox top parameter outside data.\n";} $lonMin = $bbLeft;
if (($bbRight > $lonMax) or ($bbRight < $lonMin)) { print "WARNING -clipbox right parameter outside data.\n" ; }
if (($bbBottom > $latMax) or ($bbBottom < $latMin)) { print "WARNING -clipbox bottom parameter outside data.\n" ; }
if (($bbTop > $latMax) or ($bbTop < $latMin)) { print "WARNING -clipbox top parameter outside data.\n" ; }
$lonMin = $bbLeft ;
$lonMax = $bbRight; $lonMax = $bbRight;
$latMin = $bbBottom; $latMin = $bbBottom;
$latMax = $bbTop; $latMax = $bbTop;
} } else{ if(defined cv('clip')){ if((cv('clip')> 0)and(cv('clip')< 100)){
else {
if (defined cv('clip')) {
if ( (cv('clip') > 0) and (cv('clip') < 100) ) {
my $clip = cv('clip'); my $clip = cv('clip');
$clip = $clip / 100; $clip = $clip / 100;
$lonMin +=($lonMax-$lonMin)* $clip; $lonMin +=($lonMax-$lonMin)* $clip;
$lonMax -=($lonMax-$lonMin)* $clip; $lonMax -=($lonMax-$lonMin)* $clip;
$latMin +=($latMax-$latMin)* $clip; $latMin +=($latMax-$latMin)* $clip;
$latMax -=($latMax-$latMin)* $clip; $latMax -=($latMax-$latMin)* $clip;
} } }}
}
}
# pad picture if desired # pad picture if desired
if (defined cv('pad')) { if(defined cv('pad')){ my $pad = cv('pad');
my $pad = cv('pad') ;
if(($pad > 0)and($pad < 100)){ if(($pad > 0)and($pad < 100)){
$pad = $pad / 100; $pad = $pad / 100;
$lonMin -=($lonMax-$lonMin)* $pad; $lonMin -=($lonMax-$lonMin)* $pad;
$lonMax +=($lonMax-$lonMin)* $pad; $lonMax +=($lonMax-$lonMin)* $pad;
$latMin -=($latMax-$latMin)* $pad; $latMin -=($latMax-$latMin)* $pad;
$latMax +=($latMax-$latMin)* $pad; $latMax +=($latMax-$latMin)* $pad;
} }}
}
my $size = cv('size'); my $size = cv('size');
# calc pic size # calc pic size
if ( cv('scaleSet') != 0 ) { if(cv('scaleSet')!= 0){ my $dist = distance($lonMin, $latMin, $lonMax, $latMin);
my $dist = distance ($lonMin, $latMin, $lonMax, $latMin) ;
my $width = $dist / cv('scaleSet')* 1000 * 100 / 2.54; # inches my $width = $dist / cv('scaleSet')* 1000 * 100 / 2.54; # inches
$size = int($width * 300); $size = int($width * 300);
} }
if(cv('maxTargetSize')ne ""){ my @a = split /,/, cv('maxTargetSize');
if ( cv('maxTargetSize') ne "" ) {
my @a = split /,/, cv('maxTargetSize') ;
my $targetWidth = $a[0]; my $targetWidth = $a[0];
my $targetHeight = $a[1]; my $targetHeight = $a[1];
# print "TS: $targetWidth, $targetHeight [cm]\n"; # print "TS: $targetWidth, $targetHeight [cm]\n";
@ -403,32 +298,23 @@ sub readFile {
my $scaleLon =($distLon * 1000 * 100)/ $targetWidth; my $scaleLon =($distLon * 1000 * 100)/ $targetWidth;
my $scaleLat =($distLat * 1000 * 100)/ $targetHeight; my $scaleLat =($distLat * 1000 * 100)/ $targetHeight;
my $targetScale = int $scaleLon; my $targetScale = int $scaleLon;
if ( $scaleLat > $targetScale ) { $targetScale = int $scaleLat ; } if($scaleLat > $targetScale){$targetScale = int $scaleLat;} # print "TS: $targetScale [1:n]\n";
# print "TS: $targetScale [1:n]\n" ;
my $width = $distLon / $targetScale * 1000 * 100 / 2.54; # inches my $width = $distLon / $targetScale * 1000 * 100 / 2.54; # inches
$size = int($width * 300); $size = int($width * 300);
print "Map width now $size [px] due to maxTargetSize parameter\n"; print "Map width now $size [px] due to maxTargetSize parameter\n";
} }
mwMap::initGraph($size, $lonMin, $latMin, $lonMax, $latMax); mwMap::initGraph($size, $lonMin, $latMin, $lonMax, $latMax);
} }
sub getNodePointers{ return(\%lon, \%lat, \%memNodeTags);
sub getNodePointers {
return ( \%lon, \%lat, \%memNodeTags) ;
} }
sub getWayPointers{ return(\%memWayNodes, \%memWayTags);
sub getWayPointers {
return ( \%memWayNodes, \%memWayTags) ;
} }
sub getRelationPointers{ sub getRelationPointers{
return(\%memRelationMembers, \%memRelationTags); return(\%memRelationMembers, \%memRelationTags);
} }
1; 1;

View File

@ -38,7 +38,6 @@ require Exporter ;
sub processGPXFile{ sub processGPXFile{
my($ref1, $ref2, $ref3)= readGPXFile(cv('gpx')); my($ref1, $ref2, $ref3)= readGPXFile(cv('gpx'));
my %wptHash = %$ref1; my %wptHash = %$ref1;
@ -48,30 +47,24 @@ sub processGPXFile {
my $size = cv('gpxsize'); my $size = cv('gpxsize');
my $color = cv('gpxcolor'); my $color = cv('gpxcolor');
foreach my $wptNr ( sort { $a <=> $b } keys %wptHash) { foreach my $wptNr(sort{$a <=> $b}keys %wptHash){ # print "WPT $wptNr: $wptHash{$wptNr}{'lon'}$wptHash{$wptNr}{'lat'}\n";
# print "WPT $wptNr: $wptHash{$wptNr}{'lon'} $wptHash{$wptNr}{'lat'}\n" ;
if(defined $wptHash{$wptNr}{'name'}){ if(defined $wptHash{$wptNr}{'name'}){
# print " name: $wptHash{$wptNr}{'name'}\n"; # print " name: $wptHash{$wptNr}{'name'}\n";
} } if(defined $wptHash{$wptNr}{'ele'}){
if (defined $wptHash{$wptNr}{'ele'}) {
# print " ele: $wptHash{$wptNr}{'ele'}\n"; # print " ele: $wptHash{$wptNr}{'ele'}\n";
} }
my $svgString = "fill=\"$color\" stroke=\"none\" "; my $svgString = "fill=\"$color\" stroke=\"none\" ";
my $lon = $wptHash{$wptNr}{'lon'}; my $lon = $wptHash{$wptNr}{'lon'};
my $lat = $wptHash{$wptNr}{'lat'}; my $lat = $wptHash{$wptNr}{'lat'};
drawCircle($lon, $lat, 1, 3*$size, 0, $svgString, 'gpx'); drawCircle($lon, $lat, 1, 3*$size, 0, $svgString, 'gpx');
} }
foreach my $rteNr(sort{$a <=> $b}keys %rteHash){ # print "RTE $rteNr\n";
foreach my $rteNr ( sort { $a <=> $b } keys %rteHash) {
# print "RTE $rteNr\n" ;
my @coords =(); my @coords =();
foreach my $rteWptNr ( sort { $a <=> $b } keys %{$rteHash{$rteNr}}) { foreach my $rteWptNr(sort{$a <=> $b}keys %{$rteHash{$rteNr}}){ # print " wpt $rteWptNr: $rteHash{$rteNr}{$rteWptNr}{'lon'}$rteHash{$rteNr}{$rteWptNr}{'lat'}\n";
# print " wpt $rteWptNr: $rteHash{$rteNr}{$rteWptNr}{'lon'} $rteHash{$rteNr}{$rteWptNr}{'lat'}\n" ;
my $svgString = "fill=\"$color\" stroke=\"none\" "; my $svgString = "fill=\"$color\" stroke=\"none\" ";
my $lon = $rteHash{$rteNr}{$rteWptNr}{'lon'}; my $lon = $rteHash{$rteNr}{$rteWptNr}{'lon'};
@ -81,7 +74,6 @@ sub processGPXFile {
my($x, $y)= convert($lon, $lat); my($x, $y)= convert($lon, $lat);
push @coords, $x, $y; push @coords, $x, $y;
} }
my $svgString = ""; my $svgString = "";
my $lc = "round"; my $lc = "round";
@ -91,29 +83,21 @@ sub processGPXFile {
drawWay(\@coords, 0, $svgString, "gpx", undef); drawWay(\@coords, 0, $svgString, "gpx", undef);
} }
foreach my $trkNr(sort{$a <=> $b}keys %trkHash){ # print "TRK $trkNr\n";
foreach my $trkNr ( sort { $a <=> $b } keys %trkHash) {
# print "TRK $trkNr\n" ;
my %seg; my %seg;
%seg = %{$trkHash{$trkNr}}; %seg = %{$trkHash{$trkNr}};
foreach my $segNr ( sort {$a <=> $b} keys %seg) { foreach my $segNr(sort{$a <=> $b}keys %seg){ # print " SEG $segNr\n";
# print " SEG $segNr\n" ;
my %points; my %points;
%points = %{$seg{$segNr}}; %points = %{$seg{$segNr}};
foreach my $ptNr ( sort { $a <=> $b } keys %points) { foreach my $ptNr(sort{$a <=> $b}keys %points){ # print " trkpt $ptNr: $points{$ptNr}{'lon'}$points{$ptNr}{'lat'}\n";
# print " trkpt $ptNr: $points{$ptNr}{'lon'} $points{$ptNr}{'lat'}\n" ;
my $svgString = "fill=\"$color\" stroke=\"none\" "; my $svgString = "fill=\"$color\" stroke=\"none\" ";
my $lon = $points{$ptNr}{'lon'}; my $lon = $points{$ptNr}{'lon'};
my $lat = $points{$ptNr}{'lat'}; my $lat = $points{$ptNr}{'lat'};
drawCircle($lon, $lat, 1, $size, 0, $svgString, 'gpx'); drawCircle($lon, $lat, 1, $size, 0, $svgString, 'gpx');
} }}
} }
}
}
}

View File

@ -22,13 +22,11 @@ my $style = "" ;
print "Mapweaver interactive\n\n"; print "Mapweaver interactive\n\n";
while ($place eq "") { while($place eq ""){ print "Please enter exact place name:\n";
print "Please enter exact place name:\n" ;
$place = <STDIN>; $place = <STDIN>;
print "\n"; print "\n";
chomp $place; chomp $place;
} }
# --- # ---
print "Please enter exact place name of bigger city i.e. in vicinity:\n"; print "Please enter exact place name of bigger city i.e. in vicinity:\n";
@ -44,7 +42,6 @@ print "\n" ;
chomp $dist; chomp $dist;
if($dist eq ""){$dist = 50000;} if($dist eq ""){$dist = 50000;}
# --- # ---
print "Please enter radius in km for latitude(defaults to 2km):\n"; print "Please enter radius in km for latitude(defaults to 2km):\n";
@ -52,7 +49,6 @@ $latrad = <STDIN> ;
print "\n"; print "\n";
chomp $latrad; chomp $latrad;
if($latrad eq ""){$latrad=2;} if($latrad eq ""){$latrad=2;}
# --- # ---
print "Please enter radius in km for longitude(defaults to 2km):\n"; print "Please enter radius in km for longitude(defaults to 2km):\n";
@ -60,7 +56,6 @@ $lonrad = <STDIN> ;
print "\n"; print "\n";
chomp $lonrad; chomp $lonrad;
if($lonrad eq ""){$lonrad=2;} if($lonrad eq ""){$lonrad=2;}
# --- # ---
print "Please enter scale of map(i.e. 10000 for 1:10.000):\n"; print "Please enter scale of map(i.e. 10000 for 1:10.000):\n";
@ -68,7 +63,6 @@ $scaleset = <STDIN> ;
print "\n"; print "\n";
chomp $scaleset; chomp $scaleset;
if($scaleset eq ""){$scaleset = 10000;} if($scaleset eq ""){$scaleset = 10000;}
# --- # ---
print "Output map in PDF format yes/no(defaults to yes):\n"; print "Output map in PDF format yes/no(defaults to yes):\n";
@ -76,16 +70,13 @@ $pdf = <STDIN> ;
print "\n"; print "\n";
chomp $pdf; chomp $pdf;
if(($pdf eq "")or(lc $pdf eq "yes")){$pdf = 1;} if(($pdf eq "")or(lc $pdf eq "yes")){$pdf = 1;}
# --- # ---
print "Output map in PNG format yes/no(defaults to no):\n"; print "Output map in PNG format yes/no(defaults to no):\n";
$png = <STDIN>; $png = <STDIN>;
print "\n"; print "\n";
chomp $png; chomp $png;
if (($png eq "") or (lc $png eq "no")) { $png = 0 ; } if(($png eq "")or(lc $png eq "no")){$png = 0;}if(lc $png eq "yes"){$png = 1;}
if (lc $png eq "yes") { $png = 1 ; }
# --- # ---
$outName = $place . ".svg"; $outName = $place . ".svg";
@ -95,9 +86,7 @@ $outName = <STDIN> ;
print "\n"; print "\n";
chomp $outName; chomp $outName;
if ($outName eq "") { $outName = $place . ".svg" ; } if($outName eq ""){$outName = $place . ".svg";}if(! grep /\.svg$/, $outName){$outName .= ".svg";}
if (! grep /\.svg$/, $outName) { $outName .= ".svg" ; }
# --- # ---
print "Select map style from list:\n"; print "Select map style from list:\n";
@ -107,18 +96,13 @@ $style = <STDIN> ;
print "\n"; print "\n";
chomp $style; chomp $style;
if ($style eq "2") { $style = "mwTopoRules.txt" ; } if($style eq "2"){$style = "mwTopoRules.txt";}else{$style = "mwStandardRules.txt";}
else { $style = "mwStandardRules.txt" ; }
my $cmd = "perl mw.pl -place=\"$place\" -overpass -style=\"$style\" -out=\"$outName\" -scaleset=$scaleset "; my $cmd = "perl mw.pl -place=\"$place\" -overpass -style=\"$style\" -out=\"$outName\" -scaleset=$scaleset ";
if ($near ne "") { $cmd .= "-near=\"$near\" -overpassdistance=$dist " ; } if($near ne ""){$cmd .= "-near=\"$near\" -overpassdistance=$dist ";}$cmd .= " -lonrad=$lonrad -latrad=$latrad ";
$cmd .= " -lonrad=$lonrad -latrad=$latrad " ; if($png eq "1"){$cmd .= " -png ";}if($pdf eq "1"){$cmd .= " -pdf ";}
if ($png eq "1") { $cmd .= " -png " ; }
if ($pdf eq "1") { $cmd .= " -pdf " ; }
print "call mw.pl: $cmd\n"; print "call mw.pl: $cmd\n";
`$cmd`; `$cmd`;

View File

@ -45,8 +45,7 @@ require Exporter ;
@ISA = qw(Exporter AutoLoader); @ISA = qw(Exporter AutoLoader);
@EXPORT = qw ( @EXPORT = qw( placeLabelAndIcon
placeLabelAndIcon
addToPoiHash addToPoiHash
getPoiHash getPoiHash
); );
@ -54,18 +53,15 @@ require Exporter ;
sub placeLabelAndIcon { sub placeLabelAndIcon{#
#
# intelligent icon and label placement alg. # intelligent icon and label placement alg.
# #
my($lon, $lat, $offset, $thickness, $text, $svgText, $icon, $iconSizeX, $iconSizeY, $layer)= @_; my($lon, $lat, $offset, $thickness, $text, $svgText, $icon, $iconSizeX, $iconSizeY, $layer)= @_;
if(cv('debug')eq "1"){print "PLAI: $lon, $lat, $offset, $thickness, $text, $svgText, $icon, $iconSizeX, $iconSizeY, $layer\n";} if(cv('debug')eq "1"){print "PLAI: $lon, $lat, $offset, $thickness, $text, $svgText, $icon, $iconSizeX, $iconSizeY, $layer\n";}
my($x, $y)= mwMap::convert($lon, $lat); # center ! my($x, $y)= mwMap::convert($lon, $lat); # center !
if(! coordsOut($x, $y)){ if(! coordsOut($x, $y)){
$y = $y + $offset; $y = $y + $offset;
my($ref)= splitLabel($text); my($ref)= splitLabel($text);
@ -79,52 +75,34 @@ sub placeLabelAndIcon {
my($textSize)=($svgText =~ /font-size=\"(\d+)\"/); my($textSize)=($svgText =~ /font-size=\"(\d+)\"/);
if(! defined $textSize){die("ERROR: font size could not be determined from svg format string \"$svgText\"\n");} if(! defined $textSize){die("ERROR: font size could not be determined from svg format string \"$svgText\"\n");}
foreach my $line(@lines){ my $len = length($line)* cv('ppc')/ 10 * $textSize; # in pixels
foreach my $line (@lines) { if($len > $maxTextLenPix){$maxTextLenPix = $len;} } my $spaceTextX = $maxTextLenPix;
my $len = length ($line) * cv('ppc') / 10 * $textSize ; # in pixels
if ($len > $maxTextLenPix) { $maxTextLenPix = $len ; }
}
my $spaceTextX = $maxTextLenPix ;
my $spaceTextY = $numLines *($lineDist+$textSize); my $spaceTextY = $numLines *($lineDist+$textSize);
if ($icon ne "none") { if($icon ne "none"){ $numIcons++;
$numIcons++ ;
# space for icon? # space for icon?
my $sizeX1 = $iconSizeX ; if ($sizeX1 == 0) { $sizeX1 = 20 ; } my $sizeX1 = $iconSizeX; if($sizeX1 == 0){$sizeX1 = 20;} my $sizeY1 = $iconSizeY; if($sizeY1 == 0){$sizeY1 = 20;} my $iconX = $x - $sizeX1/2; # top left corner
my $sizeY1 = $iconSizeY ; if ($sizeY1 == 0) { $sizeY1 = 20 ; }
my $iconX = $x - $sizeX1/2 ; # top left corner
my $iconY = $y - $sizeY1/2; my $iconY = $y - $sizeY1/2;
my @shifts =(0); my @shifts =(0);
if ($allowIconMove eq "1") { if($allowIconMove eq "1"){ @shifts =(0, -15, 15);
@shifts = ( 0, -15, 15 ) ; } my $posFound = 0; my $posCount = 0;
}
my $posFound = 0 ; my $posCount = 0 ;
my($iconAreaX1, $iconAreaY1, $iconAreaX2, $iconAreaY2); my($iconAreaX1, $iconAreaY1, $iconAreaX2, $iconAreaY2);
LABAB: foreach my $xShift (@shifts) { LABAB: foreach my $xShift(@shifts){ foreach my $yShift(@shifts){ $posCount++;
foreach my $yShift (@shifts) { if((! boxAreaOccupied($iconX+$xShift, $iconY+$sizeY1+$yShift, $iconX+$sizeX1+$xShift, $iconY+$yShift))or(cv('forcenodes')eq "1")){ placeIcon($iconX+$xShift, $iconY+$yShift, $icon, $sizeX1, $sizeY1, "nodes");
$posCount++ ;
if ( ( ! boxAreaOccupied ($iconX+$xShift, $iconY+$sizeY1+$yShift, $iconX+$sizeX1+$xShift, $iconY+$yShift) ) or ( cv('forcenodes') eq "1" ) ) {
placeIcon ($iconX+$xShift, $iconY+$yShift, $icon, $sizeX1, $sizeY1, "nodes") ;
$iconAreaX1 = $iconX+$xShift; $iconAreaX1 = $iconX+$xShift;
$iconAreaY1 = $iconY+$sizeY1+$yShift; $iconAreaY1 = $iconY+$sizeY1+$yShift;
$iconAreaX2 = $iconX+$sizeX1+$xShift; $iconAreaX2 = $iconX+$sizeX1+$xShift;
$iconAreaY2 = $iconY+$yShift; $iconAreaY2 = $iconY+$yShift;
$posFound = 1; $posFound = 1;
if ($posCount > 1) { $numIconsMoved++ ; } if($posCount > 1){$numIconsMoved++;} $iconX = $iconX + $xShift; # for later use with label
$iconX = $iconX + $xShift ; # for later use with label
$iconY = $iconY + $yShift; $iconY = $iconY + $yShift;
last LABAB; last LABAB;
} } } } if($posFound == 1){
}
}
if ($posFound == 1) {
# label text? # label text?
if ($text ne "") { if($text ne ""){ $numLabels++;
$numLabels++ ;
$sizeX1 += 1; $sizeY1 += 1; $sizeX1 += 1; $sizeY1 += 1;
@ -169,27 +147,18 @@ sub placeLabelAndIcon {
$tries = 0; $tries = 0;
LABB: foreach my $pos (@positions) { LABB: foreach my $pos(@positions){ $tries++;
$tries++ ;
$positionFound = checkAndDrawText($pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], \@lines, $svgText, $layer); $positionFound = checkAndDrawText($pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], \@lines, $svgText, $layer);
if ($positionFound == 1) { if($positionFound == 1){ last LABB;
last LABB ; } } if($positionFound == 0){$numLabelsOmitted++;} if($tries > 1){$numLabelsMoved++;} }# label
}
}
if ($positionFound == 0) { $numLabelsOmitted++ ; }
if ($tries > 1) { $numLabelsMoved++ ; }
} # label
boxOccupyArea($iconAreaX1, $iconAreaY1, $iconAreaX2, $iconAreaY2, 0, 2); boxOccupyArea($iconAreaX1, $iconAreaY1, $iconAreaX2, $iconAreaY2, 0, 2);
}# pos found }# pos found
else { else{ # no, count omitted
# no, count omitted
$numIconsOmitted++; $numIconsOmitted++;
} } } else{# only text
}
else { # only text
my($x1, $x2, $y1, $y2); my($x1, $x2, $y1, $y2);
# x1, x2, y1, y2 # x1, x2, y1, y2
# left, right, bottom, top # left, right, bottom, top
@ -215,31 +184,20 @@ sub placeLabelAndIcon {
my $positionFound = 0; my $positionFound = 0;
$tries = 0; $tries = 0;
LABA: foreach my $pos (@positions) { LABA: foreach my $pos(@positions){ $tries++;
$tries++ ;
# print "$lines[0] $pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], $numLines\n"; # print "$lines[0] $pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], $numLines\n";
$positionFound = checkAndDrawText($pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], \@lines, $svgText, $layer); $positionFound = checkAndDrawText($pos->[0], $pos->[1], $pos->[2], $pos->[3], $pos->[4], \@lines, $svgText, $layer);
if ($positionFound == 1) { if($positionFound == 1){ last LABA;
last LABA ; } } if($positionFound == 0){$numLabelsOmitted++;} if($tries > 1){$numLabelsMoved++;} }}}
}
}
if ($positionFound == 0) { $numLabelsOmitted++ ; }
if ($tries > 1) { $numLabelsMoved++ ; }
}
}
}
sub checkAndDrawText{#
sub checkAndDrawText {
#
# checks if area available and if so draws text # checks if area available and if so draws text
# #
my($x1, $x2, $y1, $y2, $orientation, $refLines, $svgText, $layer)= @_; my($x1, $x2, $y1, $y2, $orientation, $refLines, $svgText, $layer)= @_;
if(cv('debug')eq "1"){print "CADT: $x1, $x2, $y1, $y2, $orientation, $refLines, $svgText, $layer\n";} if(cv('debug')eq "1"){print "CADT: $x1, $x2, $y1, $y2, $orientation, $refLines, $svgText, $layer\n";}
my @lines = @$refLines; my @lines = @$refLines;
my $numLines = scalar @lines; my $numLines = scalar @lines;
my $lineDist = cv('linedist'); my $lineDist = cv('linedist');
@ -247,82 +205,48 @@ sub checkAndDrawText {
my($size)=($svgText =~ /font-size=\"(\d+)\"/); my($size)=($svgText =~ /font-size=\"(\d+)\"/);
if(! defined $size){die("ERROR: font size could not be determined from svg format string \"$svgText\"\n");} if(! defined $size){die("ERROR: font size could not be determined from svg format string \"$svgText\"\n");}
# WATCH for variable sequence! # WATCH for variable sequence!
if ( if((! boxAreaOccupied($x1, $y1, $x2, $y2))or
( ! boxAreaOccupied ($x1, $y1, $x2, $y2) ) or (cv('forcenodes')eq "1")){
( cv('forcenodes') eq "1" )
) {
for(my $i=0; $i<=$#lines; $i++){ for(my $i=0; $i<=$#lines; $i++){
my @points =($x1, $y2+($i+1)*($size+$lineDist), $x2, $y2+($i+1)*($size+$lineDist)); my @points =($x1, $y2+($i+1)*($size+$lineDist), $x2, $y2+($i+1)*($size+$lineDist));
my $pathName = "LabelPath" . $labelPathId; my $pathName = "LabelPath" . $labelPathId;
$labelPathId++; $labelPathId++;
createPath($pathName, \@points, "definitions"); createPath($pathName, \@points, "definitions");
if ($orientation eq "centered") { if($orientation eq "centered"){ pathText($svgText, $lines[$i], $pathName, 0, "middle", 50, $layer) } if($orientation eq "left"){ pathText($svgText, $lines[$i], $pathName, 0, "start", 0, $layer) } if($orientation eq "right"){ pathText($svgText, $lines[$i], $pathName, 0, "end", 100, $layer) } }
pathText ($svgText, $lines[$i], $pathName, 0, "middle", 50, $layer)
}
if ($orientation eq "left") {
pathText ($svgText, $lines[$i], $pathName, 0, "start", 0, $layer)
}
if ($orientation eq "right") {
pathText ($svgText, $lines[$i], $pathName, 0, "end", 100, $layer)
}
}
boxOccupyArea($x1, $y1, $x2, $y2, 0, 2); boxOccupyArea($x1, $y1, $x2, $y2, 0, 2);
return(1); return(1);
} } else{ return 0;
else { }}
return 0 ; sub splitLabel{#
}
}
sub splitLabel {
#
# split label text at space locations and then merge new parts if new part will be smaller than XX chars # split label text at space locations and then merge new parts if new part will be smaller than XX chars
# #
my $text = shift; my $text = shift;
my @lines = split / /, $text; my @lines = split / /, $text;
my $merged = 1; my $merged = 1;
while ($merged) { while($merged){ $merged = 0;
$merged = 0 ; LAB2: for(my $i=0; $i<$#lines; $i++){ if(length($lines[$i] . " " . $lines[$i+1])<= cv('maxcharperline')){
LAB2: for (my $i=0; $i<$#lines; $i++) {
if (length ($lines[$i] . " " . $lines[$i+1]) <= cv ('maxcharperline') ) {
$lines[$i] = $lines[$i] . " " . $lines[$i+1]; $lines[$i] = $lines[$i] . " " . $lines[$i+1];
splice(@lines, $i+1, 1); splice(@lines, $i+1, 1);
$merged = 1; $merged = 1;
last LAB2; last LAB2;
} }} return(\@lines);
} }
}
}
return (\@lines) ;
}
# ------------------------------------------------------------ # ------------------------------------------------------------
sub addToPoiHash { sub addToPoiHash{ my($name, $sq)= @_;
my ($name, $sq) = @_ ; if(defined $sq){ $poiHash{$name}{$sq}= 1;
if (defined $sq) { } else{ $poiHash{$name}= 1;
$poiHash{$name}{$sq} = 1 ; }}
}
else {
$poiHash{$name} = 1 ;
}
}
sub getPoiHash{ return \%poiHash;
sub getPoiHash {
return \%poiHash ;
} }
1; 1;

633
mwMap.pm

File diff suppressed because it is too large Load Diff

484
mwMisc.pm
View File

@ -58,17 +58,11 @@ require Exporter ;
sub getValue { sub getValue{ my($key, $aRef)= @_;
my ($key, $aRef) = @_ ;
my $value = undef; my $value = undef;
foreach my $kv (@$aRef) { foreach my $kv(@$aRef){ if($kv->[0] eq $key){$value = $kv->[1];}} return $value;
if ($kv->[0] eq $key) { $value = $kv->[1]; }
} }
return $value ; sub createLabel{#
}
sub createLabel {
#
# takes @tags and labelKey(s)from style file and creates labelTextTotal and array of labels for directory # takes @tags and labelKey(s)from style file and creates labelTextTotal and array of labels for directory
# takes more keys in one string - using a separator. # takes more keys in one string - using a separator.
# #
@ -86,39 +80,23 @@ sub createLabel {
if(grep /!/, $styleLabelText){# AND if(grep /!/, $styleLabelText){# AND
@keys = split(/!/, $styleLabelText); @keys = split(/!/, $styleLabelText);
# print "par found: $styleLabelText; @keys\n"; # print "par found: $styleLabelText; @keys\n";
for (my $i=0; $i<=$#keys; $i++) { for(my $i=0; $i<=$#keys; $i++){ if($keys[$i] eq "_lat"){push @labels, $lat;}
if ($keys[$i] eq "_lat") { push @labels, $lat ; }
if($keys[$i] eq "_lon"){push @labels, $lon;} if($keys[$i] eq "_lon"){push @labels, $lon;}
foreach my $tag (@tags) { foreach my $tag(@tags){ if($tag->[0] eq $keys[$i]){ push @labels, $tag->[1];
if ($tag->[0] eq $keys[$i]) { } } } $labelTextTotal = "";
push @labels, $tag->[1] ; foreach my $label(@labels){$labelTextTotal .= $label . " ";}} else{# PRIO
}
}
}
$labelTextTotal = "" ;
foreach my $label (@labels) { $labelTextTotal .= $label . " " ; }
}
else { # PRIO
@keys = split(/#/, $styleLabelText); @keys = split(/#/, $styleLabelText);
my $i = 0; my $found = 0; my $i = 0; my $found = 0;
while ( ($i<=$#keys) and ($found == 0) ) { while(($i<=$#keys)and($found == 0)){ if($keys[$i] eq "_lat"){push @labels, $lat; $found = 1; $labelTextTotal = $lat;}
if ($keys[$i] eq "_lat") { push @labels, $lat ; $found = 1 ; $labelTextTotal = $lat ; }
if($keys[$i] eq "_lon"){push @labels, $lon; $found = 1; $labelTextTotal = $lon;} if($keys[$i] eq "_lon"){push @labels, $lon; $found = 1; $labelTextTotal = $lon;}
foreach my $tag (@tags) { foreach my $tag(@tags){ if($tag->[0] eq $keys[$i]){ push @labels, $tag->[1];
if ($tag->[0] eq $keys[$i]) {
push @labels, $tag->[1] ;
$labelTextTotal = $tag->[1]; $labelTextTotal = $tag->[1];
$found = 1; $found = 1;
} } $i++;
} }
} return($labelTextTotal, \@labels);
} }
$i++ ; sub buildRings{#
}
}
return ( $labelTextTotal, \@labels) ;
}
sub buildRings {
#
# accepts ref to array of ways and option if unclosed rings shoulf be returned # accepts ref to array of ways and option if unclosed rings shoulf be returned
# closeOpt == 1 returns only closed rings # closeOpt == 1 returns only closed rings
# #
@ -133,68 +111,44 @@ sub buildRings {
my($memWayNodesRef, $memWayTagsRef)= mwFile::getWayPointers(); my($memWayNodesRef, $memWayTagsRef)= mwFile::getWayPointers();
# print "build rings for @allWays\n"; # print "build rings for @allWays\n";
if (cv('debug') eq "1" ) { print "BR: called.\n" ; } if(cv('debug')eq "1"){print "BR: called.\n";} while(scalar @allWays > 0){ # build new test ring
while ( scalar @allWays > 0) {
# build new test ring
my(@currentWays)=(); my(@currentNodes)=(); my(@currentWays)=(); my(@currentNodes)=();
push @currentWays, $allWays[0]; push @currentWays, $allWays[0];
if (cv('debug') eq "1" ) { print "BR: initial way for next ring id= $allWays[0]\n" ; } if(cv('debug')eq "1"){print "BR: initial way for next ring id= $allWays[0]\n";} push @currentNodes, @{$$memWayNodesRef{$allWays[0]}};
push @currentNodes, @{$$memWayNodesRef{$allWays[0]}} ;
my $startNode = $currentNodes[0]; my $startNode = $currentNodes[0];
my $endNode = $currentNodes[-1]; my $endNode = $currentNodes[-1];
if (cv('debug') eq "1" ) { print "BR: initial start and end node $startNode $endNode\n" ; } if(cv('debug')eq "1"){print "BR: initial start and end node $startNode $endNode\n";} my $closed = 0;
my $closed = 0 ;
shift @allWays; # remove first element shift @allWays; # remove first element
if($startNode == $endNode){$closed = 1;} if($startNode == $endNode){$closed = 1;}
my $success = 1; my $success = 1;
while ( ($closed == 0) and ( (scalar @allWays) > 0) and ($success == 1) ) { while(($closed == 0)and((scalar @allWays)> 0)and($success == 1)){ # try to find new way
# try to find new way if(cv('debug')eq "1"){print "TRY TO FIND NEW WAY\n";} $success = 0;
if (cv('debug') eq "1" ) { print "TRY TO FIND NEW WAY\n" ; } if(cv('debug')eq "1"){print "BR: actual start and end node $startNode $endNode\n";} my $i = 0;
$success = 0 ; while(($i <(scalar @allWays))and($success == 0)){ if(cv('debug')eq "1"){print "BR: testing way $i = $allWays[$i]\n";} if(cv('debug')eq "1"){print "BR: rev in front?\n";} if($$memWayNodesRef{$allWays[$i]}[0] == $startNode){
if (cv('debug') eq "1" ) { print "BR: actual start and end node $startNode $endNode\n" ; }
my $i = 0 ;
while ( ($i < (scalar @allWays) ) and ($success == 0) ) {
if (cv('debug') eq "1" ) { print "BR: testing way $i = $allWays[$i]\n" ; }
if (cv('debug') eq "1" ) { print "BR: rev in front?\n" ; }
if ( $$memWayNodesRef{$allWays[$i]}[0] == $startNode ) {
$success = 1; $success = 1;
# reverse in front # reverse in front
@currentWays =($allWays[$i], @currentWays); @currentWays =($allWays[$i], @currentWays);
@currentNodes =(reverse(@{$$memWayNodesRef{$allWays[$i]}}), @currentNodes); @currentNodes =(reverse(@{$$memWayNodesRef{$allWays[$i]}}), @currentNodes);
splice(@allWays, $i, 1); splice(@allWays, $i, 1);
} } if($success ==0){ if(cv('debug')eq "1"){print "BR: app at end?\n";} if($$memWayNodesRef{$allWays[$i]}[0] == $endNode){
if ($success ==0) {
if (cv('debug') eq "1" ) { print "BR: app at end?\n" ; }
if ( $$memWayNodesRef{$allWays[$i]}[0] == $endNode) {
$success = 1; $success = 1;
# append at end # append at end
@currentWays =(@currentWays, $allWays[$i]); @currentWays =(@currentWays, $allWays[$i]);
@currentNodes =(@currentNodes, @{$$memWayNodesRef{$allWays[$i]}}); @currentNodes =(@currentNodes, @{$$memWayNodesRef{$allWays[$i]}});
splice(@allWays, $i, 1); splice(@allWays, $i, 1);
} } } if($success ==0){ if(cv('debug')eq "1"){print "BR: app in front?\n";} if($$memWayNodesRef{$allWays[$i]}[-1] == $startNode){
}
if ($success ==0) {
if (cv('debug') eq "1" ) { print "BR: app in front?\n" ; }
if ( $$memWayNodesRef{$allWays[$i]}[-1] == $startNode) {
$success = 1; $success = 1;
# append in front # append in front
@currentWays =($allWays[$i], @currentWays); @currentWays =($allWays[$i], @currentWays);
@currentNodes =(@{$$memWayNodesRef{$allWays[$i]}}, @currentNodes); @currentNodes =(@{$$memWayNodesRef{$allWays[$i]}}, @currentNodes);
splice(@allWays, $i, 1); splice(@allWays, $i, 1);
} } } if($success ==0){ if(cv('debug')eq "1"){print "BR: rev at end?\n";} if($$memWayNodesRef{$allWays[$i]}[-1] == $endNode){
}
if ($success ==0) {
if (cv('debug') eq "1" ) { print "BR: rev at end?\n" ; }
if ( $$memWayNodesRef{$allWays[$i]}[-1] == $endNode) {
$success = 1; $success = 1;
# append reverse at the end # append reverse at the end
@currentWays =(@currentWays, $allWays[$i]); @currentWays =(@currentWays, $allWays[$i]);
@currentNodes =(@currentNodes,(reverse(@{$$memWayNodesRef{$allWays[$i]}}))); @currentNodes =(@currentNodes,(reverse(@{$$memWayNodesRef{$allWays[$i]}})));
splice(@allWays, $i, 1); splice(@allWays, $i, 1);
} } } $i++;
}
$i++ ;
}# look for new way that fits }# look for new way that fits
$startNode = $currentNodes[0]; $startNode = $currentNodes[0];
@ -202,34 +156,23 @@ sub buildRings {
if($startNode == $endNode){ if($startNode == $endNode){
$closed = 1; $closed = 1;
if(cv('debug')eq "1"){print "BR: ring now closed\n";} if(cv('debug')eq "1"){print "BR: ring now closed\n";}
} } }# new ring
} # new ring
# examine ring and act # examine ring and act
if ( ($closed == 1) or ($closeOpt == 0) ) { if(($closed == 1)or($closeOpt == 0)){ # eliminate double nodes in @currentNodes
# eliminate double nodes in @currentNodes
my $found = 1; my $found = 1;
while ($found) { while($found){ $found = 0;
$found = 0 ; LABCN: for(my $i=0; $i<$#currentNodes; $i++){ if($currentNodes[$i] == $currentNodes[$i+1]){ $found = 1;
LABCN: for (my $i=0; $i<$#currentNodes; $i++) {
if ($currentNodes[$i] == $currentNodes[$i+1]) {
$found = 1 ;
splice @currentNodes, $i, 1; splice @currentNodes, $i, 1;
last LABCN; last LABCN;
} } } } # add data to return data
}
}
# add data to return data
@{$ringWays[$ringCount]}= @currentWays; @{$ringWays[$ringCount]}= @currentWays;
@{$ringNodes[$ringCount]}= @currentNodes; @{$ringNodes[$ringCount]}= @currentNodes;
$ringCount++; $ringCount++;
} }}
}
return(\@ringWays, \@ringNodes); return(\@ringWays, \@ringNodes);
} }
sub angleMapgen{#
sub angleMapgen {
#
# angle between lines/segments # angle between lines/segments
# #
my($g1x1)= shift; my($g1x1)= shift;
@ -242,39 +185,23 @@ sub angleMapgen {
my($g2y2)= shift; my($g2y2)= shift;
my $g1m; my $g1m;
if ( ($g1x2-$g1x1) != 0 ) { if(($g1x2-$g1x1)!= 0){ $g1m =($g1y2-$g1y1)/($g1x2-$g1x1); # steigungen
$g1m = ($g1y2-$g1y1)/($g1x2-$g1x1) ; # steigungen } else{ $g1m = 999999999;
} }
else {
$g1m = 999999999 ;
}
my $g2m; my $g2m;
if ( ($g2x2-$g2x1) != 0 ) { if(($g2x2-$g2x1)!= 0){ $g2m =($g2y2-$g2y1)/($g2x2-$g2x1);
$g2m = ($g2y2-$g2y1)/($g2x2-$g2x1) ; } else{ $g2m = 999999999;
} }
else {
$g2m = 999999999 ;
}
if($g1m == $g2m){ # parallel if($g1m == $g2m){ # parallel
return(0); return(0);
} } else{ my $t1 = $g1m -$g2m;
else {
my $t1 = $g1m -$g2m ;
my $t2 = 1 + $g1m * $g2m; my $t2 = 1 + $g1m * $g2m;
if ($t2 == 0) { if($t2 == 0){ return 90;
return 90 ; } else{ my $a = atan(abs($t1/$t2))/ 3.141592654 * 180;
}
else {
my $a = atan (abs ($t1/$t2)) / 3.141592654 * 180 ;
return $a; return $a;
} }}}
}
}
sub triangleNode { sub triangleNode{#
#
# get segment of segment as coordinates # get segment of segment as coordinates
# from start or from end of segment # from start or from end of segment
# #
@ -288,18 +215,12 @@ sub triangleNode {
if($startEnd == 0){ if($startEnd == 0){
$x = $x1 +($x2-$x1)*$percent; $x = $x1 +($x2-$x1)*$percent;
$y = $y1 +($y2-$y1)*$percent; $y = $y1 +($y2-$y1)*$percent;
} } else{ $x = $x2 -($x2-$x1)*$percent;
else {
$x = $x2 - ($x2-$x1)*$percent ;
$y = $y2 -($y2-$y1)*$percent; $y = $y2 -($y2-$y1)*$percent;
} return($x, $y);
} }
return ($x, $y) ; sub intersection{#
} # returns intersection point of two lines, else(0,0)#
sub intersection {
#
# returns intersection point of two lines, else (0,0)
#
my($g1x1)= shift; my($g1x1)= shift;
my($g1y1)= shift; my($g1y1)= shift;
my($g1x2)= shift; my($g1x2)= shift;
@ -312,38 +233,25 @@ sub intersection {
if(($g1x1 == $g2x1)and($g1y1 == $g2y1)){# p1 = p1 ? if(($g1x1 == $g2x1)and($g1y1 == $g2y1)){# p1 = p1 ?
return($g1x1, $g1y1); return($g1x1, $g1y1);
} } if(($g1x1 == $g2x2)and($g1y1 == $g2y2)){# p1 = p2 ?
if (($g1x1 == $g2x2) and ($g1y1 == $g2y2)) { # p1 = p2 ?
return($g1x1, $g1y1); return($g1x1, $g1y1);
} } if(($g1x2 == $g2x1)and($g1y2 == $g2y1)){# p2 = p1 ?
if (($g1x2 == $g2x1) and ($g1y2 == $g2y1)) { # p2 = p1 ?
return($g1x2, $g1y2); return($g1x2, $g1y2);
} }
if(($g1x2 == $g2x2)and($g1y2 == $g2y2)){# p2 = p1 ? if(($g1x2 == $g2x2)and($g1y2 == $g2y2)){# p2 = p1 ?
return($g1x2, $g1y2); return($g1x2, $g1y2);
} }
my $g1m; my $g1m;
if ( ($g1x2-$g1x1) != 0 ) { if(($g1x2-$g1x1)!= 0){ $g1m =($g1y2-$g1y1)/($g1x2-$g1x1); # steigungen
$g1m = ($g1y2-$g1y1)/($g1x2-$g1x1) ; # steigungen } else{ $g1m = 999999;
} }
else {
$g1m = 999999 ;
}
my $g2m; my $g2m;
if ( ($g2x2-$g2x1) != 0 ) { if(($g2x2-$g2x1)!= 0){ $g2m =($g2y2-$g2y1)/($g2x2-$g2x1);
$g2m = ($g2y2-$g2y1)/($g2x2-$g2x1) ; } else{ $g2m = 999999;
} }
else {
$g2m = 999999 ;
}
if($g1m == $g2m){ # parallel if($g1m == $g2m){ # parallel
return(0, 0); return(0, 0);
} }
my($g1b)= $g1y1 - $g1m * $g1x1; # abschnitte my($g1b)= $g1y1 - $g1m * $g1x1; # abschnitte
my($g2b)= $g2y1 - $g2m * $g2x1; my($g2b)= $g2y1 - $g2m * $g2x1;
@ -367,17 +275,12 @@ sub intersection {
($sy >= $g1ymin)and ($sy >= $g1ymin)and
($sy >= $g2ymin)and ($sy >= $g2ymin)and
($sy <= $g1ymax)and ($sy <= $g1ymax)and
($sy <= $g2ymax)) { ($sy <= $g2ymax)){ return($sx, $sy);
return ($sx, $sy) ; } else{ return(0, 0);
} }}
else {
return (0, 0) ;
}
}
sub isIn { sub isIn{# checks two polygons
# checks two polygons
# return 0 = neither # return 0 = neither
# 1 = p1 is in p2 # 1 = p1 is in p2
# 2 = p2 is in p1 # 2 = p2 is in p1
@ -387,124 +290,73 @@ sub isIn {
my($p2In1)= 1; my($p2In1)= 1;
# p1 in p2 ? # p1 in p2 ?
foreach my $pt1 ($p1->points) { foreach my $pt1($p1->points){ if($p2->contains($pt1)){ # good
if ($p2->contains ($pt1) ) { } else{ $p1In2 = 0;
# good }}
}
else {
$p1In2 = 0 ;
}
}
# p2 in p1 ? # p2 in p1 ?
foreach my $pt2 ($p2->points) { foreach my $pt2($p2->points){ if($p1->contains($pt2)){ # good
if ($p1->contains ($pt2) ) { } else{ $p2In1 = 0;
# good }}
} if($p1In2 == 1){ return 1;
else { } elsif($p2In1 == 1){ return 2;
$p2In1 = 0 ; } else{ return 0;
} }}
}
if ($p1In2 == 1) {
return 1 ;
}
elsif ($p2In1 == 1) {
return 2 ;
}
else {
return 0 ;
}
}
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
sub processPageNumbers { sub processPageNumbers{ if(cv('pageNumbers')ne ""){ my $pnSize; my $pnColor;
if ( cv('pageNumbers') ne "") {
my $pnSize ; my $pnColor ;
my @a = split /,/, cv('pageNumbers'); my @a = split /,/, cv('pageNumbers');
if (scalar @a >= 3) { if(scalar @a >= 3){ $pnSize = $a[0];
$pnSize = $a[0] ;
$pnColor = $a[1]; $pnColor = $a[1];
my $pnNumber = $a[2]; my $pnNumber = $a[2];
if ($pnNumber != 0) { if($pnNumber != 0){ drawPageNumber($pnSize, $pnColor, $pnNumber);
drawPageNumber ($pnSize, $pnColor, $pnNumber) ; } } if(scalar @a == 7){ # draw 4 other positions if ne 0!!!
}
}
if (scalar @a == 7) {
# draw 4 other positions if ne 0!!!
if($a[3] != 0){# left if($a[3] != 0){# left
drawPageNumberLeft($pnSize, $pnColor, $a[3]); drawPageNumberLeft($pnSize, $pnColor, $a[3]);
} } if($a[4] != 0){# bottom
if ($a[4] != 0) { # bottom
drawPageNumberBottom($pnSize, $pnColor, $a[4]); drawPageNumberBottom($pnSize, $pnColor, $a[4]);
} } if($a[5] != 0){# right
if ($a[5] != 0) { # right
drawPageNumberRight($pnSize, $pnColor, $a[5]); drawPageNumberRight($pnSize, $pnColor, $a[5]);
} } if($a[6] != 0){# top
if ($a[6] != 0) { # top
drawPageNumberTop($pnSize, $pnColor, $a[6]); drawPageNumberTop($pnSize, $pnColor, $a[6]);
} } }}}
} sub drawPageNumber{ my($size, $col, $num)= @_;
}
}
sub drawPageNumber {
my ($size, $col, $num) = @_ ;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $x = $sizeX - 2 * $size; my $x = $sizeX - 2 * $size;
my $y = $sizeY - 2 * $size; my $y = $sizeY - 2 * $size;
my $svgString = "fill=\"$col\" font-size=\"$size\" "; my $svgString = "fill=\"$col\" font-size=\"$size\" ";
mwMap::drawText ($x, $y, 0, $num, $svgString, "text") mwMap::drawText($x, $y, 0, $num, $svgString, "text")}
} sub drawPageNumberLeft{ my($size, $col, $num)= @_;
sub drawPageNumberLeft {
my ($size, $col, $num) = @_ ;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $x = 2 * $size; my $x = 2 * $size;
my $y = $sizeY / 2; my $y = $sizeY / 2;
my $svgString = "fill=\"$col\" font-size=\"$size\" "; my $svgString = "fill=\"$col\" font-size=\"$size\" ";
mwMap::drawText ($x, $y, 0, $num, $svgString, "text") mwMap::drawText($x, $y, 0, $num, $svgString, "text")}
} sub drawPageNumberBottom{ my($size, $col, $num)= @_;
sub drawPageNumberBottom {
my ($size, $col, $num) = @_ ;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $x = $sizeX / 2; my $x = $sizeX / 2;
my $y = $sizeY - 2 * $size; my $y = $sizeY - 2 * $size;
my $svgString = "fill=\"$col\" font-size=\"$size\" "; my $svgString = "fill=\"$col\" font-size=\"$size\" ";
mwMap::drawText ($x, $y, 0, $num, $svgString, "text") mwMap::drawText($x, $y, 0, $num, $svgString, "text")}
} sub drawPageNumberRight{ my($size, $col, $num)= @_;
sub drawPageNumberRight {
my ($size, $col, $num) = @_ ;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $x = $sizeX - 2 * $size; my $x = $sizeX - 2 * $size;
my $y = $sizeY / 2; my $y = $sizeY / 2;
my $svgString = "fill=\"$col\" font-size=\"$size\" "; my $svgString = "fill=\"$col\" font-size=\"$size\" ";
mwMap::drawText ($x, $y, 0, $num, $svgString, "text") mwMap::drawText($x, $y, 0, $num, $svgString, "text")}
} sub drawPageNumberTop{ my($size, $col, $num)= @_;
sub drawPageNumberTop {
my ($size, $col, $num) = @_ ;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $x = $sizeX / 2; my $x = $sizeX / 2;
my $y = 2 * $size; my $y = 2 * $size;
my $svgString = "fill=\"$col\" font-size=\"$size\" "; my $svgString = "fill=\"$col\" font-size=\"$size\" ";
mwMap::drawText ($x, $y, 0, $num, $svgString, "text") mwMap::drawText($x, $y, 0, $num, $svgString, "text")}
}
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
sub processRectangles { sub processRectangles{ my $no = 0;
my $no = 0 ;
if ( cv('rectangles') ne "") { if(cv('rectangles')ne ""){ my @rects;
my @rects ;
@rects = split /#/, cv('rectangles'); @rects = split /#/, cv('rectangles');
foreach my $r (@rects) { foreach my $r(@rects){ $no++;
$no++ ;
my @coords; my @coords;
@coords = split /,/, $r; @coords = split /,/, $r;
@ -525,8 +377,7 @@ sub processRectangles {
drawWay(\@nodes, 0, $svgString, "rectangles", undef); drawWay(\@nodes, 0, $svgString, "rectangles", undef);
# drawRect($left, $bottom, $right, $top, 1, $svgString, "rectangles"); # drawRect($left, $bottom, $right, $top, 1, $svgString, "rectangles");
if ( cv('pagenumbers') ne "") { if(cv('pagenumbers')ne ""){ my $x =($right + $left)/ 2;
my $x = ($right + $left) / 2 ;
my $y =($bottom + $top)/ 2; my $y =($bottom + $top)/ 2;
my $xp; my $yp; my $xp; my $yp;
($xp, $yp)= convert($x, $y); ($xp, $yp)= convert($x, $y);
@ -534,15 +385,10 @@ sub processRectangles {
my $svgString = "fill=\"black\" font-size=\"60\" "; my $svgString = "fill=\"black\" font-size=\"60\" ";
drawText($xp, $yp, 0, $no, $svgString, "rectangles"); drawText($xp, $yp, 0, $no, $svgString, "rectangles");
} }
}}}
}
}
}
# -------------------------------------------------------------------- # --------------------------------------------------------------------
sub sizePNG { sub sizePNG{#
#
# evaluates size of png graphics # evaluates size of png graphics
# #
my $fileName = shift; my $fileName = shift;
@ -550,19 +396,13 @@ sub sizePNG {
my($x, $y); my($x, $y);
my $file; my $file;
my $result = open($file, "<", $fileName); my $result = open($file, "<", $fileName);
if ($result) { if($result){ my $pic = newFromPng GD::Image($file);
my $pic = newFromPng GD::Image($file) ;
($x, $y)= $pic->getBounds; ($x, $y)= $pic->getBounds;
close($file); close($file);
} else{($x, $y)=(0, 0);
} return($x, $y);
} }
else { sub sizeSVG{#
($x, $y) = (0, 0) ;
}
return ($x, $y) ;
}
sub sizeSVG {
#
# evaluates size of svg graphics # evaluates size of svg graphics
# #
my $fileName = shift; my $fileName = shift;
@ -570,65 +410,43 @@ sub sizeSVG {
my($x, $y); undef $x; undef $y; my($x, $y); undef $x; undef $y;
my $result = open($file, "<", $fileName); my $result = open($file, "<", $fileName);
if ($result) { if($result){ my $line;
my $line ; while($line = <$file>){ my($x1)=($line =~ /^.*width=\"([\d]+)px\"/);
while ($line = <$file>) {
my ($x1) = ( $line =~ /^.*width=\"([\d]+)px\"/ ) ;
my($y1)=($line =~ /^.*height=\"([\d]+)px\"/); my($y1)=($line =~ /^.*height=\"([\d]+)px\"/);
if (!defined $x1) { if(!defined $x1){ ($x1)=($line =~ /^\s*width=\"([\d]+)\"/);
($x1) = ( $line =~ /^\s*width=\"([\d]+)\"/ ) ;
} }
if (!defined $y1) { if(!defined $y1){ ($y1)=($line =~ /^\s*height=\"([\d]+)\"/);
($y1) = ( $line =~ /^\s*height=\"([\d]+)\"/ ) ;
} }
if (defined $x1) { $x = $x1 ; } if(defined $x1){$x = $x1;} if(defined $y1){$y = $y1;} } close($file);
if (defined $y1) { $y = $y1 ; }
} }
close ($file) ;
}
if((!defined $x)or(!defined $y)){ if((!defined $x)or(!defined $y)){
$x = 0; $y = 0; $x = 0; $y = 0;
print "WARNING: size of file $fileName could not be determined.\n"; print "WARNING: size of file $fileName could not be determined.\n";
} }
return($x, $y); return($x, $y);
} }
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
sub createDirPdf { sub createDirPdf{ if((cv('dir')eq "1")or(cv('poi')eq "1")){ if(cv('grid')> 0){ my $dirPdfName = cv('out');
if ((cv('dir') eq "1") or (cv('poi') eq "1")) {
if (cv('grid') > 0) {
my $dirPdfName = cv('out') ;
$dirPdfName =~ s/.svg/_dir.pdf/; $dirPdfName =~ s/.svg/_dir.pdf/;
my $sName = "none"; my $sName = "none";
my $pName = "none"; my $pName = "none";
my $prg = cv('dirprg'); my $prg = cv('dirprg');
if (cv('dir') eq "1") { $sName = cv('directoryname') ; } if(cv('dir')eq "1"){$sName = cv('directoryname');} if(cv('poi')eq "1"){$pName = cv('poiname');} my $dirColNum = cv('dircolnum');
if (cv('poi') eq "1") { $pName = cv('poiname') ; }
my $dirColNum = cv ('dircolnum') ;
my $dirTitle = cv('dirtitle'); my $dirTitle = cv('dirtitle');
print "\ncalling perl $prg $sName $pName $dirTitle $dirPdfName $dirColNum\n\n"; print "\ncalling perl $prg $sName $pName $dirTitle $dirPdfName $dirColNum\n\n";
`perl $prg $sName $pName \"$dirTitle\" $dirPdfName $dirColNum > out.txt`; `perl $prg $sName $pName \"$dirTitle\" $dirPdfName $dirColNum > out.txt`;
} else{ print "WARNING: directory PDF will not be created because -grid was not specified\n";
} }
else { } else{ print "WARNING: directory PDF will not be created because neither -dir nor -poi was specified\n";
print "WARNING: directory PDF will not be created because -grid was not specified\n" ; }}
}
}
else {
print "WARNING: directory PDF will not be created because neither -dir nor -poi was specified\n" ;
}
}
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
sub getPointOfWay { sub getPointOfWay{ #
#
# returns point of way at distance/position # returns point of way at distance/position
# coordinates and units are pixels # coordinates and units are pixels
@ -636,18 +454,14 @@ sub getPointOfWay {
my @points = @$ref; my @points = @$ref;
my @double =(); my @double =();
while (scalar @points > 0) { while(scalar @points > 0){ my $x = shift @points;
my $x = shift @points ;
my $y = shift @points; my $y = shift @points;
push @double, [$x, $y]; push @double, [$x, $y];
} }
my $i = 0; my $actLen = 0; my $i = 0; my $actLen = 0;
while ($actLen < $position) { while($actLen < $position){ $actLen += sqrt(($double[$i]->[0]-$double[$i+1]->[0])**2 +($double[$i]->[1]-$double[$i+1]->[1])**2);
$actLen += sqrt ( ($double[$i]->[0]-$double[$i+1]->[0])**2 + ($double[$i]->[1]-$double[$i+1]->[1])**2 ) ;
$i++; $i++;
} }
my $x = int(($double[$i]->[0] + $double[$i-1]->[0])/ 2); my $x = int(($double[$i]->[0] + $double[$i-1]->[0])/ 2);
my $y = int(($double[$i]->[1] + $double[$i-1]->[1])/ 2); my $y = int(($double[$i]->[1] + $double[$i-1]->[1])/ 2);
@ -655,11 +469,9 @@ sub getPointOfWay {
return($x, $y); return($x, $y);
} }
# ---------------------------------------------------------------- # ----------------------------------------------------------------
sub nodes2Coordinates { sub nodes2Coordinates{#
#
# transform list of nodeIds to list of x/y # transform list of nodeIds to list of x/y
# straight array in and out # straight array in and out
# #
@ -670,17 +482,13 @@ sub nodes2Coordinates {
my($lonRef, $latRef)= mwFile::getNodePointers(); my($lonRef, $latRef)= mwFile::getNodePointers();
foreach my $n (@nodes) { foreach my $n(@nodes){ my($x, $y)= mwMap::convert($$lonRef{$n}, $$latRef{$n});
my ($x, $y) = mwMap::convert ( $$lonRef{$n}, $$latRef{$n}) ;
push @result, $x, $y; push @result, $x, $y;
} }
return @result; return @result;
} }
sub areaCenter{#
sub areaCenter {
#
# calculate center of area by averageing lons/lats. could be smarter because result could be outside of area! TODO # calculate center of area by averageing lons/lats. could be smarter because result could be outside of area! TODO
# #
my $ref = shift; my $ref = shift;
@ -694,20 +502,16 @@ sub areaCenter {
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
foreach my $n (@nodes) { foreach my $n(@nodes){ $x += $$lonRef{$n};
$x += $$lonRef{$n} ;
$y += $$latRef{$n}; $y += $$latRef{$n};
$num++; $num++;
} } $x = $x / $num;
$x = $x / $num ;
$y = $y / $num; $y = $y / $num;
return($x, $y); return($x, $y);
} }
sub areaSize{ my $ref = shift; # nodes
sub areaSize {
my $ref = shift ; # nodes
my @nodes = @$ref; my @nodes = @$ref;
# print "SIZE: @nodes\n"; # print "SIZE: @nodes\n";
@ -715,86 +519,54 @@ sub areaSize {
my($lonRef, $latRef)= mwFile::getNodePointers(); my($lonRef, $latRef)= mwFile::getNodePointers();
my @poly =(); my @poly =();
foreach my $node ( @nodes ) { foreach my $node(@nodes){ my($x, $y)= mwMap::convert($$lonRef{$node}, $$latRef{$node});
my ($x, $y) = mwMap::convert ($$lonRef{$node}, $$latRef{$node}) ;
push @poly, [$x, $y]; push @poly, [$x, $y];
} } my($p)= Math::Polygon->new(@poly);
my ($p) = Math::Polygon->new(@poly) ;
my $size = $p->area; my $size = $p->area;
return $size; return $size;
} }
# --------------------------------------------------------------- # ---------------------------------------------------------------
sub createTextSVG { sub createTextSVG{ my($fontFamily, $font, $bold, $italic, $size, $color, $strokeWidth, $strokeColor)= @_;
my ($fontFamily, $font, $bold, $italic, $size, $color, $strokeWidth, $strokeColor) = @_ ;
my $svg = ""; my $svg = "";
if ( (defined $font) and ( $font ne "") ) { if((defined $font)and($font ne "")){ $svg .= "font=\"$font\" ";
$svg .= "font=\"$font\" " ; } if((defined $fontFamily)and($fontFamily ne "")){ $svg .= "font-family=\"$fontFamily\" ";
} }
if ( (defined $fontFamily) and ( $fontFamily ne "") ) { if((defined $bold)and(lc($bold)eq "yes")){ $svg .= "font-weight=\"bold\" ";
$svg .= "font-family=\"$fontFamily\" " ; } if((defined $italic)and(lc($italic)eq "yes")){ $svg .= "font-style=\"italic\" ";
} }
if((defined $size)and($size ne "")){ $svg .= "font-size=\"$size\" ";
if ( (defined $bold) and ( lc ($bold) eq "yes") ) { } if((defined $color)and($color ne "")){ $svg .= "fill=\"$color\" ";
$svg .= "font-weight=\"bold\" " ;
} }
if ( (defined $italic) and ( lc ($italic) eq "yes") ) { if((defined $strokeColor)and($strokeColor ne "")){ $svg .= "stroke=\"$strokeColor\" ";
$svg .= "font-style=\"italic\" " ; } if((defined $strokeWidth)and($strokeWidth ne "")){ $svg .= "stroke-width=\"$strokeWidth\" ";
} }
if ( (defined $size) and ( $size ne "") ) {
$svg .= "font-size=\"$size\" " ;
}
if ( (defined $color) and ( $color ne "") ) {
$svg .= "fill=\"$color\" " ;
}
if ( (defined $strokeColor) and ( $strokeColor ne "") ) {
$svg .= "stroke=\"$strokeColor\" " ;
}
if ( (defined $strokeWidth) and ( $strokeWidth ne "") ) {
$svg .= "stroke-width=\"$strokeWidth\" " ;
}
return $svg; return $svg;
} }
# -------------------------------------------------------------------- # --------------------------------------------------------------------
sub wayVisible { sub wayVisible{ my $ref = shift;
my $ref = shift ;
my @points = @$ref; my @points = @$ref;
my($sizeX, $sizeY)= mwMap::getDimensions(); my($sizeX, $sizeY)= mwMap::getDimensions();
my $result = 0; my $result = 0;
for (my $i = 0; $i < $#points; $i += 2) { for(my $i = 0; $i < $#points; $i += 2){ my $x = $points[$i];
my $x = $points[$i] ;
my $y = $points[$i+1]; my $y = $points[$i+1];
if ( ( $x >= 0 ) and ( $y >= 0 ) and ( $x <= $sizeX ) and ( $y <= $sizeY ) ) { if(($x >= 0)and($y >= 0)and($x <= $sizeX)and($y <= $sizeY)){ $result = 1;
$result = 1 ; }} return $result;
} }
}
return $result ;
}
# -------------------------------------------------------------------- # --------------------------------------------------------------------
sub labelTransform { sub labelTransform{ my($label, $cmd)= @_;
my ($label, $cmd) = @_ ; if($cmd ne ""){ eval $cmd;
if ($cmd ne "") { if($@){print "ERROR processing label '$label' with command: '$cmd'\nERROR: $@\n";}} return $label;
eval $cmd ;
if ($@) { print "ERROR processing label '$label' with command: '$cmd'\nERROR: $@\n" ; }
} }
return $label ;
}
1; 1;

View File

@ -52,8 +52,7 @@ my %wayUsed = () ;
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
sub processMultipolygons { sub processMultipolygons{ my $notDrawnMP = 0;
my $notDrawnMP = 0 ;
my $mp = 0; my $mp = 0;
my $mpLabels = 0; my $mpLabels = 0;
my $mpNotDrawnLabels = 0; my $mpNotDrawnLabels = 0;
@ -62,47 +61,33 @@ sub processMultipolygons {
preprocessMultipolygons(); preprocessMultipolygons();
foreach my $multiId(keys %multiTags){ foreach my $multiId(keys %multiTags){
my $ruleRef = getAreaRule(\@{$multiTags{$multiId}}); my $ruleRef = getAreaRule(\@{$multiTags{$multiId}});
if(defined $ruleRef){ if(defined $ruleRef){
my $svgText = ""; my $svgText = "";
my $icon = ""; my $icon = "";
if ($$ruleRef{'icon'} ne "none") { if($$ruleRef{'icon'}ne "none"){ $icon = $$ruleRef{'icon'};
$icon = $$ruleRef{'icon'} ; } else{ my $col = $$ruleRef{'color'};
}
else {
my $col = $$ruleRef{'color'} ;
$svgText = "fill=\"$col\" "; $svgText = "fill=\"$col\" ";
} }
my $ref = $multiPaths{$multiId}[0]; # first, outer way my $ref = $multiPaths{$multiId}[0]; # first, outer way
my $size = areaSize($ref); my $size = areaSize($ref);
if ($size >= cv('minareasize') ) { if($size >= cv('minareasize')){ drawArea($svgText, $icon, $multiPaths{$multiId}, 1, "multi");
drawArea ($svgText, $icon, $multiPaths{$multiId}, 1, "multi") ;
$mp++; $mp++;
# LABELS # LABELS
my $name = ""; my $ref1; my $name = ""; my $ref1;
if ( cv('ignorelabels') eq "0" ) { if(cv('ignorelabels')eq "0"){ ($name, $ref1)= createLabel($multiTags{$multiId}, $$ruleRef{'label'}, 0, 0);
($name, $ref1) = createLabel ( $multiTags{$multiId}, $$ruleRef{'label'}, 0, 0) ;
if(($$ruleRef{'label'}ne "none")and if(($$ruleRef{'label'}ne "none")and
(cv('nolabel')eq "1")and (cv('nolabel')eq "1")and
($name eq "") ) ($name eq "")) {
{
$name = "NO LABEL"; $name = "NO LABEL";
} } }
} if($name ne ""){ if($size >= cv('minarealabelsize')){ $mpLabels++;
if ($name ne "") {
if ($size >= cv('minarealabelsize') ) {
$mpLabels++ ;
if(cv('debug')eq "1"){print "MP LABEL: $name, size: $$ruleRef{'labelsize'}, color: $$ruleRef{'labelcolor'}\n";} if(cv('debug')eq "1"){print "MP LABEL: $name, size: $$ruleRef{'labelsize'}, color: $$ruleRef{'labelcolor'}\n";}
my($x, $y)= areaCenter($multiPaths{$multiId}[0]); my($x, $y)= areaCenter($multiPaths{$multiId}[0]);
@ -123,104 +108,57 @@ sub processMultipolygons {
# $svgText = createTextSVG(undef, undef, $$ruleRef{'labelsize'}, $$ruleRef{'labelcolor'}, undef, undef); # $svgText = createTextSVG(undef, undef, $$ruleRef{'labelsize'}, $$ruleRef{'labelcolor'}, undef, undef);
if (cv('debug') eq "1") { print "MP LABEL: svg: \"$svgText\"\n" ; } if(cv('debug')eq "1"){print "MP LABEL: svg: \"$svgText\"\n";} placeLabelAndIcon($x, $y, 1, 0, $name, $svgText, "none", 0, 0, "arealabels");
placeLabelAndIcon ($x, $y, 1, 0, $name, $svgText, "none", 0, 0, "arealabels") ;
}# if size }# if size
else { else{ $mpNotDrawnLabels++;
$mpNotDrawnLabels++ ; } } else{
} } else{ $notDrawnMP++;
} }
}
else {
}
}
else {
$notDrawnMP++ ;
}
}# if rule }# if rule
}# foreach multi }# foreach multi
print "$mp multipolygon areas drawn, $notDrawnMP not drawn because they were too small.\n"; print "$mp multipolygon areas drawn, $notDrawnMP not drawn because they were too small.\n";
print "$mpLabels multipolygon labels drawn, $mpNotDrawnLabels not drawn because belonging areas were too small.\n"; print "$mpLabels multipolygon labels drawn, $mpNotDrawnLabels not drawn because belonging areas were too small.\n";
} }
# ------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------
sub preprocessMultipolygons { sub preprocessMultipolygons{#
#
# preprecess all multipolygons # preprecess all multipolygons
# #
my($wayNodesRef, $wayTagsRef)= getWayPointers(); my($wayNodesRef, $wayTagsRef)= getWayPointers();
my($relationMembersRef, $relationTagsRef)= getRelationPointers(); my($relationMembersRef, $relationTagsRef)= getRelationPointers();
foreach my $relId (keys %$relationMembersRef) { foreach my $relId(keys %$relationMembersRef){ my $isMulti = 0;
my $isMulti = 0 ; foreach my $tag(@{$$relationTagsRef{$relId}}){ if(($tag->[0] eq "type")and($tag->[1] eq "multipolygon")){$isMulti = 1;} }
foreach my $tag (@{$$relationTagsRef{$relId}}) { if($isMulti){ if(cv('debug')eq "1"){print "\n---------------------------------------------------\n";} if(cv('debug')eq "1"){print "\nRelation $relId is multipolygon!\n";}
if ( ($tag->[0] eq "type") and ($tag->[1] eq "multipolygon") ) { $isMulti = 1 ; }
}
if ($isMulti) {
if (cv('debug') eq "1") { print "\n---------------------------------------------------\n" ; }
if (cv('debug') eq "1") { print "\nRelation $relId is multipolygon!\n" ; }
# get inner and outer ways # get inner and outer ways
my(@innerWays)=(); my(@outerWays)=(); my(@innerWays)=(); my(@outerWays)=();
foreach my $member ( @{$$relationMembersRef{$relId}} ) { foreach my $member(@{$$relationMembersRef{$relId}}){ if(($member->[0] eq "way")and($member->[2] eq "outer")and(defined @{$$wayNodesRef{$member->[1]}})){push @outerWays, $member->[1];} if(($member->[0] eq "way")and($member->[2] eq "inner")and(defined @{$$wayNodesRef{$member->[1]}})){push @innerWays, $member->[1];} } if(cv('debug')eq "1"){print "OUTER WAYS: @outerWays\n";} if(cv('debug')eq "1"){print "INNER WAYS: @innerWays\n";}
if ( ($member->[0] eq "way") and ($member->[2] eq "outer") and (defined @{$$wayNodesRef{$member->[1]}} ) ) { push @outerWays, $member->[1] ; }
if ( ($member->[0] eq "way") and ($member->[2] eq "inner") and (defined @{$$wayNodesRef{$member->[1]}} )) { push @innerWays, $member->[1] ; }
}
if (cv('debug') eq "1") { print "OUTER WAYS: @outerWays\n" ; }
if (cv('debug') eq "1") { print "INNER WAYS: @innerWays\n" ; }
my($ringsWaysRef, $ringsNodesRef); my($ringsWaysRef, $ringsNodesRef);
my @ringWaysInner =(); my @ringNodesInner =(); my @ringTagsInner =(); my @ringWaysInner =(); my @ringNodesInner =(); my @ringTagsInner =();
# build rings inner # build rings inner
if (scalar @innerWays > 0) { if(scalar @innerWays > 0){ ($ringsWaysRef, $ringsNodesRef)= buildRings(\@innerWays, 1);
($ringsWaysRef, $ringsNodesRef) = buildRings (\@innerWays, 1) ;
@ringWaysInner = @$ringsWaysRef; @ringWaysInner = @$ringsWaysRef;
@ringNodesInner = @$ringsNodesRef; @ringNodesInner = @$ringsNodesRef;
for (my $ring=0; $ring<=$#ringWaysInner; $ring++) { for(my $ring=0; $ring<=$#ringWaysInner; $ring++){ if(cv('debug')eq "1"){print "INNER RING $ring: @{$ringWaysInner[$ring]}\n";} my $firstWay = $ringWaysInner[$ring]->[0];
if (cv('debug') eq "1") { print "INNER RING $ring: @{$ringWaysInner[$ring]}\n" ; }
my $firstWay = $ringWaysInner[$ring]->[0] ;
if(scalar @{$ringWaysInner[$ring]}== 1){$wayUsed{$firstWay}= 1;}# way will be marked as used/drawn by multipolygon if(scalar @{$ringWaysInner[$ring]}== 1){$wayUsed{$firstWay}= 1;}# way will be marked as used/drawn by multipolygon
@{$ringTagsInner[$ring]}= @{$$wayTagsRef{$firstWay}}; # ring will be tagged like first contained way @{$ringTagsInner[$ring]}= @{$$wayTagsRef{$firstWay}}; # ring will be tagged like first contained way
if (cv('debug') eq "1") { if(cv('debug')eq "1"){ print "tags from first way...\n";
print "tags from first way...\n" ; foreach my $tag(@{$$wayTagsRef{$firstWay}}){ print " $tag->[0] - $tag->[1]\n";
foreach my $tag (@{$$wayTagsRef{$firstWay}}) { } } if((scalar @{$$wayTagsRef{$firstWay}})== 0){ if(cv('debug')eq "1"){print "tags set to hole in mp.\n";} push @{$ringTagsInner[$ring]}, ["multihole", "yes"];
print " $tag->[0] - $tag->[1]\n" ; } } }
}
}
if ( (scalar @{$$wayTagsRef{$firstWay}}) == 0 ) {
if (cv('debug') eq "1") { print "tags set to hole in mp.\n" ; }
push @{$ringTagsInner[$ring]}, ["multihole", "yes"] ;
}
}
}
# build rings outer # build rings outer
my @ringWaysOuter =(); my @ringNodesOuter =(); my @ringTagsOuter =(); my @ringWaysOuter =(); my @ringNodesOuter =(); my @ringTagsOuter =();
if (scalar @outerWays > 0) { if(scalar @outerWays > 0){ ($ringsWaysRef, $ringsNodesRef)= buildRings(\@outerWays, 1);
($ringsWaysRef, $ringsNodesRef) = buildRings (\@outerWays, 1) ;
@ringWaysOuter = @$ringsWaysRef; # not necessary for outer @ringWaysOuter = @$ringsWaysRef; # not necessary for outer
@ringNodesOuter = @$ringsNodesRef; @ringNodesOuter = @$ringsNodesRef;
for (my $ring=0; $ring<=$#ringWaysOuter; $ring++) { for(my $ring=0; $ring<=$#ringWaysOuter; $ring++){ if(cv('debug')eq "1"){print "OUTER RING $ring: @{$ringWaysOuter[$ring]}\n";} my $firstWay = $ringWaysOuter[$ring]->[0];
if (cv('debug') eq "1") { print "OUTER RING $ring: @{$ringWaysOuter[$ring]}\n" ; } if(scalar @{$ringWaysOuter[$ring]}== 1){$wayUsed{$firstWay}= 1;} @{$ringTagsOuter[$ring]}= @{$$relationTagsRef{$relId}}; # tags from relation
my $firstWay = $ringWaysOuter[$ring]->[0] ; if(cv('debug')eq "1"){ print "tags from relation...\n";
if (scalar @{$ringWaysOuter[$ring]} == 1) {$wayUsed{$firstWay} = 1 ; } foreach my $tag(@{$$relationTagsRef{$relId}}){ print " $tag->[0] - $tag->[1]\n";
@{$ringTagsOuter[$ring]} = @{$$relationTagsRef{$relId}} ; # tags from relation } } if(scalar @{$$relationTagsRef{$relId}}== 1){ @{$ringTagsOuter[$ring]}= @{$$wayTagsRef{$firstWay}}; # ring will be tagged like first way
if (cv('debug') eq "1") { } } }# outer
print "tags from relation...\n" ;
foreach my $tag (@{$$relationTagsRef{$relId}}) {
print " $tag->[0] - $tag->[1]\n" ;
}
}
if (scalar @{$$relationTagsRef{$relId}} == 1) {
@{$ringTagsOuter[$ring]} = @{$$wayTagsRef{$firstWay}} ; # ring will be tagged like first way
}
}
} # outer
my @ringNodesTotal =(@ringNodesInner, @ringNodesOuter); my @ringNodesTotal =(@ringNodesInner, @ringNodesOuter);
my @ringWaysTotal =(@ringWaysInner, @ringWaysOuter); my @ringWaysTotal =(@ringWaysInner, @ringWaysOuter);
@ -231,11 +169,9 @@ sub preprocessMultipolygons {
}# relIds }# relIds
} }
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
sub processRings { sub processRings{#
#
# process rings of multipolygons and create path data for svg # process rings of multipolygons and create path data for svg
# #
my($ref1, $ref2, $ref3)= @_; my($ref1, $ref2, $ref3)= @_;
@ -254,145 +190,82 @@ sub processRings {
my($wayNodesRef, $wayTagsRef)= getWayPointers(); my($wayNodesRef, $wayTagsRef)= getWayPointers();
# create polygons # create polygons
if (cv('debug') eq "1") { print "CREATING POLYGONS\n" ; } if(cv('debug')eq "1"){print "CREATING POLYGONS\n";} for(my $ring = 0; $ring <= $#ringWays; $ring++){ my @poly =();
for (my $ring = 0 ; $ring <= $#ringWays; $ring++) { foreach my $node(@{$ringNodes[$ring]}){ push @poly, [$$lonRef{$node}, $$latRef{$node}];
my @poly = () ; } my($p)= Math::Polygon->new(@poly);
foreach my $node ( @{$ringNodes[$ring]} ) {
push @poly, [$$lonRef{$node}, $$latRef{$node}] ;
}
my ($p) = Math::Polygon->new(@poly) ;
$polygon[$ring] = $p; $polygon[$ring] = $p;
$polygonSize[$ring] = $p->area; $polygonSize[$ring] = $p->area;
if(cv('debug')eq "1"){ if(cv('debug')eq "1"){
print " POLYGON $ring - created, size = $polygonSize[$ring] \n"; print " POLYGON $ring - created, size = $polygonSize[$ring] \n";
foreach my $tag (@{$ringTags[$ring]}) { foreach my $tag(@{$ringTags[$ring]}){ print " $tag->[0] - $tag->[1]\n";
print " $tag->[0] - $tag->[1]\n" ; } }}
}
}
}
# create is_in list(unsorted)for each ring # create is_in list(unsorted)for each ring
if (cv('debug') eq "1") { print "CALC isIn\n" ; } if(cv('debug')eq "1"){print "CALC isIn\n";} for(my $ring1=0; $ring1<=$#polygon; $ring1++){ my $res = 0;
for (my $ring1=0 ; $ring1<=$#polygon; $ring1++) { for(my $ring2=0; $ring2<=$#polygon; $ring2++){ if($ring1 < $ring2){ $res = isIn($polygon[$ring1], $polygon[$ring2]);
my $res = 0 ;
for (my $ring2=0 ; $ring2<=$#polygon; $ring2++) {
if ($ring1 < $ring2) {
$res = isIn ($polygon[$ring1], $polygon[$ring2]) ;
if($res == 1){ if($res == 1){
push @{$ringIsIn[$ring1]}, $ring2; push @{$ringIsIn[$ring1]}, $ring2;
if (cv('debug') eq "1") { print " $ring1 isIn $ring2\n" ; } if(cv('debug')eq "1"){print " $ring1 isIn $ring2\n";} }
}
if($res == 2){ if($res == 2){
push @{$ringIsIn[$ring2]}, $ring1; push @{$ringIsIn[$ring2]}, $ring1;
if (cv('debug') eq "1") { print " $ring2 isIn $ring1\n" ; } if(cv('debug')eq "1"){print " $ring2 isIn $ring1\n";} }
} }} if(cv('debug')eq "1"){ print "IS IN LIST\n";
for(my $ring1=0; $ring1<=$#ringNodes; $ring1++){ if(defined @{$ringIsIn[$ring1]}){ print " ring $ring1 isIn - @{$ringIsIn[$ring1]}\n";
} } print "\n";
} }
}
}
}
if (cv('debug') eq "1") {
print "IS IN LIST\n" ;
for (my $ring1=0 ; $ring1<=$#ringNodes; $ring1++) {
if (defined @{$ringIsIn[$ring1]}) {
print " ring $ring1 isIn - @{$ringIsIn[$ring1]}\n" ;
}
}
print "\n" ;
}
# sort is_in list, biggest first # sort is_in list, biggest first
if (cv('debug') eq "1") { print "SORTING isIn\n" ; } if(cv('debug')eq "1"){print "SORTING isIn\n";} for(my $ring=0; $ring<=$#ringIsIn; $ring++){ my @isIn =();
for (my $ring=0 ; $ring<=$#ringIsIn; $ring++) { foreach my $ring2(@{$ringIsIn[$ring]}){ push @isIn, [$ring2, $polygonSize[$ring2]];
my @isIn = () ; } @isIn = sort{$a->[1] <=> $b->[1]}(@isIn); # sorted array
foreach my $ring2 (@{$ringIsIn[$ring]}) {
push @isIn, [$ring2, $polygonSize[$ring2]] ;
}
@isIn = sort { $a->[1] <=> $b->[1] } (@isIn) ; # sorted array
my @isIn2 =(); # only ring numbers my @isIn2 =(); # only ring numbers
foreach my $temp (@isIn) { foreach my $temp(@isIn){ push @isIn2, $temp->[0];
push @isIn2, $temp->[0] ; } @{$stack[$ring]}= reverse(@isIn2);
}
@{$stack[$ring]} = reverse (@isIn2) ;
push @{$stack[$ring]}, $ring; # sorted descending and ring self appended push @{$stack[$ring]}, $ring; # sorted descending and ring self appended
if (cv('debug') eq "1") { print " stack ring $ring sorted: @{$stack[$ring]}\n" ; } if(cv('debug')eq "1"){print " stack ring $ring sorted: @{$stack[$ring]}\n";}}
}
# find tops and select stacks # find tops and select stacks
if (cv('debug') eq "1") { print "SELECTING STACKS\n" ; } if(cv('debug')eq "1"){print "SELECTING STACKS\n";} my $actualStack = 0;
my $actualStack = 0 ; for(my $stackNumber=0; $stackNumber<=$#stack; $stackNumber++){ # look for top element
for (my $stackNumber=0 ; $stackNumber<=$#stack; $stackNumber++) {
# look for top element
my $topElement = $stack[$stackNumber]->[(scalar @{$stack[$stackNumber]}- 1)]; my $topElement = $stack[$stackNumber]->[(scalar @{$stack[$stackNumber]}- 1)];
my $found = 0; my $found = 0;
for (my $stackNumber2=0 ; $stackNumber2<=$#stack; $stackNumber2++) { for(my $stackNumber2=0; $stackNumber2<=$#stack; $stackNumber2++){ if($stackNumber != $stackNumber2){ foreach my $ring(@{$stack[$stackNumber2]}){ if($ring == $topElement){
if ($stackNumber != $stackNumber2) {
foreach my $ring (@{$stack[$stackNumber2]}) {
if ($ring == $topElement) {
$found = 1; $found = 1;
if (cv('debug') eq "1") { print " element also found in stack $stackNumber2\n" ; } if(cv('debug')eq "1"){print " element also found in stack $stackNumber2\n";} } } } }
} if($found == 0){ @{$selectedStacks{$actualStack}}= @{$stack[$stackNumber]};
}
}
}
if ($found == 0) {
@{$selectedStacks{$actualStack}} = @{$stack[$stackNumber]} ;
$actualStack++; $actualStack++;
if (cv('debug') eq "1") { print " stack $stackNumber has been selected.\n" ; } if(cv('debug')eq "1"){print " stack $stackNumber has been selected.\n";} }
} }
}
# process selected stacks # process selected stacks
if (cv('debug') eq "1") { print "PROCESS SELECTED STACKS\n" ; } if(cv('debug')eq "1"){print "PROCESS SELECTED STACKS\n";} # while stacks left
# while stacks left while(scalar(keys %selectedStacks)> 0){ my(@k)= keys %selectedStacks;
while (scalar (keys %selectedStacks) > 0) { if(cv('debug')eq "1"){print " stacks available: @k\n";} my @nodes =();
my (@k) = keys %selectedStacks ;
if (cv('debug') eq "1") { print " stacks available: @k\n" ; }
my @nodes = () ;
my @nodesOld; my @nodesOld;
my @processedStacks =(); my @processedStacks =();
# select one bottom element # select one bottom element
my $key = $k[0]; # key of first stack my $key = $k[0]; # key of first stack
if (cv('debug') eq "1") { print " stack nr $key selected\n" ; } if(cv('debug')eq "1"){print " stack nr $key selected\n";} my $ringToDraw = $selectedStacks{$key}[0];
my $ringToDraw = $selectedStacks{$key}[0] ;
if(cv('debug')eq "1"){print " ring to draw: $ringToDraw\n";} if(cv('debug')eq "1"){print " ring to draw: $ringToDraw\n";}
push @nodesOld, @{$ringNodes[$ringToDraw]}; # outer polygon push @nodesOld, @{$ringNodes[$ringToDraw]}; # outer polygon
push @nodes, [@{$ringNodes[$ringToDraw]}]; # outer polygon as array push @nodes, [@{$ringNodes[$ringToDraw]}]; # outer polygon as array
# and remove ring from stacks; store processed stacks # and remove ring from stacks; store processed stacks
foreach my $k2 (keys %selectedStacks) { foreach my $k2(keys %selectedStacks){ if($selectedStacks{$k2}[0] == $ringToDraw){
if ($selectedStacks{$k2}[0] == $ringToDraw) {
shift(@{$selectedStacks{$k2}}); shift(@{$selectedStacks{$k2}});
push @processedStacks, $k2; push @processedStacks, $k2;
if (scalar @{$selectedStacks{$k2}} == 0) { delete $selectedStacks{$k2} ; } if(scalar @{$selectedStacks{$k2}}== 0){delete $selectedStacks{$k2};} if(cv('debug')eq "1"){print " removed $ringToDraw from stack $k2\n";} }
if (cv('debug') eq "1") { print " removed $ringToDraw from stack $k2\n" ; }
} }
}
# foreach stack in processed stacks # foreach stack in processed stacks
foreach my $k (@processedStacks) { foreach my $k(@processedStacks){ # if now bottom of a stack is hole, then add this polygon to points
# if now bottom of a stack is hole, then add this polygon to points if(defined $selectedStacks{$k}){ my $tempRing = $selectedStacks{$k}[0];
if (defined $selectedStacks{$k}) {
my $tempRing = $selectedStacks{$k}[0] ;
my $temp = $ringTags[$tempRing]->[0]->[0]; my $temp = $ringTags[$tempRing]->[0]->[0];
if (cv('debug') eq "1") { print " testing for hole: stack $k, ring $tempRing, tag $temp\n" ; } if(cv('debug')eq "1"){print " testing for hole: stack $k, ring $tempRing, tag $temp\n";} if($ringTags[$tempRing]->[0]->[0] eq "multihole"){ push @nodesOld, @{$ringNodes[$tempRing]};
if ($ringTags[$tempRing]->[0]->[0] eq "multihole") {
push @nodesOld, @{$ringNodes[$tempRing]} ;
push @nodes, [@{$ringNodes[$tempRing]}]; push @nodes, [@{$ringNodes[$tempRing]}];
# print " nodes so far: @nodes\n"; # print " nodes so far: @nodes\n";
# and remove this element from stack # and remove this element from stack
shift @{$selectedStacks{$k}}; shift @{$selectedStacks{$k}};
if (scalar @{$selectedStacks{$k}} == 0) { delete $selectedStacks{$k} ; } if(scalar @{$selectedStacks{$k}}== 0){delete $selectedStacks{$k};} if(cv('debug')eq "1"){print " ring $tempRing identified as hole\n";} } } }
if (cv('debug') eq "1") { print " ring $tempRing identified as hole\n" ; }
}
}
}
# add way # add way
@{$multiNodes{$newId}}= @nodesOld; @{$multiNodes{$newId}}= @nodesOld;
@ -404,16 +277,11 @@ sub processRings {
if(cv('debug')eq "1"){ if(cv('debug')eq "1"){
print " DRAWN: $ringToDraw, wayId $newId\n"; print " DRAWN: $ringToDraw, wayId $newId\n";
foreach my $tag (@{$ringTags[$ringToDraw]}) { foreach my $tag(@{$ringTags[$ringToDraw]}){ print " k/v $tag->[0] - $tag->[1]\n";
print " k/v $tag->[0] - $tag->[1]\n" ; } }
}
}
$newId++; $newId++;
} # (while) }#(while)}
}
1; 1;

View File

@ -42,67 +42,37 @@ require Exporter ;
sub processNodes{ sub processNodes{
print "drawing nodes...\n"; print "drawing nodes...\n";
my $lonRef; my $latRef; my $tagRef; my $lonRef; my $latRef; my $tagRef;
($lonRef, $latRef, $tagRef)= getNodePointers(); ($lonRef, $latRef, $tagRef)= getNodePointers();
foreach my $nodeId (keys %$lonRef) { foreach my $nodeId(keys %$lonRef){ my @tags = @{$$tagRef{$nodeId}};
my @tags = @{ $$tagRef{$nodeId} } ;
my $tagsString = ""; my $tagsString = "";
my $ruleRef = getNodeRule(\@tags); my $ruleRef = getNodeRule(\@tags);
if(defined $ruleRef){ if(defined $ruleRef){
# draw disc first ! # draw disc first !
if (grep /yes/, $$ruleRef{'disc'}) { if(grep /yes/, $$ruleRef{'disc'}){ my $svgString = "";
my $svgString = "" ; if($$ruleRef{'discsvgstring'}ne ""){ $svgString = $$ruleRef{'discsvgstring'};
if ( $$ruleRef{'discsvgstring'} ne "" ) { } else{ $svgString = "fill=\"$$ruleRef{'disccolor'}\" stroke=\"none\" fill-opacity=\"$$ruleRef{'discopacity'}\"";
$svgString = $$ruleRef{'discsvgstring'} ; } drawCircle($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'discradius'}, 1, $svgString, 'nodes');
} }
else { if(grep /yes/, $$ruleRef{'circle'}){ my $svgString = "";
$svgString = "fill=\"$$ruleRef{'disccolor'}\" stroke=\"none\" fill-opacity=\"$$ruleRef{'discopacity'}\"" ; if($$ruleRef{'circlesvgstring'}ne ""){ $svgString = $$ruleRef{'circlesvgstring'};
} else{ $svgString = "fill=\"none\" stroke=\"$$ruleRef{'circlecolor'}\" stroke-width=\"$$ruleRef{'circlethickness'}\"";
} drawCircle($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'circleradius'}, 1, $svgString, 'nodes');
} }
drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'discradius'}, 1, $svgString, 'nodes') ; if(($$ruleRef{'size'}> 0)and($$ruleRef{'icon'}eq "none")){ my $svgString = "";
if($$ruleRef{'svgstring'}ne ""){ $svgString = $$ruleRef{'svgstring'};
} else{ $svgString = "fill=\"$$ruleRef{'color'}\"";
} }
if($$ruleRef{'shape'}eq "circle"){ drawCircle($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes');
if (grep /yes/, $$ruleRef{'circle'}) { } elsif($$ruleRef{'shape'}eq "square"){ drawSquare($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes');
my $svgString = "" ; } elsif($$ruleRef{'shape'}eq "triangle"){ drawTriangle($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes');
if ( $$ruleRef{'circlesvgstring'} ne "" ) { } elsif($$ruleRef{'shape'}eq "diamond"){ drawDiamond($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes');
$svgString = $$ruleRef{'circlesvgstring'} ; } }
} if(($$ruleRef{'label'}ne "none")or($$ruleRef{'icon'}ne "none")){ my($labelText, $ref)= createLabel(\@tags, $$ruleRef{'label'}, $$lonRef{$nodeId}, $$latRef{$nodeId});
else {
$svgString = "fill=\"none\" stroke=\"$$ruleRef{'circlecolor'}\" stroke-width=\"$$ruleRef{'circlethickness'}\"" ;
}
drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'circleradius'}, 1, $svgString, 'nodes') ;
}
if ( ($$ruleRef{'size'} > 0) and ($$ruleRef{'icon'} eq "none") ) {
my $svgString = "" ;
if ( $$ruleRef{'svgstring'} ne "" ) {
$svgString = $$ruleRef{'svgstring'} ;
}
else {
$svgString = "fill=\"$$ruleRef{'color'}\"" ;
}
if ( $$ruleRef{'shape'} eq "circle") {
drawCircle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ;
}
elsif ( $$ruleRef{'shape'} eq "square") {
drawSquare ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ;
}
elsif ( $$ruleRef{'shape'} eq "triangle") {
drawTriangle ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ;
}
elsif ( $$ruleRef{'shape'} eq "diamond") {
drawDiamond ($$lonRef{$nodeId}, $$latRef{$nodeId}, 1, $$ruleRef{'size'}, 0, $svgString, 'nodes') ;
}
}
if ( ($$ruleRef{'label'} ne "none") or ($$ruleRef{'icon'} ne "none") ) {
my ($labelText, $ref) = createLabel (\@tags, $$ruleRef{'label'}, $$lonRef{$nodeId}, $$latRef{$nodeId}) ;
$labelText = labelTransform($labelText, $$ruleRef{'labeltransform'}); $labelText = labelTransform($labelText, $$ruleRef{'labeltransform'});
my $labelSize = $$ruleRef{'labelsize'}; my $labelSize = $$ruleRef{'labelsize'};
my $labelColor = $$ruleRef{'labelcolor'}; my $labelColor = $$ruleRef{'labelcolor'};
@ -119,7 +89,6 @@ sub processNodes {
placeLabelAndIcon($$lonRef{$nodeId}, $$latRef{$nodeId}, 0, $$ruleRef{'size'}, $labelText, $svgText, $icon, $iconSize, $iconSize, "nodes"); placeLabelAndIcon($$lonRef{$nodeId}, $$latRef{$nodeId}, 0, $$ruleRef{'size'}, $labelText, $svgText, $icon, $iconSize, $iconSize, "nodes");
} }
# fill poi directory # fill poi directory
my $thing0 = $$ruleRef{'keyvalue'}; my $thing0 = $$ruleRef{'keyvalue'};
@ -128,31 +97,19 @@ sub processNodes {
my $dirName = getValue("name", $$tagRef{$nodeId}); my $dirName = getValue("name", $$tagRef{$nodeId});
if((cv('poi')eq "1")and if((cv('poi')eq "1")and
(defined $dirName)and (defined $dirName)and
( $$ruleRef{'direxclude'} eq "no") ($$ruleRef{'direxclude'}eq "no") ){ $dirName .= "($thing)";
) { if(cv('grid')> 0){ my $sq = gridSquare($$lonRef{$nodeId}, $$latRef{$nodeId}, cv('grid'));
$dirName .= " ($thing)" ; if(defined $sq){ addToPoiHash($dirName, $sq);
if ( cv('grid') > 0) { } } else{ # $poiHash{$dirName}= 1;
my $sq = gridSquare($$lonRef{$nodeId}, $$latRef{$nodeId}, cv('grid')) ;
if (defined $sq) {
addToPoiHash ($dirName, $sq) ;
}
}
else {
# $poiHash{$dirName} = 1 ;
addToPoiHash($dirName, undef); addToPoiHash($dirName, undef);
} } }
}
}# defined ruleref }# defined ruleref
} }
} }
# ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------
sub createPoiDirectory { sub createPoiDirectory{ my $poiName;
my $poiName ;
my $poiFile; my $poiFile;
$poiName = cv('out'); $poiName = cv('out');
$poiName =~ s/\.svg/\_pois.txt/; $poiName =~ s/\.svg/\_pois.txt/;
@ -163,25 +120,14 @@ sub createPoiDirectory {
my $ref = getPoiHash(); my $ref = getPoiHash();
my %poiHash = %$ref; my %poiHash = %$ref;
if ( cv('grid') eq "0") { if(cv('grid')eq "0"){ foreach my $poi(sort keys %poiHash){ $poi = replaceHTMLCode($poi);
foreach my $poi (sort keys %poiHash) {
$poi = replaceHTMLCode ( $poi ) ;
print $poiFile "$poi\n"; print $poiFile "$poi\n";
} }} else{ foreach my $poi(sort keys %poiHash){ $poi = replaceHTMLCode($poi);
}
else {
foreach my $poi (sort keys %poiHash) {
$poi = replaceHTMLCode ( $poi ) ;
print $poiFile "$poi\t"; print $poiFile "$poi\t";
foreach my $square (sort keys %{$poiHash{$poi}}) { foreach my $square(sort keys %{$poiHash{$poi}}){ print $poiFile "$square ";
print $poiFile "$square " ; } print $poiFile "\n";
}} close($poiFile);
} }
print $poiFile "\n" ;
}
}
close ($poiFile) ;
}
1; 1;

View File

@ -46,17 +46,13 @@ my %box = () ;
# ------------------------------------------------------------- # -------------------------------------------------------------
sub boxOccupyLines { sub boxOccupyLines{ my($refCoords, $buffer, $value)= @_;
my ($refCoords, $buffer, $value) = @_ ;
my @coordinates = @$refCoords; my @coordinates = @$refCoords;
my @lines =(); my @lines =();
for ( my $i = 0; $i < $#coordinates-2; $i += 2 ) { for(my $i = 0; $i < $#coordinates-2; $i += 2){ push @lines, [$coordinates[$i], $coordinates[$i+1], $coordinates[$i+2], $coordinates[$i+3]];
push @lines, [$coordinates[$i], $coordinates[$i+1], $coordinates[$i+2], $coordinates[$i+3]] ;
} }
foreach my $line(@lines){ my $x1 = $line->[0];
foreach my $line ( @lines ) {
my $x1 = $line->[0] ;
my $y1 = $line->[1]; my $y1 = $line->[1];
my $x2 = $line->[2]; my $x2 = $line->[2];
my $y2 = $line->[3]; my $y2 = $line->[3];
@ -65,18 +61,14 @@ sub boxOccupyLines {
# print "$x1, $y1, $x2, $y2\n"; # print "$x1, $y1, $x2, $y2\n";
if($x1 != $x2){ if($x1 != $x2){
my $m =($y2 - $y1)/($x2 - $x1); my $m =($y2 - $y1)/($x2 - $x1);
my $b = $y1 - $m * $x1; my $b = $y1 - $m * $x1;
if(abs($x1 - $x2)> abs($y1 - $y2)){ if(abs($x1 - $x2)> abs($y1 - $y2)){
# calc points on x axis # calc points on x axis
my $x = $x1; my $x = $x1;
my $stepX = $boxSize; my $stepX = $boxSize;
if ( $x2 < $x1 ) { $stepX = - $boxSize ; } if($x2 < $x1){$stepX = - $boxSize;} while(($x >= min($x1, $x2))and($x <= max($x1, $x2))){
while ( ( $x >= min ($x1, $x2) ) and ( $x <= max ($x1, $x2) ) ) {
my $y = $m * $x + $b; my $y = $m * $x + $b;
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
@ -87,16 +79,12 @@ sub boxOccupyLines {
boxOccupyArea($ax1, $ay1, $ax2, $ay2, 0, $value); boxOccupyArea($ax1, $ay1, $ax2, $ay2, 0, $value);
$x += $stepX; $x += $stepX;
} }
} else{
}
else {
# calc points on y axis # calc points on y axis
my $y = $y1; my $y = $y1;
my $stepY = $boxSize; my $stepY = $boxSize;
if ( $y2 < $y1 ) { $stepY = - $boxSize ; } if($y2 < $y1){$stepY = - $boxSize;} while(($y >= min($y1, $y2))and($y <= max($y1, $y2))){
while ( ( $y >= min ($y1, $y2) ) and ( $y <= max ($y1, $y2) ) ) {
my $x =($y - $b)/ $m; my $x =($y - $b)/ $m;
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
@ -108,19 +96,14 @@ sub boxOccupyLines {
$y += $stepY; $y += $stepY;
} }
}# abs }# abs
} } else{ my $x = $x1;
else {
my $x = $x1 ;
# calc points on y axis # calc points on y axis
my $y = $y1; my $y = $y1;
my $stepY = $boxSize; my $stepY = $boxSize;
if ( $y2 < $y1 ) { $stepY = - $boxSize ; } if($y2 < $y1){$stepY = - $boxSize;} while(($y >= min($y1, $y2))and($y <= max($y1, $y2))){
while ( ( $y >= min ($y1, $y2) ) and ( $y <= max ($y1, $y2) ) ) {
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
my $ax1 = $x - $buffer; my $ax1 = $x - $buffer;
my $ax2 = $x + $buffer; my $ax2 = $x + $buffer;
@ -129,25 +112,18 @@ sub boxOccupyLines {
boxOccupyArea($ax1, $ay1, $ax2, $ay2, 0, $value); boxOccupyArea($ax1, $ay1, $ax2, $ay2, 0, $value);
$y += $stepY; $y += $stepY;
} } }
}
} }}
}
sub boxLinesOccupied{ my($refCoords, $buffer)= @_;
sub boxLinesOccupied {
my ($refCoords, $buffer) = @_ ;
my @coordinates = @$refCoords; my @coordinates = @$refCoords;
my @lines =(); my @lines =();
my $result = 0; my $result = 0;
for ( my $i = 0; $i < $#coordinates-2; $i += 2 ) { for(my $i = 0; $i < $#coordinates-2; $i += 2){ push @lines, [$coordinates[$i], $coordinates[$i+1], $coordinates[$i+2], $coordinates[$i+3]];
push @lines, [$coordinates[$i], $coordinates[$i+1], $coordinates[$i+2], $coordinates[$i+3]] ;
} }
foreach my $line(@lines){ my $x1 = $line->[0];
foreach my $line ( @lines ) {
my $x1 = $line->[0] ;
my $y1 = $line->[1]; my $y1 = $line->[1];
my $x2 = $line->[2]; my $x2 = $line->[2];
my $y2 = $line->[3]; my $y2 = $line->[3];
@ -156,18 +132,14 @@ sub boxLinesOccupied {
# print "$x1, $y1, $x2, $y2\n"; # print "$x1, $y1, $x2, $y2\n";
if($x1 != $x2){ if($x1 != $x2){
my $m =($y2 - $y1)/($x2 - $x1); my $m =($y2 - $y1)/($x2 - $x1);
my $b = $y1 - $m * $x1; my $b = $y1 - $m * $x1;
if(abs($x1 - $x2)> abs($y1 - $y2)){ if(abs($x1 - $x2)> abs($y1 - $y2)){
# calc points on x axis # calc points on x axis
my $x = $x1; my $x = $x1;
my $stepX = $boxSize; my $stepX = $boxSize;
if ( $x2 < $x1 ) { $stepX = - $boxSize ; } if($x2 < $x1){$stepX = - $boxSize;} while(($x >= min($x1, $x2))and($x <= max($x1, $x2))){
while ( ( $x >= min ($x1, $x2) ) and ( $x <= max ($x1, $x2) ) ) {
my $y = $m * $x + $b; my $y = $m * $x + $b;
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
@ -176,19 +148,14 @@ sub boxLinesOccupied {
my $ay1 = $y - $buffer; my $ay1 = $y - $buffer;
my $ay2 = $y + $buffer; my $ay2 = $y + $buffer;
my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2); my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2);
if ($tmp > $result) { $result = $tmp ; } if($tmp > $result){$result = $tmp;} $x += $stepX;
$x += $stepX ;
} }
} else{
}
else {
# calc points on y axis # calc points on y axis
my $y = $y1; my $y = $y1;
my $stepY = $boxSize; my $stepY = $boxSize;
if ( $y2 < $y1 ) { $stepY = - $boxSize ; } if($y2 < $y1){$stepY = - $boxSize;} while(($y >= min($y1, $y2))and($y <= max($y1, $y2))){
while ( ( $y >= min ($y1, $y2) ) and ( $y <= max ($y1, $y2) ) ) {
my $x =($y - $b)/ $m; my $x =($y - $b)/ $m;
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
@ -198,22 +165,16 @@ sub boxLinesOccupied {
my $ay2 = $y + $buffer; my $ay2 = $y + $buffer;
my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2); my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2);
if($tmp > $result){$result = $tmp;} if($tmp > $result){$result = $tmp;}
$y += $stepY; $y += $stepY;
} }
}# abs }# abs
} } else{ my $x = $x1;
else {
my $x = $x1 ;
# calc points on y axis # calc points on y axis
my $y = $y1; my $y = $y1;
my $stepY = $boxSize; my $stepY = $boxSize;
if ( $y2 < $y1 ) { $stepY = - $boxSize ; } if($y2 < $y1){$stepY = - $boxSize;} while(($y >= min($y1, $y2))and($y <= max($y1, $y2))){
while ( ( $y >= min ($y1, $y2) ) and ( $y <= max ($y1, $y2) ) ) {
# ACTUAL COORDINATE $x, $y # ACTUAL COORDINATE $x, $y
my $ax1 = $x - $buffer; my $ax1 = $x - $buffer;
my $ax2 = $x + $buffer; my $ax2 = $x + $buffer;
@ -221,111 +182,71 @@ sub boxLinesOccupied {
my $ay2 = $y + $buffer; my $ay2 = $y + $buffer;
my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2); my $tmp = boxAreaOccupied($ax1, $ay1, $ax2, $ay2);
if($tmp > $result){$result = $tmp;} if($tmp > $result){$result = $tmp;}
$y += $stepY; $y += $stepY;
} } }
}
} return $result;
} }
return $result ;
}
# ------------------------------------------------------------- # -------------------------------------------------------------
sub boxOccupyArea { sub boxOccupyArea{ my($x1, $y1, $x2, $y2, $buffer, $value)= @_;
my ($x1, $y1, $x2, $y2, $buffer, $value) = @_ ;
if ( $x2 < $x1) { if($x2 < $x1){ my $tmp = $x1;
my $tmp = $x1 ;
$x1 = $x2; $x1 = $x2;
$x2 = $tmp; $x2 = $tmp;
} } if($y2 < $y1){ my $tmp = $y1;
if ( $y2 < $y1) {
my $tmp = $y1 ;
$y1 = $y2; $y1 = $y2;
$y2 = $tmp; $y2 = $tmp;
} }
$x1 -= $buffer; $x1 -= $buffer;
$x2 += $buffer; $x2 += $buffer;
$y1 -= $buffer; $y1 -= $buffer;
$y2 += $buffer; $y2 += $buffer;
for ( my $x = $x1; $x <= $x2; $x += $boxSize) { for(my $x = $x1; $x <= $x2; $x += $boxSize){ for(my $y = $y1; $y <= $y2; $y += $boxSize){ my $bx = int($x / $boxSize);
for ( my $y = $y1; $y <= $y2; $y += $boxSize) {
my $bx = int ( $x / $boxSize ) ;
my $by = int($y / $boxSize); my $by = int($y / $boxSize);
$box{$bx}{$by}= $value; $box{$bx}{$by}= $value;
# print "box $bx, $by occupied\n"; # print "box $bx, $by occupied\n";
} }}
}
return; return;
} }
sub boxAreaOccupied{ my($x1, $y1, $x2, $y2)= @_;
sub boxAreaOccupied {
my ($x1, $y1, $x2, $y2) = @_ ;
my $result = 0; my $result = 0;
if ( $x2 < $x1) { if($x2 < $x1){ my $tmp = $x1;
my $tmp = $x1 ;
$x1 = $x2; $x1 = $x2;
$x2 = $tmp; $x2 = $tmp;
} } if($y2 < $y1){ my $tmp = $y1;
if ( $y2 < $y1) {
my $tmp = $y1 ;
$y1 = $y2; $y1 = $y2;
$y2 = $tmp; $y2 = $tmp;
} }
for(my $x = $x1; $x <= $x2; $x += $boxSize){ my $bx = int($x / $boxSize);
for ( my $x = $x1; $x <= $x2; $x += $boxSize) { for(my $y = $y1; $y <= $y2; $y += $boxSize){ my $by = int($y / $boxSize);
my $bx = int ($x / $boxSize) ;
for ( my $y = $y1; $y <= $y2; $y += $boxSize) {
my $by = int ($y / $boxSize) ;
# print " $bx, $by\n"; # print " $bx, $by\n";
if ( defined $box{$bx}{$by} ) { if(defined $box{$bx}{$by}){ if($box{$bx}{$by}> $result){ # print "check box $bx, $by\n";
if ( $box{$bx}{$by} > $result ) {
# print "check box $bx, $by\n" ;
$result = $box{$bx}{$by}; $result = $box{$bx}{$by};
} } }} return $result;
} }
}
}
}
return $result ;
}
# ------------------------------------------------------------- # -------------------------------------------------------------
sub boxDrawOccupiedAreas { sub boxDrawOccupiedAreas{ my $format1 = "fill=\"red\" fill-opacity=\"0.3\" ";
my $format1 = "fill=\"red\" fill-opacity=\"0.3\" " ;
my $format2 = "fill=\"blue\" fill-opacity=\"0.3\" "; my $format2 = "fill=\"blue\" fill-opacity=\"0.3\" ";
my $format3 = "fill=\"green\" fill-opacity=\"0.5\" "; my $format3 = "fill=\"green\" fill-opacity=\"0.5\" ";
foreach my $bx ( sort {$a <=> $b} keys %box ) { foreach my $bx(sort{$a <=> $b}keys %box){ foreach my $by(sort{$a <=> $b}keys %{$box{$bx}}){ my $x1 = $bx * $boxSize;
foreach my $by ( sort {$a <=> $b} keys %{$box{$bx}} ) {
my $x1 = $bx * $boxSize ;
my $x2 = $x1 + $boxSize; my $x2 = $x1 + $boxSize;
my $y1 = $by * $boxSize; my $y1 = $by * $boxSize;
my $y2 = $y1 + $boxSize; my $y2 = $y1 + $boxSize;
if ( $box{$bx}{$by} == 1) { if($box{$bx}{$by}== 1){ drawRect($x1, $y1, $x2, $y2, 0, $format1, "occupied");
drawRect ($x1, $y1, $x2, $y2, 0, $format1, "occupied") ; } elsif($box{$bx}{$by}== 2){ drawRect($x1, $y1, $x2, $y2, 0, $format2, "occupied");
} else { drawRect($x1, $y1, $x2, $y2, 0, $format3, "occupied");
} # print "occupied $bx, $by\n";
}}
} }
elsif ( $box{$bx}{$by} == 2) {
drawRect ($x1, $y1, $x2, $y2, 0, $format2, "occupied") ;
}
else {
drawRect ($x1, $y1, $x2, $y2, 0, $format3, "occupied") ;
}
# print "occupied $bx, $by\n" ;
}
}
}
1; 1;

View File

@ -46,8 +46,7 @@ my %iconSizeY = () ;
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
sub processRoutes { sub processRoutes{#
#
# process route data # process route data
# #
my %routeColors =(); # will point to arrays of colors per route type my %routeColors =(); # will point to arrays of colors per route type
@ -64,51 +63,35 @@ sub processRoutes {
my $ref = getRouteColors(); my $ref = getRouteColors();
%routeColors = %$ref; %routeColors = %$ref;
foreach my $type (keys %routeColors) { foreach my $type(keys %routeColors){ $colorNumber{$type}= scalar @{$routeColors{$type}};
$colorNumber{$type} = scalar @{$routeColors{$type}} ;
$actualColorIndex{$type}= 0; $actualColorIndex{$type}= 0;
} }
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
my($wayNodesRef, $wayTagsRef)= getWayPointers(); my($wayNodesRef, $wayTagsRef)= getWayPointers();
my($relationMembersRef, $relationTagsRef)= getRelationPointers(); my($relationMembersRef, $relationTagsRef)= getRelationPointers();
foreach my $relId (keys %$relationTagsRef) { foreach my $relId(keys %$relationTagsRef){ my $relationType = getValue("type", $$relationTagsRef{$relId});
my $relationType = getValue ("type", $$relationTagsRef{$relId} ) ;
if(! defined $relationType){$relationType = "";} if(! defined $relationType){$relationType = "";}
if(($relationType eq "route")and((cv('relid')== $relId)or(cv('relid')== 0))){ if(($relationType eq "route")and((cv('relid')== $relId)or(cv('relid')== 0))){
my $ruleRef = getRouteRule($$relationTagsRef{$relId}); my $ruleRef = getRouteRule($$relationTagsRef{$relId});
if(defined $ruleRef){ if(defined $ruleRef){
# new route detected # new route detected
if(cv('debug')eq "1"){print "ROUTE: rule found for $relId, $$ruleRef{'type'}.\n";} if(cv('debug')eq "1"){print "ROUTE: rule found for $relId, $$ruleRef{'type'}.\n";}
# try to get color from relation tags first # try to get color from relation tags first
# #
my $color = getValue("color", $$relationTagsRef{$relId}); my $color = getValue("color", $$relationTagsRef{$relId});
if ( ! defined $color) { if(! defined $color){ $color = getValue("colour", $$relationTagsRef{$relId});
$color = getValue ("colour", $$relationTagsRef{$relId} ) ;
} }
# no color yet, then get color from rule # no color yet, then get color from rule
# #
if(! defined $color){ if(! defined $color){
if (cv('debug') eq "1" ) { print "ROUTE: actual color index: $actualColorIndex{ $$ruleRef{'type'} }\n" ; } if(cv('debug')eq "1"){print "ROUTE: actual color index: $actualColorIndex{$$ruleRef{'type'}}\n";} $color = $routeColors{$$ruleRef{'type'}}[$actualColorIndex{$$ruleRef{'type'}}];
$color = $routeColors{ $$ruleRef{'type'} }[$actualColorIndex{ $$ruleRef{'type'} }] ;
$actualColorIndex{$$ruleRef{'type'}}=($actualColorIndex{$$ruleRef{'type'}}+ 1)% $colorNumber{$$ruleRef{'type'}}; $actualColorIndex{$$ruleRef{'type'}}=($actualColorIndex{$$ruleRef{'type'}}+ 1)% $colorNumber{$$ruleRef{'type'}};
} } if(cv('debug')eq "1"){print "ROUTE: $relId final color: $color\n";}
if (cv('debug') eq "1" ) { print "ROUTE: $relId final color: $color\n" ; }
# find icon # find icon
my $iconName = getValue("ref", $$relationTagsRef{$relId}); my $iconName = getValue("ref", $$relationTagsRef{$relId});
if ( ! defined $iconName ) { if(! defined $iconName){ getValue("name", $$relationTagsRef{$relId}) } if(! defined $iconName){$iconName = "";}
getValue ("name", $$relationTagsRef{$relId} )
}
if ( ! defined $iconName) { $iconName = "" ; }
# look for route icon. svg first, then png # look for route icon. svg first, then png
my $file; my $file;
@ -116,78 +99,55 @@ sub processRoutes {
my $iconResult = open($file, "<", $iconName); my $iconResult = open($file, "<", $iconName);
# print " trying $iconName\n"; # print " trying $iconName\n";
if($iconResult){ if($iconResult){
if (cv('debug') eq "1") { print "ROUTE: icon $iconName found!\n" ; } if(cv('debug')eq "1"){print "ROUTE: icon $iconName found!\n";} close($file);
close ($file) ;
} }
if ( ! $iconResult) { if(! $iconResult){ $iconName =~ s/.svg/.png/;
$iconName =~ s/.svg/.png/ ;
# print " trying $iconName\n"; # print " trying $iconName\n";
$iconResult = open($file, "<", $iconName); $iconResult = open($file, "<", $iconName);
if($iconResult){ if($iconResult){
if (cv('debug') eq "1") { print "ROUTE: icon $iconName found!\n" ; } if(cv('debug')eq "1"){print "ROUTE: icon $iconName found!\n";} close($file);
close ($file) ;
} }
} }
if($iconResult){ my($x, $y); undef $x; undef $y;
if ($iconResult) { if(grep /.svg/, $iconName){ ($x, $y)= sizeSVG($iconName);
my ($x, $y) ; undef $x ; undef $y ;
if (grep /.svg/, $iconName) {
($x, $y) = sizeSVG ($iconName) ;
if(($x == 0)or($y == 0)){ if(($x == 0)or($y == 0)){
$x = 32; $y = 32; $x = 32; $y = 32;
print "WARNING: size of file $iconName could not be determined. Set to 32px x 32px\n"; print "WARNING: size of file $iconName could not be determined. Set to 32px x 32px\n";
} }
} }
if(grep /.png/, $iconName){ ($x, $y)= sizePNG($iconName);
if (grep /.png/, $iconName) {
($x, $y) = sizePNG ($iconName) ;
} }
$iconSizeX{$iconName}= $x; $iconSizeX{$iconName}= $x;
$iconSizeY{$iconName}= $y; $iconSizeY{$iconName}= $y;
} }
my($label, $ref)= createLabel($$relationTagsRef{$relId}, $$ruleRef{'label'}); my($label, $ref)= createLabel($$relationTagsRef{$relId}, $$ruleRef{'label'});
my $printIcon = ""; if($iconResult){$printIcon = $iconName;} my $printIcon = ""; if($iconResult){$printIcon = $iconName;}
if(cv('verbose')eq "1"){ if(cv('verbose')eq "1"){
printf "ROUTE: route %10s %10s %10s %30s %40s\n", $relId, $$ruleRef{'type'}, $color, $label, $printIcon; printf "ROUTE: route %10s %10s %10s %30s %40s\n", $relId, $$ruleRef{'type'}, $color, $label, $printIcon;
} }
# collect ways # collect ways
my $mRef = getAllMembers($relId, 0); my $mRef = getAllMembers($relId, 0);
my @tempMembers = @$mRef; my @tempMembers = @$mRef;
my @relWays =(); my @relWays =();
foreach my $member (@tempMembers) { foreach my $member(@tempMembers){ if((($member->[2] eq "none")or($member->[2] eq "route"))and($member->[0] eq "way")){push @relWays, $member->[1];} if((($member->[2] eq "forward")or($member->[2] eq "backward"))and($member->[0] eq "way")){push @relWays, $member->[1];}
if ( ( ($member->[2] eq "none") or ($member->[2] eq "route") ) and ($member->[0] eq "way") ) { push @relWays, $member->[1] ; }
if ( ( ($member->[2] eq "forward") or ($member->[2] eq "backward") ) and ($member->[0] eq "way") ) { push @relWays, $member->[1] ; }
# TODO diversions, shortcuts? # TODO diversions, shortcuts?
# stops # stops
if ( (grep /stop/, $member->[2]) and ($member->[0] eq "node") ) { if((grep /stop/, $member->[2])and($member->[0] eq "node")){ if(($$ruleRef{'nodesize'}> 0)and(defined $$latRef{$member->[1]})and(defined $$lonRef{$member->[1]})){ my $svgString = "fill=\"$color\" ";
if ( ( $$ruleRef{'nodesize'} > 0) and (defined $$latRef{$member->[1]}) and (defined $$lonRef{$member->[1]}) ) {
my $svgString = "fill=\"$color\" " ;
drawCircle($$lonRef{$member->[1]}, $$latRef{$member->[1]}, 1, $$ruleRef{'nodesize'}, 0, $svgString, 'routes'); drawCircle($$lonRef{$member->[1]}, $$latRef{$member->[1]}, 1, $$ruleRef{'nodesize'}, 0, $svgString, 'routes');
} } } }
}
}
if(cv('debug')eq "1"){print "ROUTE: ways: @relWays\n";} if(cv('debug')eq "1"){print "ROUTE: ways: @relWays\n";}
foreach my $w(@relWays){ foreach my $w(@relWays){
my $op = $$ruleRef{'opacity'}/ 100; my $op = $$ruleRef{'opacity'}/ 100;
my $width = $$ruleRef{'size'}; my $width = $$ruleRef{'size'};
my $linecap = $$ruleRef{'linecap'}; my $linecap = $$ruleRef{'linecap'};
my $dashString = ""; my $dashString = "";
my $dash = $$ruleRef{'dash'}; my $dash = $$ruleRef{'dash'};
if ( $dash ne "") { $dashString = "stroke-dasharray=\"$dash\" " ; } if($dash ne ""){$dashString = "stroke-dasharray=\"$dash\" ";} my $svgString = "stroke=\"$color\" stroke-opacity=\"$op\" stroke-width=\"$width\" fill=\"none\" stroke-linejoin=\"round\" stroke-linecap=\"$linecap\" " . $dashString;
my $svgString = "stroke=\"$color\" stroke-opacity=\"$op\" stroke-width=\"$width\" fill=\"none\" stroke-linejoin=\"round\" stroke-linecap=\"$linecap\" " . $dashString ;
drawWay($$wayNodesRef{$w}, 1, $svgString, "routes", undef); drawWay($$wayNodesRef{$w}, 1, $svgString, "routes", undef);
@ -196,35 +156,25 @@ sub processRoutes {
$wayRouteLabels{$w}{$label}= 1; $wayRouteLabels{$w}{$label}= 1;
if($iconResult){ if($iconResult){
$wayRouteIcons{$w}{$iconName}= 1; $wayRouteIcons{$w}{$iconName}= 1;
} } }
}
}# rule found }# rule found
if (cv('debug') eq "1") { print "\n" ; } if(cv('debug')eq "1"){print "\n";} }# rel route
} # rel route
}# relation }# relation
# label route ways after all relations have been processed # label route ways after all relations have been processed
foreach my $w (keys %wayRouteLabels) { foreach my $w(keys %wayRouteLabels){ if((defined $$wayNodesRef{$w})and(scalar @{$$wayNodesRef{$w}}> 1)){ my $label = "";
if ( (defined $$wayNodesRef{$w}) and (scalar @{$$wayNodesRef{$w}} > 1) ) { foreach my $l(keys %{$wayRouteLabels{$w}}){ $label .= $l . " ";
my $label = "" ;
foreach my $l (keys %{$wayRouteLabels{$w}}) {
$label .= $l . " " ;
} }
my @way = @{$$wayNodesRef{$w}}; my @way = @{$$wayNodesRef{$w}};
if ($$lonRef{$way[0]} > $$lonRef{$way[-1]}) { if($$lonRef{$way[0]}> $$lonRef{$way[-1]}){ @way = reverse(@way);
@way = reverse (@way) ;
} }
if(labelFitsWay(\@way, $label, cv('routelabelfont'), cv('routelabelsize'))){ my $pathName = "RoutePath" . $pathNumber;
if (labelFitsWay ( \@way, $label, cv('routelabelfont'), cv('routelabelsize') ) ) {
my $pathName = "RoutePath" . $pathNumber ;
$pathNumber++; $pathNumber++;
my @points = nodes2Coordinates(@way); my @points = nodes2Coordinates(@way);
if(! coordsOut(@points)){ if(! coordsOut(@points)){
createPath($pathName, \@points, "definitions"); createPath($pathName, \@points, "definitions");
my $size = cv('routelabelsize'); my $size = cv('routelabelsize');
@ -234,35 +184,23 @@ sub processRoutes {
my $svgText = createTextSVG($fontFamily, $font, $size, $color, undef, undef); my $svgText = createTextSVG($fontFamily, $font, $size, $color, undef, undef);
pathText($svgText, $label, $pathName, cv('routelabeloffset'), "middle", 50, "routes"); pathText($svgText, $label, $pathName, cv('routelabeloffset'), "middle", 50, "routes");
} } } }}
}
}
}
# place icons # place icons
foreach my $w (keys %wayRouteIcons) { foreach my $w(keys %wayRouteIcons){ my $offset = 0;
my $offset = 0 ;
my $nodeNumber = scalar @{$$wayNodesRef{$w}}; my $nodeNumber = scalar @{$$wayNodesRef{$w}};
if ($nodeNumber > 1) { if($nodeNumber > 1){ my $node = $$wayNodesRef{$w}[int($nodeNumber / 2)];
my $node = $$wayNodesRef{$w}[int ($nodeNumber / 2)] ;
my $num = scalar(keys %{$wayRouteIcons{$w}}); my $num = scalar(keys %{$wayRouteIcons{$w}});
$offset = int(-($num-1)* cv('routeicondist')/ 2); $offset = int(-($num-1)* cv('routeicondist')/ 2);
foreach my $iconName(keys %{$wayRouteIcons{$w}}){ foreach my $iconName(keys %{$wayRouteIcons{$w}}){
my $size = 40; my $size = 40;
placeLabelAndIcon($$lonRef{$node}, $$latRef{$node}, $offset, $size, "", "", $iconName, $iconSizeX{$iconName}, $iconSizeY{$iconName}, "routes"); placeLabelAndIcon($$lonRef{$node}, $$latRef{$node}, $offset, $size, "", "", $iconName, $iconSizeX{$iconName}, $iconSizeY{$iconName}, "routes");
$offset += cv('routeicondist'); $offset += cv('routeicondist');
} } }}}
}
}
}
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
sub getAllMembers { sub getAllMembers{#
#
# get all members of a relation recursively # get all members of a relation recursively
# takes rel id and nesting level # takes rel id and nesting level
# retruns ref to array with all members # retruns ref to array with all members
@ -275,51 +213,33 @@ sub getAllMembers {
if($nestingLevel > $maxNestingLevel){ if($nestingLevel > $maxNestingLevel){
print "ERROR/WARNING nesting level of relations too deep. recursion stopped at depth $maxNestingLevel! relId=$relId\n"; print "ERROR/WARNING nesting level of relations too deep. recursion stopped at depth $maxNestingLevel! relId=$relId\n";
} } else{ foreach my $member(@{$$relationMembersRef{$relId}}){ if(($member->[0] eq "way")or($member->[0] eq "node")){ push @allMembers, $member;
else { } if($member->[0] eq "relation"){ my $ref = getAllMembers($member->[1], $nestingLevel+1);
foreach my $member ( @{$$relationMembersRef{$relId}} ) {
if ( ($member->[0] eq "way") or ($member->[0] eq "node") ) {
push @allMembers, $member ;
}
if ( $member->[0] eq "relation" ) {
my $ref = getAllMembers ($member->[1], $nestingLevel+1) ;
push @allMembers, @$ref; push @allMembers, @$ref;
} }
} return \@allMembers;
} }
} sub labelFitsWay{ my($refWayNodes, $text, $font, $size)= @_;
}
return \@allMembers ;
}
sub labelFitsWay {
my ($refWayNodes, $text, $font, $size) = @_ ;
my @wayNodes = @$refWayNodes; my @wayNodes = @$refWayNodes;
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
# calc waylen # calc waylen
my $wayLength = 0; # in pixels my $wayLength = 0; # in pixels
for (my $i=0; $i<$#wayNodes; $i++) { for(my $i=0; $i<$#wayNodes; $i++){ my($x1, $y1)= convert($$lonRef{$wayNodes[$i]}, $$latRef{$wayNodes[$i]});
my ($x1, $y1) = convert ($$lonRef{$wayNodes[$i]}, $$latRef{$wayNodes[$i]}) ;
my($x2, $y2)= convert($$lonRef{$wayNodes[$i+1]}, $$latRef{$wayNodes[$i+1]}); my($x2, $y2)= convert($$lonRef{$wayNodes[$i+1]}, $$latRef{$wayNodes[$i+1]});
$wayLength += sqrt(($x2-$x1)**2 +($y2-$y1)**2); $wayLength += sqrt(($x2-$x1)**2 +($y2-$y1)**2);
} }
# calc label len # calc label len
my $labelLength = length($text)* cv('ppc')/ 10 * $size; # in pixels my $labelLength = length($text)* cv('ppc')/ 10 * $size; # in pixels
my $fit; my $fit;
if ($labelLength < $wayLength) { $fit="fit" ; } else { $fit = "NOFIT" ; } if($labelLength < $wayLength){$fit="fit";}else{$fit = "NOFIT";} # print "labelFitsWay: $fit, $text, labelLen = $labelLength, wayLen = $wayLength\n";
# print "labelFitsWay: $fit, $text, labelLen = $labelLength, wayLen = $wayLength\n" ;
if ($labelLength < $wayLength) {
return 1 ;
}
else {
return 0 ;
}
}
if($labelLength < $wayLength){ return 1;
} else{ return 0;
}}
1; 1;

View File

@ -46,8 +46,7 @@ require Exporter ;
createLegend createLegend
); );
my @validNodeProperties = ( my @validNodeProperties =( ["keyValue","key and value like [amenity=hospital]"],
["keyValue","key and value like [amenity=hospital]"],
["color","color of node i.e. [black]"], ["color","color of node i.e. [black]"],
["size","size of node i.e. [50]"], ["size","size of node i.e. [50]"],
["shape","shape of node [circle|disc|triangle|diamond|rectangle]"], ["shape","shape of node [circle|disc|triangle|diamond|rectangle]"],
@ -85,8 +84,7 @@ my @validNodeProperties = (
["direxclude","should these objects be excluded from directory? [yes|no]"] ["direxclude","should these objects be excluded from directory? [yes|no]"]
); );
my @validWayProperties = ( my @validWayProperties =( ["keyValue","key and value like [highway=residential]"],
["keyValue","key and value like [highway=residential]"],
["color","color for the way i.e. [gray]"], ["color","color for the way i.e. [gray]"],
["size","size of the way i.e. [15]"], ["size","size of the way i.e. [15]"],
["dash","svg dash array for the way i.e. [20,20]; old mapgen values are also possible"], ["dash","svg dash array for the way i.e. [20,20]; old mapgen values are also possible"],
@ -117,8 +115,7 @@ my @validWayProperties = (
["direxclude","should these objects be excluded from directory? [yes|no]"] ["direxclude","should these objects be excluded from directory? [yes|no]"]
); );
my @validAreaProperties = ( my @validAreaProperties =( ["keyValue","key and value of object i.e. [amenity=parking]"],
["keyValue","key and value of object i.e. [amenity=parking]"],
["color","color of area i.e. [lightgrey]"], ["color","color of area i.e. [lightgrey]"],
["icon","icon for fill pattern to be used i.e. [icondir/parking.svg]"], ["icon","icon for fill pattern to be used i.e. [icondir/parking.svg]"],
["label", "label text to be rendered i.e. [name]"] , ["label", "label text to be rendered i.e. [name]"] ,
@ -140,8 +137,7 @@ my @validAreaProperties = (
); );
my @validRouteProperties = ( my @validRouteProperties =( ["type","type of route like [bus|hiking]"],
["type","type of route like [bus|hiking]"],
["color","color of route like [red]"], ["color","color of route like [red]"],
["size","size of route i.e. [10]"], ["size","size of route i.e. [10]"],
["dash","svg dash array style like [20,20]"], ["dash","svg dash array style like [20,20]"],
@ -172,34 +168,23 @@ my $ruleFile ;
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
sub printValidObjectProperties{ sub printValidObjectProperties{
print "\nValid Object Properties\n"; print "\nValid Object Properties\n";
print "\nNodes\n-----\n"; print "\nNodes\n-----\n";
foreach my $p (sort {$a->[0] cmp $b->[0]} @validNodeProperties) { foreach my $p(sort{$a->[0] cmp $b->[0]}@validNodeProperties){ printf "%-20s %s\n", $p->[0], $p->[1];
printf "%-20s %s\n", $p->[0], $p->[1] ; } print "\nWays\n----\n";
foreach my $p(sort{$a->[0] cmp $b->[0]}@validWayProperties){ printf "%-20s %s\n", $p->[0], $p->[1];
} print "\nAreas\n-----\n";
foreach my $p(sort{$a->[0] cmp $b->[0]}@validAreaProperties){ printf "%-20s %s\n", $p->[0], $p->[1];
} print "\nRoutes\n-----\n";
foreach my $p(sort{$a->[0] cmp $b->[0]}@validRouteProperties){ printf "%-20s %s\n", $p->[0], $p->[1];
} print "\n";
} }
print "\nWays\n----\n" ;
foreach my $p (sort {$a->[0] cmp $b->[0]} @validWayProperties) {
printf "%-20s %s\n", $p->[0], $p->[1] ;
}
print "\nAreas\n-----\n" ;
foreach my $p (sort {$a->[0] cmp $b->[0]} @validAreaProperties) {
printf "%-20s %s\n", $p->[0], $p->[1] ;
}
print "\nRoutes\n-----\n" ;
foreach my $p (sort {$a->[0] cmp $b->[0]} @validRouteProperties) {
printf "%-20s %s\n", $p->[0], $p->[1] ;
}
print "\n" ;
}
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
sub readRules{ sub readRules{
my $fileName = cv('style'); my $fileName = cv('style');
my $nrr = 0; my $wrr = 0; my $arr = 0; my $rrr = 0; my $crr = 0; my $nrr = 0; my $wrr = 0; my $arr = 0; my $rrr = 0; my $crr = 0;
@ -207,20 +192,14 @@ sub readRules {
my %vnp =(); my %vnp =();
foreach my $p(@validNodeProperties){$vnp{lc($p->[0])}= 1;} foreach my $p(@validNodeProperties){$vnp{lc($p->[0])}= 1;}
my %vwp =(); my %vwp =();
foreach my $p(@validWayProperties){$vwp{lc($p->[0])}= 1;} foreach my $p(@validWayProperties){$vwp{lc($p->[0])}= 1;}
my %vap =(); my %vap =();
foreach my $p(@validAreaProperties){$vap{lc($p->[0])}= 1;} foreach my $p(@validAreaProperties){$vap{lc($p->[0])}= 1;}
my %vrp =(); my %vrp =();
foreach my $p(@validRouteProperties){$vrp{lc($p->[0])}= 1;} foreach my $p(@validRouteProperties){$vrp{lc($p->[0])}= 1;}
openRuleFile($fileName); openRuleFile($fileName);
while (defined $line) { while(defined $line){ if(grep /^rule node/i, $line){ $nodeNr++;
if ( grep /^rule node/i, $line ) {
$nodeNr++ ;
$nrr++; $nrr++;
getRuleLine(); getRuleLine();
@ -264,24 +243,15 @@ sub readRules {
$nodeRules{$nodeNr}{'direxclude'}= cv('direxcludedefault'); $nodeRules{$nodeNr}{'direxclude'}= cv('direxcludedefault');
while ( ( defined $line) and ( ! grep /^rule/i, $line) ) { while((defined $line)and(! grep /^rule/i, $line)){ my($k, $v)=($line =~ /(.+?)=(.+)/);
my ($k, $v) = ( $line =~ /(.+?)=(.+)/ ) ; if((! defined $k)or(! defined $v)){ print "WARNING: could not parse rule line: $line";
if ( ( ! defined $k ) or ( ! defined $v ) ) { } else{ $k = lc($k);
print "WARNING: could not parse rule line: $line" ;
}
else {
$k = lc ( $k ) ;
$nodeRules{$nodeNr}{$k}= $v; $nodeRules{$nodeNr}{$k}= $v;
if ( ! defined $vnp{$k} ) { print "WARNING: $k is not a valid node property!\n" ; } if(! defined $vnp{$k}){print "WARNING: $k is not a valid node property!\n";} } getRuleLine();
} } if(! defined $nodeRules{$nodeNr}{'keyvalue'}){die "ERROR: rule without keyValue detected!\n";}
getRuleLine() ;
}
if ( ! defined $nodeRules{ $nodeNr }{ 'keyvalue' } ) { die "ERROR: rule without keyValue detected!\n" ; }
}# node }# node
elsif(grep /^rule way/i, $line){ elsif(grep /^rule way/i, $line){
$wayNr++; $wayNr++;
$wrr++; $wrr++;
getRuleLine(); getRuleLine();
@ -316,24 +286,15 @@ sub readRules {
$wayRules{$wayNr}{'direxclude'}= cv('direxcludedefault'); $wayRules{$wayNr}{'direxclude'}= cv('direxcludedefault');
while ( ( defined $line) and ( ! grep /^rule/i, $line) ) { while((defined $line)and(! grep /^rule/i, $line)){ my($k, $v)=($line =~ /(.+?)=(.+)/);
my ($k, $v) = ( $line =~ /(.+?)=(.+)/ ) ; if((! defined $k)or(! defined $v)){ print "WARNING: could not parse rule line: $line";
if ( ( ! defined $k ) or ( ! defined $v ) ) { } else{ $k = lc($k);
print "WARNING: could not parse rule line: $line" ;
}
else {
$k = lc ( $k ) ;
$wayRules{$wayNr}{$k}= $v; $wayRules{$wayNr}{$k}= $v;
if ( ! defined $vwp{$k} ) { print "WARNING: $k is not a valid way property!\n" ; } if(! defined $vwp{$k}){print "WARNING: $k is not a valid way property!\n";} } getRuleLine();
} } if(! defined $wayRules{$wayNr}{'keyvalue'}){die "ERROR: rule without keyValue detected!\n";}
getRuleLine() ;
}
if ( ! defined $wayRules{ $wayNr }{ 'keyvalue' } ) { die "ERROR: rule without keyValue detected!\n" ; }
}# way }# way
elsif ( grep /^rule area/i, $line ) { elsif(grep /^rule area/i, $line){ $areaNr++;
$areaNr++ ;
$arr++; $arr++;
getRuleLine(); getRuleLine();
@ -358,26 +319,16 @@ sub readRules {
$areaRules{$areaNr}{'fromscale'}= cv('ruledefaultareafromscale'); $areaRules{$areaNr}{'fromscale'}= cv('ruledefaultareafromscale');
$areaRules{$areaNr}{'toscale'}= cv('ruledefaultareatoscale'); $areaRules{$areaNr}{'toscale'}= cv('ruledefaultareatoscale');
while ( ( defined $line) and ( ! grep /^rule/i, $line) ) { while((defined $line)and(! grep /^rule/i, $line)){ my($k, $v)=($line =~ /(.+?)=(.+)/);
my ($k, $v) = ( $line =~ /(.+?)=(.+)/ ) ; if((! defined $k)or(! defined $v)){ print "WARNING: could not parse rule line: $line";
if ( ( ! defined $k ) or ( ! defined $v ) ) { } else{ $k = lc($k);
print "WARNING: could not parse rule line: $line" ;
}
else {
$k = lc ( $k ) ;
$areaRules{$areaNr}{$k}= $v; $areaRules{$areaNr}{$k}= $v;
if(! defined $vap{$k}){print "WARNING: $k is not a valid area property!\n";} if(! defined $vap{$k}){print "WARNING: $k is not a valid area property!\n";}
if($k eq "icon"){mwMap::addAreaIcon($v);} } getRuleLine();
if ($k eq "icon") { mwMap::addAreaIcon ($v) ; } } if(! defined $areaRules{$areaNr}{'keyvalue'}){die "ERROR: rule without keyValue detected!\n";}
}
getRuleLine() ;
}
if ( ! defined $areaRules{ $areaNr }{ 'keyvalue' } ) { die "ERROR: rule without keyValue detected!\n" ; }
}# area }# area
elsif ( grep /^rule route/i, $line ) { elsif(grep /^rule route/i, $line){ $routeNr++;
$routeNr++ ;
$rrr++; $rrr++;
getRuleLine(); getRuleLine();
@ -395,92 +346,65 @@ sub readRules {
$routeRules{$routeNr}{'fromscale'}= cv('ruleDefaultRouteFromScale'); $routeRules{$routeNr}{'fromscale'}= cv('ruleDefaultRouteFromScale');
$routeRules{$routeNr}{'toscale'}= cv('ruleDefaultRouteToScale'); $routeRules{$routeNr}{'toscale'}= cv('ruleDefaultRouteToScale');
while ( ( defined $line) and ( ! grep /^rule/i, $line) ) { while((defined $line)and(! grep /^rule/i, $line)){ my($k, $v)=($line =~ /(.+?)=(.+)/);
my ($k, $v) = ( $line =~ /(.+?)=(.+)/ ) ; if((! defined $k)or(! defined $v)){ print "WARNING: could not parse rule line: $line";
if ( ( ! defined $k ) or ( ! defined $v ) ) { } else{ $k = lc($k);
print "WARNING: could not parse rule line: $line" ;
}
else {
$k = lc ( $k ) ;
$routeRules{$routeNr}{$k}= $v; $routeRules{$routeNr}{$k}= $v;
if ( ! defined $vrp{$k} ) { print "WARNING: $k is not a valid route property!\n" ; } if(! defined $vrp{$k}){print "WARNING: $k is not a valid route property!\n";} } getRuleLine();
} } if(! defined $routeRules{$routeNr}{'type'}){die "ERROR: route rule without type detected!\n";}
getRuleLine() ;
}
if ( ! defined $routeRules{ $routeNr }{ 'type' } ) { die "ERROR: route rule without type detected!\n" ; }
}# route }# route
elsif ( grep /^rule config/i, $line ) { elsif(grep /^rule config/i, $line){ $crr++;
$crr++ ;
my($key, $value)=($line =~ /^rule config\s+(.+)=(.+)/i); my($key, $value)=($line =~ /^rule config\s+(.+)=(.+)/i);
if ( (defined $key) and (defined $value) ) { if((defined $key)and(defined $value)){ setConfigValue($key, $value);
setConfigValue ($key, $value) ; if(cv('debug')eq "1"){ print "RULES: config changed $key=$value\n";
if ( cv('debug') eq "1" ) { } } getRuleLine();
print "RULES: config changed $key=$value\n" ;
}
}
getRuleLine() ;
}# config }# config
else { else{ getRuleLine();
getRuleLine() ;
} }
} }
close($ruleFile); close($ruleFile);
print "rules read: $nrr nodes, $wrr ways, $arr areas, $rrr routes and $crr configs\n\n"; print "rules read: $nrr nodes, $wrr ways, $arr areas, $rrr routes and $crr configs\n\n";
} }
sub getNodeRule{ sub getNodeRule{
# takes tagref and returns hashref to rule properties # takes tagref and returns hashref to rule properties
my $tagRef = shift; my $tagRef = shift;
my $scale = getScale(); my $scale = getScale();
if ( cv('rulescaleset') != 0 ) { $scale = cv('rulescaleset') ; } if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');} # print "GNR: scale: $scale\n";
# print "GNR: scale: $scale\n" ;
my $ruleFound; undef $ruleFound; my $ruleFound; undef $ruleFound;
# print "\n"; # print "\n";
RUL2: foreach my $rule ( sort { $a <=> $b } keys %nodeRules) { RUL2: foreach my $rule(sort{$a <=> $b}keys %nodeRules){ # print "rule $rule\n";
# print "rule $rule\n" ;
if(($nodeRules{$rule}{'fromscale'}<= $scale)and($nodeRules{$rule}{'toscale'}>= $scale)){ if(($nodeRules{$rule}{'fromscale'}<= $scale)and($nodeRules{$rule}{'toscale'}>= $scale)){
my @kvs = split /;/, $nodeRules{$rule}{'keyvalue'}; my @kvs = split /;/, $nodeRules{$rule}{'keyvalue'};
my $allValid = 1; my $allValid = 1;
RUL1: foreach my $kv1(@kvs){# for each needed RUL1: foreach my $kv1(@kvs){# for each needed
my($k, $v)=($kv1 =~ /(.+)=(.+)/); my($k, $v)=($kv1 =~ /(.+)=(.+)/);
# print " looking for $k=$v\n"; # print " looking for $k=$v\n";
my $found = 0; my $found = 0;
RUL3: foreach my $tag ( @$tagRef) { RUL3: foreach my $tag(@$tagRef){ # print " actual kvs: $tag->[0]=$tag->[1]\n";
# print " actual kvs: $tag->[0]=$tag->[1]\n" ; if(($tag->[0] eq $k)and(($tag->[1] eq $v)or($v eq "*"))){ $found = 1;
if ( ( $tag->[0] eq $k) and ( ( $tag->[1] eq $v) or ( $v eq "*") ) ) {
$found = 1 ;
# print " FOUND\n"; # print " FOUND\n";
last RUL3; last RUL3;
} } }# tags
} # tags
if(! $found){ if(! $found){
$allValid = 0; $allValid = 0;
last RUL1; last RUL1;
} } }# kv1
} # kv1
if ( $allValid ) { if($allValid){ # print "ALL VALID\n";
# print "ALL VALID\n" ;
# return the first rule found # return the first rule found
$ruleFound = \%{$nodeRules{$rule}}; $ruleFound = \%{$nodeRules{$rule}};
last RUL2; last RUL2;
} }
}# scale }# scale
}# all rules }# all rules
@ -488,63 +412,47 @@ sub getNodeRule {
return($ruleFound); return($ruleFound);
} }
sub printNodeRules{ foreach my $n(sort{$a <=> $b} keys %nodeRules){ print "node rule $n\n";
sub printNodeRules { foreach my $v(sort keys %{$nodeRules{$n}}){ print " $v=$nodeRules{$n}{$v}\n";
foreach my $n ( sort { $a <=> $b } keys %nodeRules) {
print "node rule $n\n" ;
foreach my $v (sort keys %{$nodeRules{$n}}) {
print " $v=$nodeRules{$n}{$v}\n" ;
} }
print "\n"; print "\n";
} }}
}
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
sub getWayRule{ sub getWayRule{
# takes tagref and returns hashref to rule properties # takes tagref and returns hashref to rule properties
my $tagRef = shift; my $tagRef = shift;
my $scale = getScale(); my $scale = getScale();
if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');} if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');}
my $ruleFound; undef $ruleFound; my $ruleFound; undef $ruleFound;
RUL5: foreach my $rule ( sort { $a <=> $b } keys %wayRules) { RUL5: foreach my $rule(sort{$a <=> $b}keys %wayRules){ # print "rule $rule\n";
# print "rule $rule\n" ;
if(($wayRules{$rule}{'fromscale'}<= $scale)and($wayRules{$rule}{'toscale'}>= $scale)){ if(($wayRules{$rule}{'fromscale'}<= $scale)and($wayRules{$rule}{'toscale'}>= $scale)){
my @kvs = split /;/, $wayRules{$rule}{'keyvalue'}; my @kvs = split /;/, $wayRules{$rule}{'keyvalue'};
my $allValid = 1; my $allValid = 1;
RUL4: foreach my $kv1(@kvs){# for each needed RUL4: foreach my $kv1(@kvs){# for each needed
my($k, $v)=($kv1 =~ /(.+)=(.+)/); my($k, $v)=($kv1 =~ /(.+)=(.+)/);
# print " looking for $k=$v\n"; # print " looking for $k=$v\n";
my $found = 0; my $found = 0;
RUL6: foreach my $tag ( @$tagRef) { RUL6: foreach my $tag(@$tagRef){ # print " actual kvs: $tag->[0]=$tag->[1]\n";
# print " actual kvs: $tag->[0]=$tag->[1]\n" ; if(($tag->[0] eq $k)and(($tag->[1] eq $v)or($v eq "*"))){ $found = 1;
if ( ( $tag->[0] eq $k) and ( ( $tag->[1] eq $v) or ( $v eq "*") ) ) {
$found = 1 ;
# print " FOUND\n"; # print " FOUND\n";
last RUL6; last RUL6;
} } }# tags
} # tags
if(! $found){ if(! $found){
$allValid = 0; $allValid = 0;
last RUL4; last RUL4;
} } }# kv1
} # kv1
if ( $allValid ) { if($allValid){ # print "ALL VALID\n";
# print "ALL VALID\n" ;
# return the first rule found # return the first rule found
$ruleFound = \%{$wayRules{$rule}}; $ruleFound = \%{$wayRules{$rule}};
last RUL5; last RUL5;
} }
}# scale }# scale
}# all rules }# all rules
@ -553,64 +461,48 @@ sub getWayRule {
} }
sub printWayRules{ foreach my $n(sort{$a <=> $b} keys %wayRules){ print "way rule $n\n";
sub printWayRules { foreach my $v(sort keys %{$wayRules{$n}}){ print " $v=$wayRules{$n}{$v}\n";
foreach my $n ( sort { $a <=> $b } keys %wayRules) {
print "way rule $n\n" ;
foreach my $v (sort keys %{$wayRules{$n}}) {
print " $v=$wayRules{$n}{$v}\n" ;
} }
print "\n"; print "\n";
} }}
}
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
sub getAreaRule{ sub getAreaRule{
# takes tagref and returns hashref to rule properties # takes tagref and returns hashref to rule properties
my $tagRef = shift; my $tagRef = shift;
my $scale = getScale(); my $scale = getScale();
if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');} if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');}
my $ruleFound; undef $ruleFound; my $ruleFound; undef $ruleFound;
RUL8: foreach my $rule ( sort { $a <=> $b } keys %areaRules) { RUL8: foreach my $rule(sort{$a <=> $b}keys %areaRules){ # print "rule $rule\n";
# print "rule $rule\n" ;
if(($areaRules{$rule}{'fromscale'}<= $scale)and($areaRules{$rule}{'toscale'}>= $scale)){ if(($areaRules{$rule}{'fromscale'}<= $scale)and($areaRules{$rule}{'toscale'}>= $scale)){
my @kvs = split /;/, $areaRules{$rule}{'keyvalue'}; my @kvs = split /;/, $areaRules{$rule}{'keyvalue'};
my $allValid = 1; my $allValid = 1;
RUL7: foreach my $kv1(@kvs){# for each needed RUL7: foreach my $kv1(@kvs){# for each needed
my($k, $v)=($kv1 =~ /(.+)=(.+)/); my($k, $v)=($kv1 =~ /(.+)=(.+)/);
# print " looking for $k=$v\n"; # print " looking for $k=$v\n";
my $found = 0; my $found = 0;
RUL9: foreach my $tag ( @$tagRef) { RUL9: foreach my $tag(@$tagRef){ # print " actual kvs: $tag->[0]=$tag->[1]\n";
# print " actual kvs: $tag->[0]=$tag->[1]\n" ; if(($tag->[0] eq $k)and(($tag->[1] eq $v)or($v eq "*"))){ $found = 1;
if ( ( $tag->[0] eq $k) and ( ( $tag->[1] eq $v) or ( $v eq "*") ) ) {
$found = 1 ;
# print " FOUND\n"; # print " FOUND\n";
last RUL9; last RUL9;
} } }# tags
} # tags
if(! $found){ if(! $found){
$allValid = 0; $allValid = 0;
last RUL7; last RUL7;
} } }# kv1
} # kv1
if ( $allValid ) { if($allValid){ # print "ALL VALID\n";
# print "ALL VALID\n" ;
# return the first rule found # return the first rule found
$ruleFound = \%{$areaRules{$rule}}; $ruleFound = \%{$areaRules{$rule}};
last RUL8; last RUL8;
} }
}# scale }# scale
}# all rules }# all rules
@ -619,121 +511,65 @@ sub getAreaRule {
} }
sub printAreaRules{ foreach my $n(sort{$a <=> $b} keys %areaRules){ print "area rule $n\n";
sub printAreaRules { foreach my $v(sort keys %{$areaRules{$n}}){ print " $v=$areaRules{$n}{$v}\n";
foreach my $n ( sort { $a <=> $b } keys %areaRules) {
print "area rule $n\n" ;
foreach my $v (sort keys %{$areaRules{$n}}) {
print " $v=$areaRules{$n}{$v}\n" ;
} }
print "\n"; print "\n";
} }}
}
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
sub getRouteRule { sub getRouteRule{ my $tagRef = shift;
my $tagRef = shift ;
my $scale = getScale(); my $scale = getScale();
if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');} if(cv('rulescaleset')!= 0){$scale = cv('rulescaleset');}
my $ruleFound; undef $ruleFound; my $ruleFound; undef $ruleFound;
my $type = getValue("route", $tagRef); my $type = getValue("route", $tagRef);
if (defined $type) { if(defined $type){ # print " GRR: $type \n";
# print " GRR: $type \n" ; RULA: foreach my $r(sort{$a <=> $b} keys %routeRules){ # print " GRR: $routeRules{$r}{'type'}\n";
RULA: foreach my $r ( sort { $a <=> $b } keys %routeRules) { if($routeRules{$r}{'type'}eq $type){ if(($routeRules{$r}{'fromscale'}<= $scale)and($routeRules{$r}{'toscale'}>= $scale)){ $ruleFound = \%{$routeRules{$r}};
# print " GRR: $routeRules{$r}{'type'}\n" ;
if ($routeRules{$r}{'type'} eq $type) {
if ( ( $routeRules{$r}{'fromscale'} <= $scale) and ( $routeRules{$r}{'toscale'} >= $scale) ) {
$ruleFound = \%{ $routeRules{ $r } } ;
last RULA; last RULA;
} } }
} }
}
}
}
return $ruleFound; return $ruleFound;
} }
sub getRouteColors{ my %routeColors =();
sub getRouteColors { foreach my $n(keys %routeRules){ my $type = $routeRules{$n}{'type'};
my %routeColors = () ;
foreach my $n (keys %routeRules) {
my $type = $routeRules{$n}{'type'} ;
my $color = $routeRules{$n}{'color'}; my $color = $routeRules{$n}{'color'};
@{$routeColors{$type}}= split(/;/, $color); @{$routeColors{$type}}= split(/;/, $color);
} return \%routeColors;
} }
return \%routeColors ; sub printRouteRules{ foreach my $n(sort{$a <=> $b} keys %routeRules){ print "route rule $n\n";
} foreach my $v(sort keys %{$routeRules{$n}}){ print " $v=$routeRules{$n}{$v}\n";
sub printRouteRules {
foreach my $n ( sort { $a <=> $b } keys %routeRules) {
print "route rule $n\n" ;
foreach my $v (sort keys %{$routeRules{$n}}) {
print " $v=$routeRules{$n}{$v}\n" ;
} }
print "\n"; print "\n";
} }}
}
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
sub openRuleFile { sub openRuleFile{ my $fileName = shift;
my $fileName = shift ;
open($ruleFile, "<", $fileName)or die("ERROR: could not open rule file $fileName\n"); open($ruleFile, "<", $fileName)or die("ERROR: could not open rule file $fileName\n");
getRuleLine(); getRuleLine();
} }
sub getRuleLine{ $line = <$ruleFile>;
sub getRuleLine {
$line = <$ruleFile> ;
if(defined $line){ if(defined $line){
$line =~ s/\r//g; # remove dos/win char at line end $line =~ s/\r//g; # remove dos/win char at line end
} while((defined $line)and((length $line < 2)or(grep /^comment/i, $line)or(grep /^\#/i, $line))){ $line = <$ruleFile>;
} return $line;
} }
while ( (defined $line) and ( (length $line < 2) or ( grep /^comment/i, $line) or ( grep /^\#/i, $line) ) ) { sub adaptRuleSizes{ foreach my $r(keys %nodeRules){ foreach my $p(qw(iconSize labelOffset labelSize shieldSize size)){ if(defined $nodeRules{$r}{$p}){ if(grep /:/, $nodeRules{$r}{$p}){ my $old = $nodeRules{$r}{$p};
$line = <$ruleFile> ;
}
return $line ;
}
sub adaptRuleSizes {
foreach my $r ( keys %nodeRules ) {
foreach my $p ( qw (iconSize labelOffset labelSize shieldSize size) ) {
if ( defined $nodeRules{ $r }{ $p } ) {
if ( grep /:/, $nodeRules{ $r }{ $p } ) {
my $old = $nodeRules{ $r }{ $p } ;
my $new = scaleSize($nodeRules{$r}{$p}, $nodeRules{$r}{'fromscale'}, $nodeRules{$r}{'toscale'}); my $new = scaleSize($nodeRules{$r}{$p}, $nodeRules{$r}{'fromscale'}, $nodeRules{$r}{'toscale'});
$nodeRules{$r}{$p}= $new; $nodeRules{$r}{$p}= $new;
if ( cv('debug') eq "1" ) { if(cv('debug')eq "1"){ print "RULES/scale/node: $old -> $new\n";
print "RULES/scale/node: $old -> $new\n" ; } } } }} foreach my $r(keys %wayRules){ foreach my $p(qw(bordersize labelsize labeloffset size)){ if(defined $wayRules{$r}{$p}){ if(grep /:/, $wayRules{$r}{$p}){ my $kv = $wayRules{$r}{'keyvalue'};
}
}
}
}
}
foreach my $r ( keys %wayRules ) {
foreach my $p ( qw (bordersize labelsize labeloffset size ) ) {
if ( defined $wayRules{ $r }{ $p } ) {
if ( grep /:/, $wayRules{ $r }{ $p } ) {
my $kv = $wayRules{ $r }{ 'keyvalue' } ;
my $old = $wayRules{$r}{$p}; my $old = $wayRules{$r}{$p};
my $new = 0; my $new = 0;
$new = scaleSize($wayRules{$r}{$p}, $wayRules{$r}{'fromscale'}, $wayRules{$r}{'toscale'}); $new = scaleSize($wayRules{$r}{$p}, $wayRules{$r}{'fromscale'}, $wayRules{$r}{'toscale'});
$wayRules{$r}{$p}= $new; $wayRules{$r}{$p}= $new;
if ( cv('debug') eq "1" ) { if(cv('debug')eq "1"){ print "RULES/scale/way: $kv $p $old to $new\n";
print "RULES/scale/way: $kv $p $old to $new\n" ; } } } }}}
} sub scaleSize{ my($str, $fromScale, $toScale)= @_;
}
}
}
}
}
sub scaleSize {
my ($str, $fromScale, $toScale) = @_ ;
my @tmp = split /:/, $str; my @tmp = split /:/, $str;
my $lower = $tmp[0]; my $lower = $tmp[0];
my $upper = $tmp[1]; my $upper = $tmp[1];
@ -742,22 +578,14 @@ sub scaleSize {
my $scale = getScale(); my $scale = getScale();
if(cv('rulescaleset')ne "0"){$scale = cv('rulescaleset')}; if(cv('rulescaleset')ne "0"){$scale = cv('rulescaleset')};
if ( $scale < $fromScale) { if($scale < $fromScale){ $newSize = $upper;
$newSize = $upper ; } elsif($scale > $toScale){ $newSize = $lower;
} } else{ my $percent =($scale - $fromScale)/($toScale - $fromScale);
elsif ( $scale > $toScale ) {
$newSize = $lower ;
}
else {
my $percent = ( $scale - $fromScale ) / ($toScale - $fromScale) ;
$newSize = $upper - $percent *($upper - $lower); $newSize = $upper - $percent *($upper - $lower);
} } $newSize = int($newSize * 10)/ 10;
$newSize = int ( $newSize * 10 ) / 10 ;
return $newSize; return $newSize;
} }
sub createLegend{ sub createLegend{
# TODO Auto size # TODO Auto size
my $nx = 80; my $nx = 80;
@ -770,17 +598,7 @@ sub createLegend {
my $actualLine = 0; my $actualLine = 0;
my $preCount = 0; my $preCount = 0;
foreach my $n (keys %nodeRules) { foreach my $n(keys %nodeRules){ if($nodeRules{$n}{"legend"}eq "yes"){$preCount++;}} foreach my $n(keys %wayRules){ if($wayRules{$n}{"legend"}eq "yes"){$preCount++;}} foreach my $n(keys %areaRules){ if($areaRules{$n}{"legend"}eq "yes"){$preCount++;}} if(cv('debug')eq "1"){print "LEGEND: $preCount elements found\n";}
if ( $nodeRules{$n}{"legend"} eq "yes" ) { $preCount++ ; }
}
foreach my $n (keys %wayRules) {
if ( $wayRules{$n}{"legend"} eq "yes" ) { $preCount++ ; }
}
foreach my $n (keys %areaRules) {
if ( $areaRules{$n}{"legend"} eq "yes" ) { $preCount++ ; }
}
if ( cv('debug') eq "1" ) { print "LEGEND: $preCount elements found\n" ; }
my $sy = $preCount * $ey; my $sy = $preCount * $ey;
addToLayer("definitions", "<g id=\"legenddef\" width=\"$sx\" height=\"$sy\" >"); addToLayer("definitions", "<g id=\"legenddef\" width=\"$sx\" height=\"$sy\" >");
@ -788,67 +606,39 @@ sub createLegend {
my $svgString = "fill=\"$color\""; my $svgString = "fill=\"$color\"";
drawRect(0, 0, $sx, $sy, 0, $svgString, "definitions"); drawRect(0, 0, $sx, $sy, 0, $svgString, "definitions");
foreach my $n (keys %nodeRules) { foreach my $n(keys %nodeRules){ if($nodeRules{$n}{"legend"}eq "yes"){ my $x = $nx;
if ( $nodeRules{$n}{"legend"} eq "yes" ) {
my $x = $nx ;
my $y = $actualLine * $ey + $ny; my $y = $actualLine * $ey + $ny;
if ( ($nodeRules{$n}{'size'} > 0) and ($nodeRules{$n}{'icon'} eq "none") ) { if(($nodeRules{$n}{'size'}> 0)and($nodeRules{$n}{'icon'}eq "none")){ my $svgString = "";
my $svgString = "" ; if($nodeRules{$n}{'svgstring'}ne ""){ $svgString = $nodeRules{$n}{'svgstring'};
if ( $nodeRules{$n}{'svgstring'} ne "" ) { } else{ $svgString = "fill=\"$nodeRules{$n}{'color'}\"";
$svgString = $nodeRules{$n}{'svgstring'} ;
} }
else { if($nodeRules{$n}{'shape'}eq "circle"){ drawCircle($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions');
$svgString = "fill=\"$nodeRules{$n}{'color'}\"" ; } elsif($nodeRules{$n}{'shape'}eq "square"){ drawSquare($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions');
} elsif($nodeRules{$n}{'shape'}eq "triangle"){ drawTriangle($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions');
} elsif($nodeRules{$n}{'shape'}eq "diamond"){ drawDiamond($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions');
} }
if ( $nodeRules{$n}{'shape'} eq "circle") {
drawCircle ($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions') ;
}
elsif ( $nodeRules{$n}{'shape'} eq "square") {
drawSquare ($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions') ;
}
elsif ( $nodeRules{$n}{'shape'} eq "triangle") {
drawTriangle ($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions') ;
}
elsif ( $nodeRules{$n}{'shape'} eq "diamond") {
drawDiamond ($x, $y, 0, $nodeRules{$n}{'size'}, 0, $svgString, 'definitions') ;
}
my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef); my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef);
drawText($tx,($actualLine+0.5)* $ey + $fs/2, 0, $nodeRules{$n}{'legendlabel'}, $textSvgString, "definitions"); drawText($tx,($actualLine+0.5)* $ey + $fs/2, 0, $nodeRules{$n}{'legendlabel'}, $textSvgString, "definitions");
} } else{ # TODO icon
else { } $actualLine ++;
# TODO icon }}
} foreach my $w(keys %wayRules){ if($wayRules{$w}{"legend"}eq "yes"){ my($x1, $x2);
$actualLine ++ ;
}
}
foreach my $w (keys %wayRules) {
if ( $wayRules{$w}{"legend"} eq "yes" ) {
my ($x1, $x2) ;
$x1 = 0.5 * $nx; $x1 = 0.5 * $nx;
$x2 = 1.5 * $nx; $x2 = 1.5 * $nx;
my $y = $actualLine * $ey + $ny; my $y = $actualLine * $ey + $ny;
my($svg1, $layer1, $svg2, $layer2)= mwWays::createWayParameters($wayRules{$w}, 0, 0, 0); my($svg1, $layer1, $svg2, $layer2)= mwWays::createWayParameters($wayRules{$w}, 0, 0, 0);
my @coords =($x1, $y, $x2, $y); my @coords =($x1, $y, $x2, $y);
if ($svg2 ne "") { if($svg2 ne ""){ drawWay(\@coords, 0, $svg2, "definitions", undef);
drawWay ( \@coords, 0, $svg2, "definitions", undef ) ; } drawWay(\@coords, 0, $svg1, "definitions", undef);
}
drawWay ( \@coords, 0, $svg1, "definitions", undef ) ;
my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef); my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef);
drawText($tx,($actualLine+0.5)*$ey + $fs/2, 0, $wayRules{$w}{'legendlabel'}, $textSvgString, "definitions"); drawText($tx,($actualLine+0.5)*$ey + $fs/2, 0, $wayRules{$w}{'legendlabel'}, $textSvgString, "definitions");
$actualLine++; $actualLine++;
} }}
} foreach my $a(keys %areaRules){ if($areaRules{$a}{"legend"}eq "yes"){ my($x1, $x2);
foreach my $a (keys %areaRules) {
if ( $areaRules{$a}{"legend"} eq "yes" ) {
my ($x1, $x2) ;
my($y1, $y2); my($y1, $y2);
$x1 = 0.7 * $nx; $x1 = 0.7 * $nx;
$x2 = 1.3 * $nx; $x2 = 1.3 * $nx;
@ -860,19 +650,15 @@ sub createLegend {
my $base = $areaRules{$a}{'base'}; my $base = $areaRules{$a}{'base'};
my $svgString = $areaRules{$a}{'svgstring'}; my $svgString = $areaRules{$a}{'svgstring'};
if ( ($svgString eq "") and ($icon eq "none") ) { if(($svgString eq "")and($icon eq "none")){ $svgString = "fill=\"$color\" ";
$svgString = "fill=\"$color\" " ;
} }
my @coords =([$x1, $y1, $x2, $y1, $x2, $y2, $x1, $y2, $x1, $y1]); my @coords =([$x1, $y1, $x2, $y1, $x2, $y2, $x1, $y2, $x1, $y1]);
drawArea($svgString, $icon, \@coords, 0, "definitions"); drawArea($svgString, $icon, \@coords, 0, "definitions");
my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef); my $textSvgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), $fs, "black", undef, undef);
drawText($tx,($actualLine+0.5)*$ey + $fs/2, 0, $areaRules{$a}{'legendlabel'}, $textSvgString, "definitions"); drawText($tx,($actualLine+0.5)*$ey + $fs/2, 0, $areaRules{$a}{'legendlabel'}, $textSvgString, "definitions");
$actualLine++; $actualLine++;
} }}
}
addToLayer("definitions", "</g>"); addToLayer("definitions", "</g>");
@ -881,29 +667,18 @@ sub createLegend {
my($sizeX, $sizeY)= getDimensions(); my($sizeX, $sizeY)= getDimensions();
if ( cv('legend') eq "2") { if(cv('legend')eq "2"){ $posX = $sizeX - $sx;
$posX = $sizeX - $sx ;
$posY = 0; $posY = 0;
} }
if(cv('legend')eq "3"){ $posX = 0;
if ( cv('legend') eq "3") {
$posX = 0 ;
$posY = $sizeY - $sy; $posY = $sizeY - $sy;
} }
if(cv('legend')eq "4"){ $posX = $sizeX - $sx;
if ( cv('legend') eq "4") {
$posX = $sizeX - $sx ;
$posY = $sizeY - $sy; $posY = $sizeY - $sy;
} }
if((cv('legend')>=1)and(cv('legend')<=4)){ addToLayer("legend", "<use x=\"$posX\" y=\"$posY\" xlink:href=\"#legenddef\" />");
if ( (cv('legend') >=1) and (cv('legend')<=4) ) { } elsif(cv('legend')== 5){ # separate file
addToLayer ("legend", "<use x=\"$posX\" y=\"$posY\" xlink:href=\"#legenddef\" />") ;
}
elsif (cv('legend') == 5) {
# separate file
createLegendFile($sx, $sy, "_legend", "#legenddef"); createLegendFile($sx, $sy, "_legend", "#legenddef");
} }
} }
1; 1;

View File

@ -54,34 +54,21 @@ my @wns =() ;
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
sub addToDirectory { sub addToDirectory{ my($name, $square)= @_;
my ($name, $square) = @_ ; if(! defined $square){ $directory{$name}= 1;
if ( ! defined $square ) { } else{ $directory{$name}{$square}= 1;
$directory { $name } = 1 ; }}
sub getDirectory{ return \%directory;
} }
else { sub addWayLabel{#
$directory { $name } { $square } = 1 ;
}
}
sub getDirectory {
return \%directory ;
}
sub addWayLabel {
#
# collect all way label data before actual labeling # collect all way label data before actual labeling
# #
my($wayId, $name, $ruleRef)= @_; my($wayId, $name, $ruleRef)= @_;
push @{$wayLabels{$ruleRef}{$name}}, $wayId; push @{$wayLabels{$ruleRef}{$name}}, $wayId;
$ruleRefs{$ruleRef}= $ruleRef; $ruleRefs{$ruleRef}= $ruleRef;
if ( cv ('debug') eq "1" ) { if(cv('debug')eq "1"){ print "AWL: $wayId, $name, $ruleRef\n";
print "AWL: $wayId, $name, $ruleRef\n" ; }}
} sub preprocessWayLabels{#
}
sub preprocessWayLabels {
#
# preprocess way labels collected so far # preprocess way labels collected so far
# combine ways with same rule and name # combine ways with same rule and name
# split ways where direction in longitude changes so labels will be readable later # split ways where direction in longitude changes so labels will be readable later
@ -91,36 +78,26 @@ sub preprocessWayLabels {
my($lonRef, $latRef)= getNodePointers(); my($lonRef, $latRef)= getNodePointers();
my($memWayNodesRef, $memWayTagsRef)= getWayPointers(); my($memWayNodesRef, $memWayTagsRef)= getWayPointers();
foreach my $rule (keys %wayLabels) { foreach my $rule(keys %wayLabels){ my $ruleRef = $ruleRefs{$rule};
my $ruleRef = $ruleRefs{ $rule } ;
# print "PPWL: ruleNum $rule\n"; # print "PPWL: ruleNum $rule\n";
foreach my $name (keys %{$wayLabels{$rule}}) { foreach my $name(keys %{$wayLabels{$rule}}){ my(@ways)= @{$wayLabels{$rule}{$name}};
my (@ways) = @{$wayLabels{$rule}{$name}} ;
# print "PPWL: processing name $name, " . scalar(@ways). " ways\n"; # print "PPWL: processing name $name, " . scalar(@ways). " ways\n";
my($waysRef, $nodesRef)= buildRings(\@ways, 0); my($waysRef, $nodesRef)= buildRings(\@ways, 0);
my @segments = @$nodesRef; my @segments = @$nodesRef;
# print "PPWL: processing name $name, " . scalar(@segments). " segments\n"; # print "PPWL: processing name $name, " . scalar(@segments). " segments\n";
if(! grep /shield:/i, $name){ if(! grep /shield:/i, $name){
my @newSegments =(); my @newSegments =();
foreach my $segment (@segments) { foreach my $segment(@segments){ my @actual = @$segment;
my @actual = @$segment ;
# print "PPWL: Actual segment @actual\n"; # print "PPWL: Actual segment @actual\n";
my $found = 1; my $found = 1;
while ($found) { while($found){ $found = 0; my $sp = 0;
$found = 0 ; my $sp = 0 ;
# look for splitting point # look for splitting point
LABSP: for (my $i=1; $i<$#actual; $i++) { LABSP: for(my $i=1; $i<$#actual; $i++){ if((($$lonRef{$actual[$i-1]}> $$lonRef{$actual[$i]})and($$lonRef{$actual[$i+1]}> $$lonRef{$actual[$i]}))or
if ( (($$lonRef{$actual[$i-1]} > $$lonRef{$actual[$i]}) and ($$lonRef{$actual[$i+1]} > $$lonRef{$actual[$i]})) or (($$lonRef{$actual[$i-1]}< $$lonRef{$actual[$i]})and($$lonRef{$actual[$i+1]}< $$lonRef{$actual[$i]}))){ $found = 1;
(($$lonRef{$actual[$i-1]} < $$lonRef{$actual[$i]}) and ($$lonRef{$actual[$i+1]} < $$lonRef{$actual[$i]})) ) {
$found = 1 ;
$sp = $i; $sp = $i;
last LABSP; last LABSP;
} } } if($found == 1){ # print "\nname $name --- sp: $sp\n";
}
if ($found == 1) {
# print "\nname $name --- sp: $sp\n" ;
# print "ACTUAL BEFORE: @actual\n"; # print "ACTUAL BEFORE: @actual\n";
# create new seg # create new seg
my @newSegment = @actual[0..$sp]; my @newSegment = @actual[0..$sp];
@ -130,66 +107,42 @@ sub preprocessWayLabels {
# splice actual # splice actual
splice @actual, 0, $sp; splice @actual, 0, $sp;
# print "ACTUAL AFTER: @actual\n\n"; # print "ACTUAL AFTER: @actual\n\n";
} } @$segment = @actual;
} }
}
@$segment = @actual ;
}
push @segments, @newSegments; push @segments, @newSegments;
} }
foreach my $segment(@segments){ my(@wayNodes)= @$segment;
foreach my $segment (@segments) {
my (@wayNodes) = @$segment ;
my @points =(); my @points =();
if ($$lonRef{$wayNodes[0]} > $$lonRef{$wayNodes[-1]}) { if($$lonRef{$wayNodes[0]}> $$lonRef{$wayNodes[-1]}){ if((! grep /motorway/, $$ruleRef{'keyvalue'})and(! grep /trunk/, $$ruleRef{'keyvalue'})){ @wayNodes = reverse @wayNodes;
if ( ( ! grep /motorway/, $$ruleRef{'keyvalue'}) and ( ! grep /trunk/, $$ruleRef{'keyvalue'} ) ) { } }
@wayNodes = reverse @wayNodes ; foreach my $node(@wayNodes){ push @points, convert($$lonRef{$node}, $$latRef{$node});
} } # print "PPWL: segment @wayNodes\n";
}
foreach my $node (@wayNodes) {
push @points, convert ($$lonRef{$node}, $$latRef{$node}) ;
}
# print "PPWL: segment @wayNodes\n" ;
# print "PPWL: segment @points\n"; # print "PPWL: segment @points\n";
my($segmentLengthPixels)= 0; my($segmentLengthPixels)= 0;
for (my $i=0; $i<$#wayNodes; $i++) { for(my $i=0; $i<$#wayNodes; $i++){ my($x1, $y1)= convert($$lonRef{$wayNodes[$i]}, $$latRef{$wayNodes[$i]});
my ($x1, $y1) = convert ($$lonRef{$wayNodes[$i]}, $$latRef{$wayNodes[$i]}) ;
my($x2, $y2)= convert($$lonRef{$wayNodes[$i+1]}, $$latRef{$wayNodes[$i+1]}); my($x2, $y2)= convert($$lonRef{$wayNodes[$i+1]}, $$latRef{$wayNodes[$i+1]});
$segmentLengthPixels += sqrt(($x2-$x1)**2 +($y2-$y1)**2); $segmentLengthPixels += sqrt(($x2-$x1)**2 +($y2-$y1)**2);
} } # print "$rule, $wayIndexLabelSize\n";
# print "$rule, $wayIndexLabelSize\n" ;
my $labelLengthPixels = 0; my $labelLengthPixels = 0;
if (grep /shield/i, $$ruleRef{'label'} ) { if(grep /shield/i, $$ruleRef{'label'}){ $labelLengthPixels = $$ruleRef{'labelsize'};
$labelLengthPixels = $$ruleRef{'labelsize'} ;
# print "PPWL: len = $labelLengthPixels\n"; # print "PPWL: len = $labelLengthPixels\n";
} else{ $labelLengthPixels = length($name)* cv('ppc')/ 10 * $$ruleRef{'labelsize'};
} }
else {
$labelLengthPixels = length ($name) * cv('ppc') / 10 * $$ruleRef{'labelsize'} ;
}
# print "\nPPWL: name $name - ppc $ppc - size $ruleArray[$wayIndexLabelSize]\n"; # print "\nPPWL: name $name - ppc $ppc - size $ruleArray[$wayIndexLabelSize]\n";
# print "PPWL: wayLen $segmentLengthPixels\n"; # print "PPWL: wayLen $segmentLengthPixels\n";
# print "PPWL: labLen $labelLengthPixels\n"; # print "PPWL: labLen $labelLengthPixels\n";
push @labelCandidates, [$rule, $name, $segmentLengthPixels, $labelLengthPixels, [@points]]; push @labelCandidates, [$rule, $name, $segmentLengthPixels, $labelLengthPixels, [@points]];
if ( cv('debug') eq "1") { if(cv('debug')eq "1"){ print "PLC: $rule, $name, $segmentLengthPixels, $labelLengthPixels\n";
print "PLC: $rule, $name, $segmentLengthPixels, $labelLengthPixels\n" ; } } }}}
} sub subWay{#
}
}
}
}
sub subWay {
#
# takes coordinates and label information and creates new way/path # takes coordinates and label information and creates new way/path
# also calculates total angles / bends # also calculates total angles / bends
# #
@ -199,69 +152,49 @@ sub subWay {
my @dists; my @dists;
my @angles =(); my @angles =();
for (my $i=0; $i < $#coordinates; $i+=2) { for(my $i=0; $i < $#coordinates; $i+=2){ push @points, [$coordinates[$i],$coordinates[$i+1]];
push @points, [$coordinates[$i],$coordinates[$i+1]] ;
} }
$dists[0] = 0; $dists[0] = 0;
my $dist = 0; my $dist = 0;
if (scalar @points > 1) { if(scalar @points > 1){ for(my $i=1;$i<=$#points; $i++){ $dist = $dist + sqrt(($points[$i-1]->[0]-$points[$i]->[0])**2 +($points[$i-1]->[1]-$points[$i]->[1])**2);
for (my $i=1;$i<=$#points; $i++) {
$dist = $dist + sqrt ( ($points[$i-1]->[0]-$points[$i]->[0])**2 + ($points[$i-1]->[1]-$points[$i]->[1])**2 ) ;
$dists[$i] = $dist; $dists[$i] = $dist;
} }
} }
# calc angles at nodes # calc angles at nodes
if (scalar @points > 2) { if(scalar @points > 2){ for(my $i=1;$i<$#points; $i++){ $angles[$i] = angleMapgen($points[$i-1]->[0], $points[$i-1]->[1], $points[$i]->[0], $points[$i]->[1], $points[$i]->[0], $points[$i]->[1], $points[$i+1]->[0], $points[$i+1]->[1]);
for (my $i=1;$i<$#points; $i++) {
$angles[$i] = angleMapgen ($points[$i-1]->[0], $points[$i-1]->[1], $points[$i]->[0], $points[$i]->[1], $points[$i]->[0], $points[$i]->[1], $points[$i+1]->[0], $points[$i+1]->[1]) ;
} }
} }
my $wayLength = $dist; my $wayLength = $dist;
my $refPoint = $wayLength / 100 * $position; my $refPoint = $wayLength / 100 * $position;
my $labelStart; my $labelEnd; my $labelStart; my $labelEnd;
if($alignment eq "start"){# left if($alignment eq "start"){# left
$labelStart = $refPoint; $labelStart = $refPoint;
$labelEnd = $labelStart + $labLen; $labelEnd = $labelStart + $labLen;
} } if($alignment eq "end"){# right
if ($alignment eq "end") { # right
$labelEnd = $refPoint; $labelEnd = $refPoint;
$labelStart = $labelEnd - $labLen; $labelStart = $labelEnd - $labLen;
} } if($alignment eq "middle"){# center
if ($alignment eq "middle") { # center
$labelEnd = $refPoint + $labLen / 2; $labelEnd = $refPoint + $labLen / 2;
$labelStart = $refPoint - $labLen / 2; $labelStart = $refPoint - $labLen / 2;
} }
# find start and end segments # find start and end segments
my $startSeg; my $endSeg; my $startSeg; my $endSeg;
for (my $i=0; $i<$#points; $i++) { for(my $i=0; $i<$#points; $i++){ if(($dists[$i]<=$labelStart)and($dists[$i+1]>=$labelStart)){$startSeg = $i;} if(($dists[$i]<=$labelEnd)and($dists[$i+1]>=$labelEnd)){$endSeg = $i;}}
if ( ($dists[$i]<=$labelStart) and ($dists[$i+1]>=$labelStart) ) { $startSeg = $i ; }
if ( ($dists[$i]<=$labelEnd) and ($dists[$i+1]>=$labelEnd) ) { $endSeg = $i ; }
}
my @finalWay =(); my @finalWay =();
my $finalAngle = 0; my $finalAngle = 0;
my($sx, $sy)= triangleNode($coordinates[$startSeg*2], $coordinates[$startSeg*2+1], $coordinates[$startSeg*2+2], $coordinates[$startSeg*2+3], $labelStart-$dists[$startSeg], 0); my($sx, $sy)= triangleNode($coordinates[$startSeg*2], $coordinates[$startSeg*2+1], $coordinates[$startSeg*2+2], $coordinates[$startSeg*2+3], $labelStart-$dists[$startSeg], 0);
push @finalWay, $sx, $sy; push @finalWay, $sx, $sy;
if ($startSeg != $endSeg) { if($startSeg != $endSeg){ for(my $i=$startSeg+1; $i<=$endSeg; $i++){
for (my $i=$startSeg+1; $i<=$endSeg; $i++) {
push @finalWay, $coordinates[$i*2], $coordinates[$i*2+1]; push @finalWay, $coordinates[$i*2], $coordinates[$i*2+1];
$finalAngle += abs($angles[$i]); $finalAngle += abs($angles[$i]);
} }}
}
my($ex, $ey)= triangleNode($coordinates[$endSeg*2], $coordinates[$endSeg*2+1], $coordinates[$endSeg*2+2], $coordinates[$endSeg*2+3], $labelEnd-$dists[$endSeg], 0); my($ex, $ey)= triangleNode($coordinates[$endSeg*2], $coordinates[$endSeg*2+1], $coordinates[$endSeg*2+2], $coordinates[$endSeg*2+3], $labelEnd-$dists[$endSeg], 0);
push @finalWay, $ex, $ey; push @finalWay, $ex, $ey;
return(\@finalWay, $finalAngle); return(\@finalWay, $finalAngle);
} }
sub createWayLabels{#
sub createWayLabels {
#
# finally take all way label candidates and try to label them # finally take all way label candidates and try to label them
# #
@ -273,17 +206,12 @@ sub createWayLabels {
# calc ratio to label ways first where label just fits # calc ratio to label ways first where label just fits
# these will be drawn first # these will be drawn first
foreach my $candidate (@labelCandidates) { foreach my $candidate(@labelCandidates){ my $wLen = $candidate->[2];
my $wLen = $candidate->[2] ;
my $lLen = $candidate->[3]; my $lLen = $candidate->[3];
if ($wLen == 0) { $wLen = 1 ; } if($wLen == 0){$wLen = 1;} if($lLen == 0){$lLen = 1;} $candidate->[5] = $lLen / $wLen;
if ($lLen == 0) { $lLen = 1 ; } } @labelCandidates = sort{$b->[5] <=> $a->[5]}@labelCandidates;
$candidate->[5] = $lLen / $wLen ;
}
@labelCandidates = sort { $b->[5] <=> $a->[5] } @labelCandidates ;
foreach my $candidate (@labelCandidates) { foreach my $candidate(@labelCandidates){ my $ruleRef = $ruleRefs{$candidate->[0]};
my $ruleRef = $ruleRefs{ $candidate->[0] } ;
my $name = $candidate->[1]; my $name = $candidate->[1];
my $wLen = $candidate->[2]; my $wLen = $candidate->[2];
my $lLen = $candidate->[3]; my $lLen = $candidate->[3];
@ -291,37 +219,25 @@ sub createWayLabels {
my $toLabel = 1; my $toLabel = 1;
if((cv('declutter')eq "1")and($points[0] > $points[-2])and if((cv('declutter')eq "1")and($points[0] > $points[-2])and
( ( grep /motorway/i, $$ruleRef{'keyvalue'}) or (grep /trunk/i, $$ruleRef{'keyvalue'}) ) ) { ((grep /motorway/i, $$ruleRef{'keyvalue'})or(grep /trunk/i, $$ruleRef{'keyvalue'}))){ $toLabel = 0;
$toLabel = 0 ;
} }
# wns? # wns?
if ( ($lLen > $wLen * 0.95) and ( cv('wns') > 0 ) ) { if(($lLen > $wLen * 0.95)and(cv('wns')> 0)){ if(($toLabel != 0)and(! grep /shield:/i, $name)and(wayVisible(\@points))){ if(! defined $wnsUnique{$name}){ my $oldName = $name;
if ( ( $toLabel != 0 ) and ( ! grep /shield:/i, $name) and ( wayVisible( \@points ) ) ) {
if ( ! defined $wnsUnique{$name} ) {
my $oldName = $name ;
$wnsUnique{$name}= 1; $wnsUnique{$name}= 1;
push @wns, [ $wnsNumber, $name]; push @wns, [ $wnsNumber, $name];
$name = $wnsNumber; $name = $wnsNumber;
$lLen = cv('ppc')/ 10 * $$ruleRef{'labelsize'}* length($name); $lLen = cv('ppc')/ 10 * $$ruleRef{'labelsize'}* length($name);
# print "WNS: $oldName - $name\n"; # print "WNS: $oldName - $name\n";
$wnsNumber++; $wnsNumber++;
} } } }
}
}
if(($lLen > $wLen*0.95)or($toLabel == 0)){ # label too long
if ( ($lLen > $wLen*0.95) or ($toLabel == 0) ) {
# label too long
$numWayLabelsOmitted++; $numWayLabelsOmitted++;
$notDrawnLabels{$name}= 1; $notDrawnLabels{$name}= 1;
} } else{
else {
if(grep /shield:/i, $name){ if(grep /shield:/i, $name){
createShield($name, $$ruleRef{'labelsize'}); createShield($name, $$ruleRef{'labelsize'});
my $shieldMaxSize = getMaxShieldSize($name); my $shieldMaxSize = getMaxShieldSize($name);
@ -329,15 +245,12 @@ sub createWayLabels {
my $numShields = int($wLen /($shieldMaxSize * 12)); my $numShields = int($wLen /($shieldMaxSize * 12));
# if($numShields > 4){$numShields = 4;} # if($numShields > 4){$numShields = 4;}
if ($numShields > 0) { if($numShields > 0){ my $step = $wLen /($numShields + 1);
my $step = $wLen / ($numShields + 1) ;
my $position = $step; my $position = $step;
while ($position < $wLen) { while($position < $wLen){ my($x, $y)= getPointOfWay(\@points, $position);
my ($x, $y) = getPointOfWay (\@points, $position) ;
# print "XY: $x, $y\n"; # print "XY: $x, $y\n";
if(! coordsOut($x, $y)){ if(! coordsOut($x, $y)){
# place shield if not occupied # place shield if not occupied
my($ssx, $ssy)= getShieldSizes($name); my($ssx, $ssy)= getShieldSizes($name);
@ -348,29 +261,21 @@ sub createWayLabels {
# print "AREA: $x2, $y2, $x2+$lLen, $y2+$lLen\n"; # print "AREA: $x2, $y2, $x2+$lLen, $y2+$lLen\n";
if(! mwLabel::boxAreaOccupied($x2, $y2+$ssy, $x2+$ssx, $y2)){ if(! mwLabel::boxAreaOccupied($x2, $y2+$ssy, $x2+$ssx, $y2)){
my $id = getShieldId($name); my $id = getShieldId($name);
addToLayer("shields", "<use xlink:href=\"#$id\" x=\"$x2\" y=\"$y2\" />"); addToLayer("shields", "<use xlink:href=\"#$id\" x=\"$x2\" y=\"$y2\" />");
mwLabel::boxOccupyArea($x2, $y2+$ssy, $x2+$ssx, $y2, 0, 3); mwLabel::boxOccupyArea($x2, $y2+$ssy, $x2+$ssx, $y2, 0, 3);
} } }
}
$position += $step; $position += $step;
} } }
}
}# shield }# shield
else{ else{
# print "$wLen - $name - $lLen\n"; # print "$wLen - $name - $lLen\n";
my $numLabels = int($wLen /(4 * $lLen)); my $numLabels = int($wLen /(4 * $lLen));
if ($numLabels < 1) { $numLabels = 1 ; } if($numLabels < 1){$numLabels = 1;} if($numLabels > 4){$numLabels = 4;}
if ($numLabels > 4) { $numLabels = 4 ; } if($numLabels == 1){ # print "LA: $name *1*\n";
if ($numLabels == 1) {
# print "LA: $name *1*\n" ;
my $spare = 0.95 * $wLen - $lLen; my $spare = 0.95 * $wLen - $lLen;
my $sparePercentHalf = $spare /($wLen*0.95)*100 / 2; my $sparePercentHalf = $spare /($wLen*0.95)*100 / 2;
my $startOffset = 50 - $sparePercentHalf; my $startOffset = 50 - $sparePercentHalf;
@ -380,18 +285,14 @@ sub createWayLabels {
my @positions =(); my @positions =();
my $actual = $startOffset; my $actual = $startOffset;
my $size = $$ruleRef{'labelsize'}; my $size = $$ruleRef{'labelsize'};
while ($actual <= $endOffset) { while($actual <= $endOffset){ my($ref, $angle)= subWay(\@points, $lLen, "middle", $actual);
my ($ref, $angle) = subWay (\@points, $lLen, "middle", $actual) ;
my @way = @$ref; my @way = @$ref;
# my($col)= lineCrossings(\@way); # my($col)= lineCrossings(\@way);
my($col)= boxLinesOccupied(\@way, $size/2); my($col)= boxLinesOccupied(\@way, $size/2);
# calc quality of position. distance from middle and bend angles # calc quality of position. distance from middle and bend angles
my $quality = $angle + abs(50 - $actual); my $quality = $angle + abs(50 - $actual);
if ($col == 0) { push @positions, ["middle", $actual, $quality] ; } if($col == 0){push @positions, ["middle", $actual, $quality];} $actual += $step;
$actual += $step ; } if(scalar @positions > 0){ $drawnLabels{$name}= 1;
}
if (scalar @positions > 0) {
$drawnLabels { $name } = 1 ;
# sort by quality and take best one # sort by quality and take best one
@positions = sort{$a->[2] <=> $b->[2]}@positions; @positions = sort{$a->[2] <=> $b->[2]}@positions;
my($pos)= shift @positions; my($pos)= shift @positions;
@ -401,8 +302,7 @@ sub createWayLabels {
# TODO IF INSIDE # TODO IF INSIDE
# print "final way @finalWay\n"; # print "final way @finalWay\n";
if ( ! coordsOut (@finalWay) ) { if(! coordsOut(@finalWay)){ my $pathName = "Path" . $pathNumber; $pathNumber++;
my $pathName = "Path" . $pathNumber ; $pathNumber++ ;
createPath($pathName, \@finalWay, "definitions"); createPath($pathName, \@finalWay, "definitions");
my $size = $$ruleRef{'labelsize'}; my $size = $$ruleRef{'labelsize'};
@ -419,31 +319,22 @@ sub createWayLabels {
pathText($svgText, $name, $pathName, $$ruleRef{'labeloffset'}, $pos->[0], 50, "text"); pathText($svgText, $name, $pathName, $$ruleRef{'labeloffset'}, $pos->[0], 50, "text");
boxOccupyLines(\@finalWay, $size/2, 3); boxOccupyLines(\@finalWay, $size/2, 3);
} } } else{ $numWayLabelsOmitted++;
} } } else{# more than one label
else {
$numWayLabelsOmitted++ ;
}
}
else { # more than one label
# print "LA: $name *X*\n"; # print "LA: $name *X*\n";
my $labelDrawn = 0; my $labelDrawn = 0;
my $interval = int(100 /($numLabels + 1)); my $interval = int(100 /($numLabels + 1));
my @positions =(); my @positions =();
for (my $i=1; $i<=$numLabels; $i++) { for(my $i=1; $i<=$numLabels; $i++){ push @positions, $i * $interval;
push @positions, $i * $interval ;
} }
foreach my $position(@positions){ my($refFinal, $angle)= subWay(\@points, $lLen, "middle", $position);
foreach my $position (@positions) {
my ($refFinal, $angle) = subWay (\@points, $lLen, "middle", $position) ;
my(@finalWay)= @$refFinal; my(@finalWay)= @$refFinal;
# my($collision)= lineCrossings(\@finalWay); # my($collision)= lineCrossings(\@finalWay);
my $size = $$ruleRef{'labelsize'}; my $size = $$ruleRef{'labelsize'};
my($collision)= boxLinesOccupied(\@finalWay, $size/2); my($collision)= boxLinesOccupied(\@finalWay, $size/2);
if ($collision == 0) { if($collision == 0){ $labelDrawn = 1;
$labelDrawn = 1 ;
$drawnLabels{$name}= 1; $drawnLabels{$name}= 1;
my $pathName = "Path" . $pathNumber; $pathNumber++; my $pathName = "Path" . $pathNumber; $pathNumber++;
@ -466,51 +357,30 @@ sub createWayLabels {
} } else{ # print "INFO: $name labeled less often than desired.\n";
else { } } if($labelDrawn == 0){ $notDrawnLabels{$name}= 1;
# print "INFO: $name labeled less often than desired.\n" ; } } } }} my $labelFileName = cv('out');
}
}
if ($labelDrawn == 0) {
$notDrawnLabels { $name } = 1 ;
}
}
}
}
}
my $labelFileName = cv('out') ;
$labelFileName =~ s/\.svg/_NotDrawnLabels.txt/; $labelFileName =~ s/\.svg/_NotDrawnLabels.txt/;
my $labelFile; my $labelFile;
open($labelFile, ">", $labelFileName)or die("couldn't open label file $labelFileName"); open($labelFile, ">", $labelFileName)or die("couldn't open label file $labelFileName");
print $labelFile "Not drawn labels\n\n"; print $labelFile "Not drawn labels\n\n";
foreach my $labelName (sort keys %notDrawnLabels) { foreach my $labelName(sort keys %notDrawnLabels){ if(!defined $drawnLabels{$labelName}){ print $labelFile "$labelName\n";
if (!defined $drawnLabels { $labelName } ) { }} close($labelFile);
print $labelFile "$labelName\n" ;
}
}
close ($labelFile) ;
# way name substitutes legend? # way name substitutes legend?
if ( cv('wns') > 0 ) { if(cv('wns')> 0){ createWNSLegend();
createWNSLegend() ;
} }
} }
# ------------------------------------------------------------ # ------------------------------------------------------------
sub createWNSLegend { sub createWNSLegend{ my $size = cv('wnssize');
my $size = cv('wnssize') ;
my $color = cv('wnscolor'); my $color = cv('wnscolor');
# TODO max len auto size # TODO max len auto size
my $maxLen = 0; my $maxLen = 0;
foreach my $e ( @wns ) { foreach my $e(@wns){ if(length $e->[1] > $maxLen){$maxLen = length $e->[1];}}
if ( length $e->[1] > $maxLen ) { $maxLen = length $e->[1] ; }
}
my $sy = 2 * $size; my $sy = 2 * $size;
my $sx =(4 + $maxLen)* $size / 10 * cv('ppc'); my $sx =(4 + $maxLen)* $size / 10 * cv('ppc');
my $tx = 4 * $size / 10 * cv('ppc'); my $tx = 4 * $size / 10 * cv('ppc');
@ -532,14 +402,12 @@ sub createWNSLegend {
drawRect(0, 0, $sizeX, $sizeY, 0, $svgString, "definitions"); drawRect(0, 0, $sizeX, $sizeY, 0, $svgString, "definitions");
$svgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), undef, undef, cv('wnssize'), cv('wnscolor'), undef, undef); $svgString = createTextSVG(cv('elementFontFamily'), cv('elementFont'), undef, undef, cv('wnssize'), cv('wnscolor'), undef, undef);
foreach my $e ( @wns ) { foreach my $e(@wns){ my $y = $actualLine * $sy + $ty;
my $y = $actualLine * $sy + $ty ;
drawText($nx, $y, 0, $e->[0], $svgString, "definitions"); drawText($nx, $y, 0, $e->[0], $svgString, "definitions");
drawText($tx, $y, 0, $e->[1], $svgString, "definitions"); drawText($tx, $y, 0, $e->[1], $svgString, "definitions");
$actualLine++; $actualLine++;
} }
addToLayer("definitions", "</g>"); addToLayer("definitions", "</g>");
my $posX = 0; my $posX = 0;
@ -549,30 +417,19 @@ sub createWNSLegend {
($sizeX, $sizeY)= getDimensions(); ($sizeX, $sizeY)= getDimensions();
$sy = $sy * scalar @wns; $sy = $sy * scalar @wns;
if ( cv('wns') eq "2") { if(cv('wns')eq "2"){ $posX = $sizeX - $sx;
$posX = $sizeX - $sx ;
$posY = 0; $posY = 0;
} }
if(cv('wns')eq "3"){ $posX = 0;
if ( cv('wns') eq "3") {
$posX = 0 ;
$posY = $sizeY - $sy; $posY = $sizeY - $sy;
} }
if(cv('wns')eq "4"){ $posX = $sizeX - $sx;
if ( cv('wns') eq "4") {
$posX = $sizeX - $sx ;
$posY = $sizeY - $sy; $posY = $sizeY - $sy;
} }
if((cv('wns')>=1)and(cv('wns')<= 4)){ addToLayer("wns", "<use x=\"$posX\" y=\"$posY\" xlink:href=\"#wnsdef\" />");
if ( ( cv('wns') >=1 ) and ( cv('wns') <= 4 ) ) {
addToLayer ("wns", "<use x=\"$posX\" y=\"$posY\" xlink:href=\"#wnsdef\" />") ;
} }
if(cv('wns')eq "5"){ createLegendFile($sx, $sy, "_wns", "#wnsdef");
if ( cv('wns') eq "5") { }}
createLegendFile ($sx, $sy, "_wns", "#wnsdef") ;
}
}
1; 1;

208
mwWays.pm
View File

@ -51,156 +51,96 @@ my $areaLabelsOmitted = 0 ;
my @coastWays =(); my @coastWays =();
sub processWays{ sub processWays{
print "drawing ways/areas...\n"; print "drawing ways/areas...\n";
my $nodesRef; my $tagRef; my $nodesRef; my $tagRef;
($nodesRef, $tagRef)= getWayPointers(); ($nodesRef, $tagRef)= getWayPointers();
my($lonRef, $latRef, $nodeTagRef)= getNodePointers(); my($lonRef, $latRef, $nodeTagRef)= getNodePointers();
foreach my $wayId (keys %$nodesRef) { foreach my $wayId(keys %$nodesRef){ my @tags = @{$$tagRef{$wayId}};
my @tags = @{ $$tagRef{$wayId} } ;
my $tagsString = ""; my $tagsString = "";
# coast # coast
my $v = getValue("natural", \@tags); my $v = getValue("natural", \@tags);
if ( (defined $v) and ($v eq "coastline") ) { if((defined $v)and($v eq "coastline")){ push @coastWays, $wayId;
push @coastWays, $wayId ;
} }
# WAYS # WAYS
my $ruleRef = getWayRule(\@tags); my $ruleRef = getWayRule(\@tags);
if (defined $ruleRef) { if(defined $ruleRef){ my @nodes = @{$$nodesRef{$wayId}};
my @nodes = @{ $$nodesRef{ $wayId } } ;
my $layer = getValue("layer", $$tagRef{$wayId}); my $layer = getValue("layer", $$tagRef{$wayId});
if(! defined $layer){$layer = 0;} if(! defined $layer){$layer = 0;}
# TODO check for numeric!!! # TODO check for numeric!!!
my $direction = 0; my $direction = 0;
my $ow = getValue("oneway", $$tagRef{$wayId}); my $ow = getValue("oneway", $$tagRef{$wayId});
if (defined $ow) { if(defined $ow){ if(($ow eq "yes")or($ow eq "true")or($ow eq "1")){$direction = 1;} if($ow eq "-1"){$direction = -1;} }
if (($ow eq "yes") or ($ow eq "true") or ($ow eq "1")) { $direction = 1 ; }
if ($ow eq "-1") { $direction = -1 ; }
}
my $bridge = getValue("bridge", $$tagRef{$wayId}); my $bridge = getValue("bridge", $$tagRef{$wayId});
if (defined $bridge) { if(defined $bridge){ if(($bridge eq "yes")or($bridge eq "true")){$bridge = 1;}else{$bridge = 0;} } else{$bridge = 0;}
if (($bridge eq "yes") or ($bridge eq "true")) { $bridge = 1 ; } else { $bridge = 0 ; }
}
else { $bridge = 0 ; }
my $tunnel = getValue("tunnel", $$tagRef{$wayId}); my $tunnel = getValue("tunnel", $$tagRef{$wayId});
if (defined $tunnel) { if(defined $tunnel){ if(($tunnel eq "yes")or($tunnel eq "true")){$tunnel = 1;}else{$tunnel = 0;} } else{$tunnel = 0;}
if (($tunnel eq "yes") or ($tunnel eq "true")) { $tunnel = 1 ; } else { $tunnel = 0 ; }
}
else { $tunnel = 0 ; }
my($svg1, $layer1, $svg2, $layer2)= createWayParameters($ruleRef, $layer, $bridge, $tunnel); my($svg1, $layer1, $svg2, $layer2)= createWayParameters($ruleRef, $layer, $bridge, $tunnel);
drawWay(\@nodes, 1, $svg1, undef, $layer1); drawWay(\@nodes, 1, $svg1, undef, $layer1);
if ($svg2 ne "") { if($svg2 ne ""){ drawWay(\@nodes, 1, $svg2, undef, $layer2);
drawWay ( \@nodes, 1, $svg2, undef, $layer2 ) ;
} }
my $size = $$ruleRef{'size'}; my $size = $$ruleRef{'size'};
if ( ( cv('oneways') eq "1" ) and ($direction != 0) ) { if((cv('oneways')eq "1")and($direction != 0)){ addOnewayArrows(\@nodes, $direction, $size, $layer);
addOnewayArrows (\@nodes, $direction, $size, $layer) ;
} }
# LABEL WAY # LABEL WAY
if ( cv('ignorelabels') eq "0" ) { if(cv('ignorelabels')eq "0"){ if($$ruleRef{'label'}ne "none"){
if ($$ruleRef{'label'} ne "none") {
my $name = ""; my $ref1; my @names; my $name = ""; my $ref1; my @names;
if (grep /shield/i, $$ruleRef{'label'} ) { if(grep /shield/i, $$ruleRef{'label'}){ ($name, $ref1)= createLabel(\@tags, "ref",0, 0);
($name, $ref1) = createLabel (\@tags, "ref",0, 0) ;
my $ref = $name; my $ref = $name;
if (grep /;/, $ref) { if(grep /;/, $ref){ my @a = split /;/, $ref;
my @a = split /;/, $ref ;
$ref = $a[0]; $ref = $a[0];
} }
if($ref ne ""){ @names =($ref);
if ($ref ne "") {
@names = ($ref) ;
$name = $$ruleRef{'label'}. ":$ref"; $name = $$ruleRef{'label'}. ":$ref";
# print "DRAW WAY: name set to $name\n"; # print "DRAW WAY: name set to $name\n";
} } else{ @names =();
else {
@names = () ;
$name = ""; $name = "";
} }
# print "WAY: name for shield >$name<\n"; # print "WAY: name for shield >$name<\n";
} } else{ ($name, $ref1)= createLabel(\@tags, $$ruleRef{'label'}, 0, 0);
else {
($name, $ref1) = createLabel (\@tags, $$ruleRef{'label'}, 0, 0) ;
@names = @$ref1; @names = @$ref1;
$name = labelTransform($name, $$ruleRef{'labeltransform'}); $name = labelTransform($name, $$ruleRef{'labeltransform'});
} }
if((cv('nolabel')eq "1")and($name eq "")){$name = "NO LABEL";} if((cv('nolabel')eq "1")and($name eq "")){$name = "NO LABEL";}
if($name ne ""){ if($name ne ""){
addWayLabel($wayId, $name, $ruleRef); addWayLabel($wayId, $name, $ruleRef);
} } if((cv('dir')eq "1")and($$ruleRef{'direxclude'}eq "no")){ if(cv('grid')> 0){ foreach my $node(@nodes){ foreach my $name(@names){ my $sq = gridSquare($$lonRef{$node}, $$latRef{$node}, cv('grid'));
if ( ( cv('dir') eq "1") and ( $$ruleRef{'direxclude'} eq "no") ) { if(defined $sq){ addToDirectory($name, $sq);
if ( cv('grid') > 0) { } } } } else{ foreach my $name(@names){ addToDirectory($name, undef);
foreach my $node ( @nodes ) { } } } } # label
foreach my $name (@names) {
my $sq = gridSquare($$lonRef{$node}, $$latRef{$node}, cv('grid') ) ;
if (defined $sq) {
addToDirectory($name, $sq) ;
}
}
}
}
else {
foreach my $name (@names) {
addToDirectory ($name, undef) ;
}
}
}
} # label
}# ignorelabels }# ignorelabels
} }
# AREAS # AREAS
$ruleRef = getAreaRule(\@tags); $ruleRef = getAreaRule(\@tags);
my @nodes = @{$$nodesRef{$wayId}}; my @nodes = @{$$nodesRef{$wayId}};
if ( (defined $ruleRef) and ($nodes[0] == $nodes[-1]) ) { if((defined $ruleRef)and($nodes[0] == $nodes[-1])){ my $color = $$ruleRef{'color'};
my $color = $$ruleRef{'color'} ;
my $icon = $$ruleRef{'icon'}; my $icon = $$ruleRef{'icon'};
my $base = $$ruleRef{'base'}; my $base = $$ruleRef{'base'};
my $svgString = $$ruleRef{'svgstring'}; my $svgString = $$ruleRef{'svgstring'};
my $size = areaSize(\@nodes); my $size = areaSize(\@nodes);
my @ways = [@nodes]; my @ways = [@nodes];
if ( ($svgString eq "") and ($icon eq "none") ) { if(($svgString eq "")and($icon eq "none")){ $svgString = "fill=\"$color\" ";
$svgString = "fill=\"$color\" " ;
} }
if($size > cv('minareasize')){ if($base eq "yes"){ drawArea($svgString, $icon, \@ways, 1, "base");
if ($size > cv('minareasize') ) { } else{ drawArea($svgString, $icon, \@ways, 1, "area");
if ($base eq "yes") { } $areasDrawn++;
drawArea ($svgString, $icon, \@ways, 1, "base") ;
}
else {
drawArea ($svgString, $icon, \@ways, 1, "area") ;
}
$areasDrawn++ ;
# DRAW label # DRAW label
if ( $$ruleRef{'label'} ne "none" ) { if($$ruleRef{'label'}ne "none"){ $areaLabels++;
$areaLabels++ ; if($size > cv('minarealabelsize')){ # text
if ($size > cv('minarealabelsize') ) {
# text
my($name, $ref1)= createLabel(\@tags, $$ruleRef{'label'},0, 0); my($name, $ref1)= createLabel(\@tags, $$ruleRef{'label'},0, 0);
$name = labelTransform($name, $$ruleRef{'labeltransform'}); $name = labelTransform($name, $$ruleRef{'labeltransform'});
@ -220,39 +160,26 @@ sub processWays {
my $svgText = createTextSVG($labelFontFamily, $labelFont, $labelBold, $labelItalic, $labelSize, $color, $labelHalo, $labelHaloColor); my $svgText = createTextSVG($labelFontFamily, $labelFont, $labelBold, $labelItalic, $labelSize, $color, $labelHalo, $labelHaloColor);
mwLabel::placeLabelAndIcon($lon, $lat, 0, 0, $name, $svgText, "none", 0, 0, "arealabels"); mwLabel::placeLabelAndIcon($lon, $lat, 0, 0, $name, $svgText, "none", 0, 0, "arealabels");
} } else{ $areaLabelsOmitted++;
else { } }
$areaLabelsOmitted++ ;
}
}
} else{ $areasOmitted++;
} }
else {
$areasOmitted++ ;
}
}# Area }# Area
} }
print "$areasDrawn areas drawn, $areasOmitted omitted because they are too small\n"; print "$areasDrawn areas drawn, $areasOmitted omitted because they are too small\n";
print "$areaLabels area labels total, $areaLabelsOmitted omitted because belonging areas were too small\n"; print "$areaLabels area labels total, $areaLabelsOmitted omitted because belonging areas were too small\n";
my $cw = scalar @coastWays; my $cw = scalar @coastWays;
if(cv('verbose')){print "$cw coast line ways found.\n";} if(cv('verbose')){print "$cw coast line ways found.\n";}
preprocessWayLabels(); preprocessWayLabels();
createWayLabels(); createWayLabels();
if ($cw > 0) { if($cw > 0){ processCoastLines(\@coastWays);
processCoastLines (\@coastWays) ; }}
}
}
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
sub createWayParameters { sub createWayParameters{ my($ruleRef, $layer, $bridge, $tunnel)= @_;
my ($ruleRef, $layer, $bridge, $tunnel) = @_ ;
my $svg1 = ""; my $layer1 = 0; my $svg1 = ""; my $layer1 = 0;
my $svg2 = ""; my $layer2 = 0; my $svg2 = ""; my $layer2 = 0;
@ -281,12 +208,9 @@ sub createWayParameters {
@{$dashDefinition{34}}=("butt", "4,20"); @{$dashDefinition{34}}=("butt", "4,20");
@{$dashDefinition{35}}=("butt", "8,20"); @{$dashDefinition{35}}=("butt", "8,20");
if ( cv ('autobridge') eq "0" ) { if(cv('autobridge')eq "0"){ $layer = 0;
$layer = 0 ;
} }
if(($$ruleRef{'svgstringtop'}ne "")or($$ruleRef{'svgstringbottom'}ne "")){ if(($$ruleRef{'svgstringtop'}ne "")or($$ruleRef{'svgstringbottom'}ne "")){
$svg1 = $$ruleRef{'svgstringtop'}; $svg1 = $$ruleRef{'svgstringtop'};
$svg2 = $$ruleRef{'svgstringbottom'}; $svg2 = $$ruleRef{'svgstringbottom'};
@ -294,9 +218,7 @@ sub createWayParameters {
$layer1 = $layer; $layer1 = $layer;
$layer2 = $layer; $layer2 = $layer;
} } else{
else {
my $size = $$ruleRef{'size'}; my $size = $$ruleRef{'size'};
my $color = $$ruleRef{'color'}; my $color = $$ruleRef{'color'};
@ -304,62 +226,41 @@ sub createWayParameters {
my $lj = "round"; my $lj = "round";
my $dash = ""; my $dash = "";
if ( $$ruleRef{'dash'} ne "" ) { if($$ruleRef{'dash'}ne ""){ if(! grep /,/, $$ruleRef{'dash'}){ my @ds = @{$dashDefinition{$$ruleRef{'dash'}}};
if ( ! grep /,/, $$ruleRef{'dash'}) {
my @ds = @{$dashDefinition{ $$ruleRef{'dash'} } } ;
$lc = $ds[0]; $lc = $ds[0];
my $style = $ds[1]; my $style = $ds[1];
$dash = "stroke-dasharray=\"$style\" "; $dash = "stroke-dasharray=\"$style\" ";
} } else{ $lc = $$ruleRef{'dashcap'};
else {
$lc = $$ruleRef{'dashcap'} ;
my $style = $$ruleRef{'dash'}; my $style = $$ruleRef{'dash'};
$dash = "stroke-dasharray=\"$style\""; $dash = "stroke-dasharray=\"$style\"";
} } }
} # top(actual way) $svg1 = "stroke=\"$color\" stroke-width=\"$size\" stroke-linecap=\"$lc\" fill=\"none\" stroke-linejoin=\"$lj\" " . $dash;
# top (actual way)
$svg1 = "stroke=\"$color\" stroke-width=\"$size\" stroke-linecap=\"$lc\" fill=\"none\" stroke-linejoin=\"$lj\" " . $dash ;
$layer1 = $layer + $size / 100; $layer1 = $layer + $size / 100;
my $bs = $$ruleRef{'bordersize'}; my $bs = $$ruleRef{'bordersize'};
$lc = "round"; $lc = "round";
$dash = ""; $dash = "";
if ( cv ('autobridge') eq "1" ) { if(cv('autobridge')eq "1"){ # TODO bridge/tunnel
# TODO bridge/tunnel if($bridge == 1){ $lc = "butt";
if ( $bridge == 1) {
$lc = "butt" ;
$bs += 3; # TODO config value $bs += 3; # TODO config value
} } elsif($tunnel == 1){ $lc = "butt";
elsif ( $tunnel == 1) {
$lc = "butt" ;
$dash = "stroke-dasharray=\"10,10\" "; $dash = "stroke-dasharray=\"10,10\" ";
$bs += 3; $bs += 3;
} } }
} # bottom(border) if($bs > 0){ $size = 2 * $bs + $$ruleRef{'size'};
# bottom (border)
if ( $bs > 0 ) {
$size = 2 * $bs + $$ruleRef{'size'} ;
$color = $$ruleRef{'bordercolor'}; $color = $$ruleRef{'bordercolor'};
$svg2 = "stroke=\"$color\" stroke-width=\"$size\" stroke-linecap=\"$lc\" fill=\"none\" stroke-linejoin=\"$lj\" " . $dash; $svg2 = "stroke=\"$color\" stroke-width=\"$size\" stroke-linecap=\"$lc\" fill=\"none\" stroke-linejoin=\"$lj\" " . $dash;
$layer2 = $layer - 0.3 + $size / 100; $layer2 = $layer - 0.3 + $size / 100;
} } else{ $svg2 = "";
else {
$svg2 = "" ;
$layer2 = 0; $layer2 = 0;
} }
} }
return($svg1, $layer1, $svg2, $layer2); return($svg1, $layer1, $svg2, $layer2);
} }
# --------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------
sub createDirectory { sub createDirectory{ my $directoryName;
my $directoryName ;
my $dirFile; my $dirFile;
$directoryName = cv('out'); $directoryName = cv('out');
$directoryName =~ s/\.svg/\_streets.txt/; $directoryName =~ s/\.svg/\_streets.txt/;
@ -370,25 +271,14 @@ sub createDirectory {
my $ref = getDirectory(); my $ref = getDirectory();
my %directory = %$ref; my %directory = %$ref;
if ( cv('grid') eq "0") { if(cv('grid')eq "0"){ foreach my $street(sort keys %directory){ $street = replaceHTMLCode($street);
foreach my $street (sort keys %directory) {
$street = replaceHTMLCode ( $street ) ;
print $dirFile "$street\n"; print $dirFile "$street\n";
} }} else{ foreach my $street(sort keys %directory){ my $streetSanitized = replaceHTMLCode($street);
}
else {
foreach my $street (sort keys %directory) {
my $streetSanitized = replaceHTMLCode ( $street ) ;
print $dirFile "$streetSanitized\t"; print $dirFile "$streetSanitized\t";
foreach my $square (sort keys %{$directory{$street}}) { foreach my $square(sort keys %{$directory{$street}}){ print $dirFile "$square ";
print $dirFile "$square " ; } print $dirFile "\n";
}} close($dirFile);
} }
print $dirFile "\n" ;
}
}
close ($dirFile) ;
}
1; 1;