From 1d9e50ed0d87b555e9639c12158c06ee554448a0 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 16 Jan 2005 03:10:19 +0000 Subject: [PATCH] Moving Magnus's experimental map software out of the MediaWiki release file tree into the extensions module. --- experiments/geo/geo.php | 356 ------------------------------ experiments/geo/geo_data.php | 30 --- experiments/geo/geo_functions.php | 65 ------ experiments/geo/geomaker.php | 103 --------- 4 files changed, 554 deletions(-) delete mode 100755 experiments/geo/geo.php delete mode 100644 experiments/geo/geo_data.php delete mode 100644 experiments/geo/geo_functions.php delete mode 100644 experiments/geo/geomaker.php diff --git a/experiments/geo/geo.php b/experiments/geo/geo.php deleted file mode 100755 index 470bf5c7c5..0000000000 --- a/experiments/geo/geo.php +++ /dev/null @@ -1,356 +0,0 @@ -style_fill[$id] ) ) $fill = $this->style_fill[$id] ; - else $fill = "fill:#CCCCCC" ; - if ( isset ( $this->style_border[$id] ) ) $border = $this->style_border[$id] ; - else $border = "stroke:black; stroke-width:10" ; - return $fill . "; " . $border ; - } - - function data_to_real ( &$x , &$y ) - { - $x = coordinate_to_number ( coordinate_take_apart ( $x ) ) ; - $y = coordinate_to_number ( coordinate_take_apart ( $y ) ) ; - - $z = $x ; $x = $y ; $y = $z ; # Switching y/x to x/y - $y = 90 * 3600 - $y ; # displaying from north to south - - # Recording min and max - $this->min_x = min ( $this->min_x , $x ) ; - $this->min_y = min ( $this->min_y , $y ) ; - $this->max_x = max ( $this->max_x , $x ) ; - $this->max_y = max ( $this->max_y , $y ) ; - } - - function get_view_box () - { - $min_x = $this->min_x ; - $max_x = $this->max_x ; - $min_y = $this->min_y ; - $max_y = $this->max_y ; - $width = $max_x - $min_x ; - $height = $max_y - $min_y ; - $min_x -= $width / 10 ; - $min_y -= $height / 10 ; - $max_x += $width / 10 ; - $max_y += $height / 10 ; - - $max_x -= $min_x ; - $max_y -= $min_y ; - return "{$min_x} {$min_y} {$max_x} {$max_y}" ; - } - - function add_label ( $text_array ) - { - $this->labels[] = $text_array ; - } - - function get_svg_labels () - { - $ret = "" ; - $medium_font_size = floor ( ( $this->max_x - $this->min_x ) / 50 ) ; - foreach ( $this->labels AS $l ) - { - $text = $l['text'] ; - $x = $l['x'] ; - $y = $l['y'] ; - $s = "id = $id ; - $t = explode ( "\n;" , "\n".geo_get_text ( $id ) ) ; - $this->data = array () ; - foreach ( $t AS $x ) - { - $b = explode ( ":" , $x , 2 ) ; - while ( count ( $b ) < 2 ) $b[] = "" ; - $key = strtolower ( str_replace ( " " , "" , array_shift ( $b ) ) ) ; - $key = str_replace ( "\n" , "" , $key ) ; - $value = trim ( str_replace ( "\n" , "" , array_shift ( $b ) ) ) ; - $value = explode ( ";" , $value ) ; - if ( $key != "" ) $this->data[$key] = $value ; - } - } - - function get_data ( &$params ) - { - $ret = array () ; - if ( !isset ( $this->data["data"] ) ) return $ret ; # No data in this set - $data = $this->data["data"] ; - $data = array_shift ( $data ) ; - $data = explode ( " " , $data ) ; - foreach ( $data AS $a ) - { - $a = explode ( "," , $a ) ; - if ( count ( $a ) == 2 ) - { - $x = trim ( array_shift ( $a ) ) ; - $y = trim ( array_shift ( $a ) ) ; - $params->data_to_real ( $x , $y ) ; - $ret[] = array ( $x , $y ) ; - } - } - return $ret ; - } - - function add_reordered_data ( &$original , &$toadd ) - { - if ( count ( $toadd ) == 0 ) return ; # Nothing to add - if ( count ( $original ) == 0 ) - { - $original = $toadd ; - return ; - } - - $o_last = array_pop ( $original ) ; array_push ( $original , $o_last ) ; # Get last one and restore - $t_last = array_pop ( $toadd ) ; array_push ( $toadd , $t_last ) ; # Get last one and restore - $t_first = array_shift ( $toadd ) ; array_unshift ( $toadd , $t_first ) ; # Get first one and restore - - $dist_to_first = ( $o_last[0] - $t_first[0] ) * ( $o_last[0] - $t_first[0] ) + - ( $o_last[1] - $t_first[1] ) * ( $o_last[1] - $t_first[1] ) ; - - $dist_to_last = ( $o_last[0] - $t_last[0] ) * ( $o_last[0] - $t_last[0] ) + - ( $o_last[1] - $t_last[1] ) * ( $o_last[1] - $t_last[1] ) ; - - if ( $dist_to_last < $dist_to_first ) # If the last point of toadd is closer than the fist one, - $toadd = array_reverse ( $toadd ) ; # add in other direction - - $original = array_merge ( $original , $toadd ) ; - } - - function get_specs ( $base , $modes ) - { - foreach ( $modes AS $x ) - { - if ( isset ( $this->data["{$base}[{$x}]"] ) ) - return "{$base}[{$x}]" ; - } - if ( isset ( $this->data[$base] ) ) - return $base ; - return "" ; - } - - function get_current_type ( &$params ) # params may override native type - { - $t = $this->get_specs ( "type" , array ( "political" ) ) ; - if ( $t != "" ) $t = $this->data[$t][0] ; - return $t ; - } - - function get_current_style ( &$params ) - { - $t = trim ( strtolower ( $this->get_current_type ( $params ) ) ) ; - if ( $t == "river" ) $s = "fill:none; stroke:blue; stroke-width:2" ; - else $s = $params->get_styles ( $this->id , $t ) ; - return "style=\"{$s}\"" ; - } - - function draw_line ( $line , &$params ) - { - $ret = "" ; - $a = explode ( "(" , $line , 2 ) ; - while ( count ( $a ) < 2 ) $a[] = "" ; - $command = trim ( strtolower ( array_shift ( $a ) ) ) ; - $values = trim ( str_replace ( ")" , "" , array_shift ( $a ) ) ) ; - if ( $command == "addregs" || $command == "include" ) - { - $values = explode ( "," , $values ) ; - foreach ( $values AS $v ) - { - $v = trim ( strtolower ( $v ) ) ; - $ng = new geo ; - $ng->set_from_id ( $v ) ; - $ret .= $ng->draw ( $params ) ; - } - } - else if ( $command == "polygon" || $command == "polyline" ) - { - $data = array () ; - $values = explode ( "," , $values ) ; - foreach ( $values AS $v ) - { - $v = trim ( strtolower ( $v ) ) ; - $ng = new geo ; - $ng->set_from_id ( $v ) ; - $b = $ng->get_data ( $params ) ; - $this->add_reordered_data ( $data , $b ) ; - } - - $style = $this->get_current_style ( $params ) ; - if ( $command == "polygon" ) $ret .= "xsum += $x ; - $this->ysum += $y ; - $this->count++ ; - $ret .= "{$x},{$y} " ; - } - $ret = trim ( $ret ) . "\"/>\n" ; - - } - return $ret ; - } - - function add_label ( $x , $y , &$params ) - { - $text = $this->get_specs ( "name" , $params->languages ) ; - if ( $text == "" ) return "" ; - $text = utf8_decode ( $this->data[$text][0] ) ; - $x = floor ( $x ) ; - $y = floor ( $y ) ; - - $a = array ( "text" => $text , "x" => $x , "y" => $y , "font-size" => "medium" ) ; - $params->add_label ( $a ) ; - } - - function draw ( &$params ) - { - $ret = "" ; - $this->xsum = $this->ysum = $this->count = 0 ; - $match = $this->get_specs ( "region" , array ( "political" ) ) ; - if ( $match != "" ) - { - $a = $this->data[$match] ; - foreach ( $a AS $line ) - $ret .= $this->draw_line ( $line , $params ) ; - } - if ( $this->count > 0 ) - { - $x = $this->xsum / $this->count ; - $y = $this->ysum / $this->count ; - $this->add_label ( $x , $y , $params ) ; - } - return $ret ; - } - } - - -$g = new geo ; -$g->set_from_id ( "germany" ) ; - -$p = new geo_params ; -$p->languages = array ( "de" , "en" ) ; # Fallback to "en" if there's no "de" -$p->style_fill = array ( "germany.hamburg" => "fill:red" ) ; - -$svg = $g->draw ( $p ) ; -$svg .= $p->get_svg_labels () ; - -$styles = "" ; - -$viewBox = $p->get_view_box () ; - -$svg = -' - - -' - . $styles . -' -' - . $svg . - ' - -' ; - -print $svg ; - -?> \ No newline at end of file diff --git a/experiments/geo/geo_data.php b/experiments/geo/geo_data.php deleted file mode 100644 index dd6ed95b52..0000000000 --- a/experiments/geo/geo_data.php +++ /dev/null @@ -1,30 +0,0 @@ - " - -", - - -"germany.sh" => " - -", - -"germany" => " - -", - -"danube" => " -!type:river -!region:polyline(danube_germany,danube_austria) -" , - -"danube_germany" =>"!data:120,350 180,250 200,290" , -"danube_austria" =>"!data:220,350 250,320 300,370" , - -) ; - -?> \ No newline at end of file diff --git a/experiments/geo/geo_functions.php b/experiments/geo/geo_functions.php deleted file mode 100644 index ce216870ab..0000000000 --- a/experiments/geo/geo_functions.php +++ /dev/null @@ -1,65 +0,0 @@ - \ No newline at end of file diff --git a/experiments/geo/geomaker.php b/experiments/geo/geomaker.php deleted file mode 100644 index 4a8c7df1e3..0000000000 --- a/experiments/geo/geomaker.php +++ /dev/null @@ -1,103 +0,0 @@ - - - -" ; - -# One should only use free maps here, but since this is just a test... -$image = "http://www.bmwnation.com/members/ausgang/Germany%20Map.jpg" ; - -# Corner points of the image above: -# 361,502 <=> 480900,113500 -# 277,67 <=> 541919,100803 - -if ( isset ( $_GET['coords'] ) ) $coords = $_GET['coords'] ; -else $coords = "" ; - -$x = $y = -1 ; -foreach ( $_GET AS $k => $v ) - { - $a = explode ( "," , str_replace ( "?" , "" , $k ) ) ; - if ( $v == "" AND count ( $a ) == 2 ) - { - $x = array_shift ( $a ) ; - $y = array_shift ( $a ) ; - } - } - -if ( $coords != "" ) $coords = explode ( ";" , $coords ) ; -else $coords = array () ; - -if ( $x != -1 AND $y != -1 ) # Adding coordinates - { - $coords[] = "{$x},{$y}" ; - } - -$c2 = $coords ; -if ( count ( $c2 ) > 0 ) array_pop ( $c2 ) ; -$c2 = implode ( ";" , $c2 ) ; - -$coords = implode ( ";" , $coords ) ; - -print " - -" ; - -print "
Remove last coordinates" ; -print " | Reset" ; - -# Conversion form - -if ( isset ( $_POST['convert'] ) ) - { - $p1 = explode ( "," , $_POST['p1'] ) ; - $p2 = explode ( "," , $_POST['p2'] ) ; - $np1 = explode ( "," , $_POST['np1'] ) ; - $np2 = explode ( "," , $_POST['np2'] ) ; - - $np1 = array ( coordinate_to_number ( $np1[0] ) , coordinate_to_number ( $np1[1] ) ) ; - $np2 = array ( coordinate_to_number ( $np2[0] ) , coordinate_to_number ( $np2[1] ) ) ; - - $cx = coord_conversion_params ( $np1[1] , $np2[1] , $p1[0] , $p2[0] ) ; - $cy = coord_conversion_params ( $np1[0] , $np2[0] , $p1[1] , $p2[1] ) ; - - $t = $_POST['ctext'] ; - $coords = "" ; - $t = explode ( " " , $t ) ; - foreach ( $t AS $s ) - { - $s = explode ( "," , trim ( $s ) ) ; - if ( count ( $s ) == 2 ) - { - $np = point_to_coords ( $s , $cx , $cy ) ; - $coords[] = coordinate_write($np[1]) . "," . coordinate_write($np[0]) ; - } - } - $coords = implode ( " " , $coords ) ; - - # For output - $p1 = $_POST['p1'] ; - $p2 = $_POST['p2'] ; - $np1 = $_POST['np1'] ; - $np2 = $_POST['np2'] ; - } -else $p1 = $p2 = $np1 = $np2 = "" ; - -print "
Coordinates so far:
\n" ; -print "
\n" ; -print "Conversion : Point matches coordinates
" ; -print "and point matches coordinates " ; -print " " ; -print "
" ; - - -print " - -" ; - -?> \ No newline at end of file -- 2.20.1