Using real-world coordinates
[lhc/web/wiklou.git] / experiments / geo / geomaker.php
1 <?
2 include_once ( "geo_functions.php" ) ;
3
4 print "
5 <html>
6 <head></head>
7 <body>
8 " ;
9
10 # One should only use free maps here, but since this is just a test...
11 $image = "http://www.bmwnation.com/members/ausgang/Germany%20Map.jpg" ;
12
13 # Corner points of the image above:
14 # 361,502 <=> 480900,113500
15 # 277,67 <=> 541919,100803
16
17 if ( isset ( $_GET['coords'] ) ) $coords = $_GET['coords'] ;
18 else $coords = "" ;
19
20 $x = $y = -1 ;
21 foreach ( $_GET AS $k => $v )
22 {
23 $a = explode ( "," , str_replace ( "?" , "" , $k ) ) ;
24 if ( $v == "" AND count ( $a ) == 2 )
25 {
26 $x = array_shift ( $a ) ;
27 $y = array_shift ( $a ) ;
28 }
29 }
30
31 if ( $coords != "" ) $coords = explode ( ";" , $coords ) ;
32 else $coords = array () ;
33
34 if ( $x != -1 AND $y != -1 ) # Adding coordinates
35 {
36 $coords[] = "{$x},{$y}" ;
37 }
38
39 $c2 = $coords ;
40 if ( count ( $c2 ) > 0 ) array_pop ( $c2 ) ;
41 $c2 = implode ( ";" , $c2 ) ;
42
43 $coords = implode ( ";" , $coords ) ;
44
45 print "
46 <a href='./geomaker.php?coords={$coords}&'><image src='{$image}' ismap/></a>
47 " ;
48
49 print "<br/><a href='geomaker.php?coords={$c2}'>Remove last coordinates</a>" ;
50 print " | <a href='geomaker.php'>Reset</a>" ;
51
52 # Conversion form
53
54 if ( isset ( $_POST['convert'] ) )
55 {
56 $p1 = explode ( "," , $_POST['p1'] ) ;
57 $p2 = explode ( "," , $_POST['p2'] ) ;
58 $np1 = explode ( "," , $_POST['np1'] ) ;
59 $np2 = explode ( "," , $_POST['np2'] ) ;
60
61 $np1 = array ( coordinate_to_number ( $np1[0] ) , coordinate_to_number ( $np1[1] ) ) ;
62 $np2 = array ( coordinate_to_number ( $np2[0] ) , coordinate_to_number ( $np2[1] ) ) ;
63
64 $cx = coord_conversion_params ( $np1[1] , $np2[1] , $p1[0] , $p2[0] ) ;
65 $cy = coord_conversion_params ( $np1[0] , $np2[0] , $p1[1] , $p2[1] ) ;
66
67 $t = $_POST['ctext'] ;
68 $coords = "" ;
69 $t = explode ( " " , $t ) ;
70 foreach ( $t AS $s )
71 {
72 $s = explode ( "," , trim ( $s ) ) ;
73 if ( count ( $s ) == 2 )
74 {
75 $np = point_to_coords ( $s , $cx , $cy ) ;
76 $coords[] = coordinate_write($np[1]) . "," . coordinate_write($np[0]) ;
77 }
78 }
79 $coords = implode ( " " , $coords ) ;
80
81 # For output
82 $p1 = $_POST['p1'] ;
83 $p2 = $_POST['p2'] ;
84 $np1 = $_POST['np1'] ;
85 $np2 = $_POST['np2'] ;
86 }
87 else $p1 = $p2 = $np1 = $np2 = "" ;
88
89 print "<br/>Coordinates so far:<br>\n" ;
90 print "<form method=post><textarea style='width:100%' rows=5 cols=40 name='ctext'>\n" ;
91 print str_replace ( ";" , " " , $coords ) ;
92 print "</textarea>\n" ;
93 print "Conversion : Point <input type='text' name='p1'/ value='{$p1}'> matches coordinates <input type='text' name='np1' value='{$np1}'/><br>" ;
94 print "and point <input type='text' name='p2' value='{$p2}'/> matches coordinates <input type='text' name='np2' value='{$np2}'/>" ;
95 print " <input type='submit' name='convert' value='Convert'/>" ;
96 print "</form>" ;
97
98
99 print "
100 </body>
101 </html>" ;
102
103 ?>