5 !type[political]:country
9 addregs(germany-west,germany-east);
14 !type[political]:county
15 !name[de]:Westdeutschland
16 !name[en]:Western Germany
18 polygon(germany-border-north-w,germany-border-ew,germany-border-south-w,germany-border-west-w)
22 !type[political]:county
23 !name[de]:Westdeutschland
24 !name[en]:Western Germany
26 polygon(germany-border-north-e,germany-border-east-e,germany-border-south-e,germany-border-ew)
29 "germany-border-ew" => "!data:2,2 2,3",
31 "germany-border-north-w" => "!data:1,1 1.8,1",
32 "germany-border-south-w" => "!data:1,4 2.2,4",
33 "germany-border-west-w" => "!data:1,1 1,4",
35 "germany-border-north-e" => "!data:2,2 3,2",
36 "germany-border-south-e" => "!data:2,3 3,3",
37 "germany-border-east-e" => "!data:3,2 3,3",
41 !region:polyline(danube_germany,danube_austria)
44 "danube_germany" =>"!data:1.2,3.5 1.8,2.5 2,2.9" ,
45 "danube_austria" =>"!data:2.2,3.5 2.5,3.2 3,3.7" ,
50 function geo_get_text ( $id )
56 function data_to_real ( &$x , &$y )
66 var $data = array () ;
67 function set_from_text ( $t )
69 $t = explode ( "\n!" , "\n".$t ) ;
70 $this->data
= array () ;
73 $b = explode ( ":" , $x , 2 ) ;
74 while ( count ( $b ) < 2 ) $b[] = "" ;
75 $key = strtolower ( str_replace ( " " , "" , array_shift ( $b ) ) ) ;
76 $key = str_replace ( "\n" , "" , $key ) ;
77 $value = trim ( str_replace ( "\n" , "" , array_shift ( $b ) ) ) ;
78 $value = explode ( ";" , $value ) ;
79 if ( $key != "" ) $this->data
[$key] = $value ;
83 function set_from_id ( $id )
85 $this->set_from_text ( geo_get_text ( $id ) ) ;
91 if ( !isset ( $this->data
["data"] ) ) return $ret ; # No data in this set
92 $data = $this->data
["data"] ;
93 $data = array_shift ( $data ) ;
94 $data = explode ( " " , $data ) ;
95 foreach ( $data AS $a )
97 $a = explode ( "," , $a ) ;
98 if ( count ( $a ) == 2 )
100 $x = trim ( array_shift ( $a ) ) ;
101 $y = trim ( array_shift ( $a ) ) ;
102 $ret[] = array ( $x , $y ) ;
108 function add_reordered_data ( &$original , &$toadd )
110 if ( count ( $toadd ) == 0 ) return ; # Nothing to add
111 if ( count ( $original ) == 0 )
117 $o_last = array_pop ( $original ) ; array_push ( $original , $o_last ) ; # Get last one and restore
118 $t_last = array_pop ( $toadd ) ; array_push ( $toadd , $t_last ) ; # Get last one and restore
119 $t_first = array_shift ( $toadd ) ; array_unshift ( $toadd , $t_first ) ; # Get first one and restore
121 $dist_to_first = ( $o_last[0] - $t_first[0] ) * ( $o_last[0] - $t_first[0] ) +
122 ( $o_last[1] - $t_first[1] ) * ( $o_last[1] - $t_first[1] ) ;
124 $dist_to_last = ( $o_last[0] - $t_last[0] ) * ( $o_last[0] - $t_last[0] ) +
125 ( $o_last[1] - $t_last[1] ) * ( $o_last[1] - $t_last[1] ) ;
127 if ( $dist_to_last < $dist_to_first ) # If the last point of toadd is closer than the fist one,
128 $toadd = array_reverse ( $toadd ) ; # add in other direction
130 $original = array_merge ( $original , $toadd ) ;
133 function get_specs ( $base , $modes )
135 foreach ( $modes AS $x )
137 if ( isset ( $this->data
["{$base}[{$x}]"] ) )
138 return "{$base}[{$x}]" ;
140 if ( isset ( $this->data
[$base] ) )
145 function get_current_type ( $params ) # params may override native type
147 $t = $this->get_specs ( "type" , array ( "political" ) ) ;
148 if ( $t != "" ) $t = $this->data
[$t][0] ;
152 function get_current_style ( $params )
154 $t = trim ( strtolower ( $this->get_current_type ( $params ) ) ) ;
155 if ( $t == "river" ) $s = "fill:none; stroke:blue; stroke-width:2" ;
156 else $s = "fill:brown; stroke:black; stroke-width:1" ;
157 return "style=\"{$s}\"" ;
160 function draw_line ( $line , $params )
163 $a = explode ( "(" , $line , 2 ) ;
164 while ( count ( $a ) < 2 ) $a[] = "" ;
165 $command = trim ( strtolower ( array_shift ( $a ) ) ) ;
166 $values = trim ( str_replace ( ")" , "" , array_shift ( $a ) ) ) ;
167 # print "Evaluating command {$line}\n" ;
168 if ( $command == "addregs" ||
$command == "include" )
170 $values = explode ( "," , $values ) ;
171 foreach ( $values AS $v )
173 $v = trim ( strtolower ( $v ) ) ;
175 $ng->set_from_id ( $v ) ;
176 $ret .= $ng->draw ( $params ) ;
179 else if ( $command == "polygon" ||
$command == "polyline" )
182 $values = explode ( "," , $values ) ;
183 foreach ( $values AS $v )
185 $v = trim ( strtolower ( $v ) ) ;
187 $ng->set_from_id ( $v ) ;
188 $b = $ng->get_data () ;
189 $this->add_reordered_data ( $data , $b ) ;
192 $style = $this->get_current_style ( $params ) ;
193 if ( $command == "polygon" ) $ret .= "<polygon {$style} points=\"" ;
194 if ( $command == "polyline" ) $ret .= "<polyline {$style} points=\"" ;
195 foreach ( $data AS $a )
199 data_to_real ( $x , $y ) ;
200 $ret .= "{$x},{$y} " ;
202 $ret = trim ( $ret ) . "\"/>\n" ;
208 function draw ( $params = array() )
211 $match = $this->get_specs ( "region" , array ( "political" ) ) ;
214 $a = $this->data
[$match] ;
215 foreach ( $a AS $line )
216 $ret .= $this->draw_line ( $line , $params ) ;
224 $g->set_from_id ( "germany" ) ;
227 $svg = $g->draw ( $p ) ;
232 <style type="text/css"><![CDATA[
233 .stuff {fill:none; stroke:blue; stroke-width:2}
240 '<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
241 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd">
242 <svg viewBox="0 0 270 400"
243 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">