<?php

    
########################################################################

    
class ModestMaps {
            
        function 
ModestMaps ($host='127.0.0.1'$port='9999'){
            
$this->host $host;
            
$this->port $port;
        }

        function 
fetch (&$args){
            
$url $this->build_url($args);

            
$opts = array('http' => array('method'=>"GET"'timeout' => 300));
            
$ctx stream_context_create($opts);

            
$data  file_get_contents($urlfalse$ctx);
            return 
imagecreatefromstring($data);
        }

        function 
build_url (&$args){

            
$params = array();

            foreach (
$args as $key => $value){
                
                if (! 
is_array($value)){
                    
$value = array($value);
                }

                foreach (
$value as $v){
                    
$enc_value urlencode($v);
                    
$params[] = "$key=$enc_value";
                }
            }

            return 
"http://{$this->host}:{$this->port}?" implode("&"$params);
        }
    }

    
########################################################################

    
function test_ws_compose($label, &$args){
        
$mm = new ModestMaps('127.0.0.1''9998');
        return 
run_test($mm$label$args);
    }

    
########################################################################

    
function test_ws_pinwin($label, &$args){
        
$mm = new ModestMaps('127.0.0.1''9999');
        return 
run_test($mm$label$args);
    }

    
########################################################################
    
    
function run_test ($mm$label, &$args){

        echo 
"test :  $label\n";
        
        foreach (
$args as $key => $value){
            
$v = (is_array($value)) ? implode(";"$value) : $value;
            echo 
"$key : $v\n";
        }

        
$url $mm->build_url($args);
        
$res = ($mm->fetch($args)) ? "OK" "FAIL";

        echo 
"fetch : {$url}\n";
        echo 
"result : {$res}\n";
        echo 
"\n";
    }

    
########################################################################

    
$args  = array(
               
'provider' => 'GOOGLE_ROAD',
               
'latitude' => '45.521375561025756',
               
'longitude' => '-73.57049345970154',
               
'zoom' => 15,
               
'height' => 500,
               
'width' => 500
               
);

    
test_ws_compose("simple map centered by lat/lon"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'extent',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'height' => 1024,
              
'width' => 1024,
              );

    
test_ws_compose("simple map by bbox + extent"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'bbox',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'zoom' => 15,
              );

    
test_ws_compose("simple map by bbox + zoom"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'bbox',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'zoom' => 14,
              
'marker' => 'roy,45.521375561025756,-73.57049345970154',
              );

    
test_ws_pinwin("pinwin map by bbox + zoom w/ marker"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'bbox',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'zoom' => 14,
              
'marker' => 'roy,45.521375561025756,-73.57049345970154,500,180',
              );

    
test_ws_pinwin("pinwin map by bbox + zoom w/ marker + custom pinwin"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'bbox',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'zoom' => 14,
              
'marker' => 'roy,45.521375561025756,-73.57049345970154,500,180',
              
'bleed' => 1,
              );

    
test_ws_pinwin("pinwin map by bbox + zoom w/ marker + custom pinwin and bleed"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'GOOGLE_ROAD',
              
'method' => 'bbox',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'zoom' => 14,
              
'marker' => array(
                    
'roy,45.521375561025756,-73.57049345970154,500,180',
                    
'mileend,45.525825499457,-73.5989034175872,600,180',
                    
'cherrier,45.51978191639917,-73.56947422027588',
                    ),
              
'bleed' => 1,
              );

    
test_ws_pinwin("pinwin map by bbox + zoom w/ multiple markers and bleed"$args);

    
########################################################################

    
$args = array(
              
'provider' => 'MICROSOFT_AERIAL',
              
'bbox' => '45.482882,-73.619899,45.532687,-73.547801',
              
'filter' => 'atkinson',
              
'height' => 1024,
              
'width' => 2048,
              
'method' => 'extent',
              
'marker' => array(
                    
'roy,45.521375561025756,-73.57049345970154,500,180',
                    
'mileend,45.525825499457,-73.5989034175872,600,180',
                    
'cherrier,45.51978191639917,-73.56947422027588',
                    ),
              
'bleed' => 1,
              );

    
test_ws_pinwin("pinwin map by extent w/ multiple markers, filtering and bleed"$args);

    
########################################################################

    
echo "done\n";
    exit;

    
########################################################################
?>