Пример #1
0
function pfind_service($prms, $pfind_defs, $type_names, $p2p_paths, $node_types = FALSE)
{
    clb_timing(__LINE__);
    pfind_def_tables($pfind_defs);
    $result = array('error' => 200, 'error_str' => 'no errors');
    //get the query or way points from the request
    $entries = array();
    if (isset($prms['q']) && $prms['q']) {
        $entries[] = $prms['q'];
    } else {
        $w = 0;
        while (isset($prms['w' . $w])) {
            $entries[] = $prms['w' . $w];
            $w++;
        }
    }
    $prop = array();
    $prop['service'] = strtolower(clb_val('json', $prms, 's'));
    //json, xml
    $prop['mode'] = strtolower(clb_val('', $prms, 'm'));
    $prop['units'] = strtolower(clb_val('mi', $prms, 'u'));
    //km, mi
    $prop['opto'] = strtolower(clb_val('best', $prms, 'o'));
    //dist, change, best
    $prop['opacity'] = strtolower(clb_val(0.5, $prms, 't'));
    $prop['color'] = strtolower(clb_val('#0000FF', $prms, 'c'));
    $prop['stroke'] = strtolower(clb_val(5, $prms, 'k'));
    $dist_only = FALSE != clb_val(0, $prms, 'gd');
    //get result from precalculated distances
    $prop['dist_only'] = $dist_only;
    $prop['getSteps'] = !$dist_only && FALSE != clb_val(0, $prms, 'gs');
    $prop['getPolyline'] = !$dist_only && FALSE != clb_val(0, $prms, 'gp');
    $path = FALSE;
    $mode = $prop['mode'];
    if (is_string($p2p_paths)) {
        $path = $p2p_paths;
    } else {
        if (!is_array($p2p_paths)) {
            $result = array('error' => 500, 'error_str' => 'server configuration error: route tables not specified');
        } else {
            if ($mode && isset($p2p_paths[$mode])) {
                $path = $p2p_paths[$mode];
            } else {
                if (isset($p2p_paths['rtm'])) {
                    $node_types = array('rail', 'tube', 'tram');
                    $path = $p2p_paths['rtm'];
                } else {
                    $path = reset($p2p_paths);
                }
            }
        }
    }
    if (is_array($path)) {
        if (!$node_types) {
            $node_types = clb_val(FALSE, $path, 'types');
        }
        //get the types
        $path = clb_val(FALSE, $path, 'path');
    }
    //if types not given as param or with paths, but the mode name is a node type use it as default.
    if (!$node_types && clb_val(FALSE, $type_names, $prop['mode'])) {
        $node_types = $prop['mode'];
    }
    if ($node_types && !is_array($node_types)) {
        $node_types = array($node_types);
    }
    //make types an array if just a single
    if (!$path || !is_string($path) || !is_file($path)) {
        $result = array('error' => 500, 'error_str' => 'server configuration error: route tables could not be loaded');
    } else {
        $waypoints = array();
        $result = pfind_interpret($entries, $mode, $waypoints, $path, $node_types);
        qlog(__LINE__, $mode, $entries, $result);
        if (IS_LOCAL) {
            foreach ($waypoints as $i => $stage) {
                foreach ($stage as $see) {
                    qlog(__LINE__, $i, join(', ', $see));
                }
            }
        }
        clb_timing('interpret');
    }
    if ($result['error'] == 200) {
        $links = FALSE;
        if (!$prop['dist_only'] && is_file($path)) {
            $data = file_get_contents($path);
            //, FILE_BINARY);	//need different p2p files for different combinations of modes
            $links = clb_blob_dec($data);
        }
        clb_timing('load array');
        if (!$links && !$prop['dist_only']) {
            $result = array('error' => 500, 'error_str' => 'point to point data file could not be found/loaded ' . $mode);
            qlog(__LINE__, $result, $mode, $path, $p2p_paths);
        } else {
            $result = pfind_routes($waypoints, $links, $prop, $type_names);
        }
        qlog(__LINE__, clb_timing('find path'));
    }
    //qlog(__LINE__,clb_xml($result, 'RouteFinder'));
    // qlog(__LINE__,clb_json($result, "'"));
    switch ($prop['service']) {
        case 'json':
            $return_data = json_encode($result);
            rs_response('application/json', $return_data, 'UTF-8');
            break;
        case 'javascript':
            $sid = clb_val('', $prms, 'sid');
            $func = clb_val('mfw_dir_result', $prms, 'callback');
            $return_data = clb_json($result, "'");
            $callback = $func . '(\'' . $sid . '\',' . $return_data . ');';
            clb_response('application/javascript', $callback, 'UTF-8');
            break;
        case 'xml':
            $return_data = clb_xml($result, 'RouteFinder');
            clb_response('xml', $return_data, 'UTF-8');
            break;
        case 'php':
            return $result;
            break;
    }
}
Пример #2
0
    }
    require_once $path . '/config.php';
}
//scan downwards for _engine directory
$path = dirname(__FILE__);
while ($path && !file_exists($path . '/_engine/')) {
    $path = dirname($path);
}
DEFINE('CODE_DIR', $path . '/_engine/');
require_once CODE_DIR . 'wp-db.php';
require_once CODE_DIR . 'core_lib.php';
require_once CODE_DIR . 'pline_lib.php';
require_once CODE_DIR . 'pfind_lib.php';
require_once CODE_DIR . 'pbuild_lib.php';
//this file included in builder but not in route finder web service
pfind_def_tables($pfind_defs);
//scan downwards for data directory
$data_path = dirname(__FILE__);
while ($data_path && !file_exists($data_path . '/route_data/')) {
    $data_path = dirname($data_path);
}
$data_path .= '/route_data/';
//links requiring reversing
// <>Newark Castle - Newark North Gate, WJUFPED, DNTPXXC - this is across a junction not from a terminus
// <>Liskeard- St Keyne, QNUBNAP, RABITVK - backs out of a terminus before splitting off at next junction
$raw_segs = array('rseg');
$metaphone_types = array('rail', 'tube', 'tram');
$near_path = $data_path . 'rtm_near.dat';
$prim_path = $data_path . 'rtm_prim.dat';
switch ('rtm') {
    //<= change this manaully to select which types to be generated