Exemple #1
0
 function var2json($var)
 {
     if (function_exists('json_encode')) {
         $result = json_encode($var);
     } else {
         $result = "";
         if (is_object($var)) {
             $result .= "{";
             $sep = "";
             foreach ($var as $key => $val) {
                 $result .= $sep . '"' . $key . '":' . var2json($val);
                 $sep = ",";
             }
             $result .= "}";
         } else {
             if (is_array($var)) {
                 $result .= "[";
                 $sep = "";
                 for ($i = 0; $i < count($var); $i++) {
                     $result .= $sep . var2json($var[$i]);
                     $sep = ",";
                 }
                 $result .= "]";
             } else {
                 if (is_string($var)) {
                     //$tmpStr = str_replace("'", "\'", $var);
                     $tmpStr = str_replace('"', '\\"', $var);
                     $result = '"' . str_replace("\n", '\\n', $tmpStr) . '"';
                 } else {
                     if (is_bool($var)) {
                         $result = $var ? 'true' : 'false';
                     } else {
                         if (is_null($var)) {
                             $result = 'null';
                         } else {
                             $result = $var;
                         }
                     }
                 }
             }
         }
     }
     return utf8_encode($result);
 }
Exemple #2
0
            $properties->extents->maxy = $oMax->GetY();
        }
        $result->layers = array();
        for ($i = 0; $i < $layers->GetCount(); $i++) {
            $layer = $layers->GetItem($i);
            $layerName = $layer->GetName();
            array_push($result->layers, $layerName);
            $layerClassName = $layer->GetFeatureClassName();
            $filter = $selection->GenerateFilter($layer, $layerClassName);
            $a = explode('OR', $filter);
            $result->{$layerName}->featureCount = count($a);
        }
        /*save selection in the session*/
        $_SESSION['selection_array'] = $properties;
    }
    echo var2json($result);
} catch (MgException $e) {
    echo "ERROR: " . $e->GetExceptionMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "\n";
}
function selectionToArray($selection, $aLayers, $bToggle = true)
{
    $layers = $selection->GetLayers();
    if ($layers) {
        for ($i = 0; $i < $layers->GetCount(); $i++) {
            $layer = $layers->GetItem($i);
            if ($layer) {
                $objId = $layer->GetName();
                if (!array_key_exists($objId, $aLayers)) {
                    $aLayers[$objId] = array();
Exemple #3
0
include "../../layers/MapServer/php/Common.php";
include "../../common/php/Utilities.php";
isset($_GET["wmsservicetitle"]) ? $gwmsServiceTitle = $_GET["wmsservicetitle"] : ($wmsservicetitle = NULL);
if (!isset($mapName)) {
    die('mapname not set');
}
if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
    switch ($_REQUEST["action"]) {
        case "listLayersWMS":
            $szObject = getLayerListFromWMS($_REQUEST["server"]);
            break;
        case "addLayer":
            $szObject = addLayer($_REQUEST["value"]);
            break;
    }
    $szJsonData = var2json($szObject);
    header('Content-type: text/plain');
    header('X-JSON: true');
    echo $szJsonData;
}
function getLayerListFromWMS($szServerName)
{
    include 'wms-parser.php';
    global $gszWMSServerName;
    global $gwmsServiceTitle;
    // add serverName as a global
    $gszWMSServerName = $szServerName;
    //$wmsServer = "http://atlas.gc.ca/cgi-bin/atlaswms_en?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS";
    $join = strpos($szServerName, '?') ? '&' : '?';
    $getCapRequest = $join . "VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS";
    //$xmlData = readData($gszWMSServerName.$getCapRequest);
Exemple #4
0
            }
            //Set compression flag
            $styleCount = count($sr->styles);
            $sr->isCompressed = $styleCount > $maxIconsPerScaleRange;
            if ($sr->isCompressed) {
                //First
                $style = $sr->styles[0];
                if ($preCacheIcons == true) {
                    $style->imageData = GetLegendImageInline($mappingService, $ldfId, $scaleVal, $style->geometryType, $style->categoryIndex);
                }
                //Pass over ones in between
                //Last
                $style = $sr->styles[$styleCount - 1];
                if ($preCacheIcons == true) {
                    $style->imageData = GetLegendImageInline($mappingService, $ldfId, $scaleVal, $style->geometryType, $style->categoryIndex);
                }
            } else {
                if ($preCacheIcons == true) {
                    foreach ($sr->styles as $style) {
                        $style->imageData = GetLegendImageInline($mappingService, $ldfId, $scaleVal, $style->geometryType, $style->categoryIndex);
                    }
                }
            }
        }
        $layerObj->scaleRanges = $scaleranges;
        array_push($scaleObj->layers, $layerObj);
    }
}
header('Content-type: application/json');
echo var2json($scaleObj);
exit;
Exemple #5
0
                    $szMapTipText .= $oLayer->name . " : " . $oShape->values[$aMapTipTextField[$key]] . $szBreak;
                    $szLabels = $aLabel[$key];
                    $szMapTip = $oShape->values[$aMapTipTextField[$key]];
                    $szURL = buildCustonUrl($oShape->values, $aMapTipURL[$key]);
                    $szMapTip = $szMapTip != "undefined" ? $szMapTip : "";
                    $szURL = $szURL != "undefined" ? $szURL : "";
                    $szLabels = $szLabels != "undefined" ? $szLabels : "";
                    array_push($aMapTips, $szMapTip);
                    array_push($aURL, $szURL);
                    array_push($aTipLabel, $szLabels);
                    $oLayer->close();
                }
            }
        }
    }
    echo "{'maptips':" . var2json($aMapTips) . ",'url':" . var2json($aURL) . ",'label':" . var2json($aTipLabel) . ",'test':'casper'}";
} else {
    echo "{'maptips':'','url':'','label':''}";
}
function isLayerVisible($szLayerName)
{
    $aVisLayers = split(",", $_POST["visLayers"]);
    foreach ($aVisLayers as $item) {
        if (trim($szLayerName) == trim($item)) {
            return true;
        }
    }
    return false;
}
function buildCustonUrl($aValues, $url)
{
Exemple #6
0
    $aData["aVisibleLayers"] = $szLayers;
    $aData["queryfile"] = $szQueryFile;
    // set the visable state in the session mapfile
    turnOnVisableLayersInMapFile($oMap);
    // save the map
    $oMap->save($_SESSION['maps'][$mapName]);
    // create the session save file
    writeSessionSaveControlFile($aData, $szSourceDir . "/");
    // create a new zip.
    $zip = new ZipArchive();
    if ($zip->open($szZipFilename, ZIPARCHIVE::CREATE) !== TRUE) {
        exit("{'error':'Can not create archive'}");
    } else {
        make_archive($szSourceDir, &$zip, $extdir = "");
        $zip->close();
        echo var2json($oReturn);
        $handle = fopen($szStoreSessionPath . $oReturn->sessionKey . ".dat", "w+");
        fwrite($handle, serialize($aData));
        fclose($handle);
        //$result = new SavedSession($oReturn->sessionKey, true);
    }
}
function writeSessionSaveControlFile($aData, $szPath)
{
    $handle = fopen($szPath . "sessionInfo.txt", "w+");
    $szOutput = "";
    fwrite($handle, serialize($aData));
    fclose($handle);
}
function readSessionSaveControlFile($szFileName)
{
Exemple #7
0
        }
        array_push($mapObj->layers, $layerObj);
    }
    //Get layer groups as xml
    $groups = $map->GetLayerGroups();
    $mapObj->groups = array();
    for ($i = 0; $i < $groups->GetCount(); $i++) {
        $group = $groups->GetItem($i);
        array_push($mapObj->groups, OutputGroupInfo($group));
    }
    $mapObj->FiniteDisplayScales = array();
    //FiniteDisplayScales for tiled maps
    for ($i = 0; $i < $map->GetFiniteDisplayScaleCount(); $i++) {
        array_push($mapObj->FiniteDisplayScales, $map->GetFiniteDisplayScaleAt($i));
    }
    echo var2json($mapObj);
} catch (MgException $e) {
    echo "ERROR: " . $e->GetExceptionMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "\n";
}
exit;
/************************************************************************/
/*                     GetLayerTypesFromResourceContent                 */
/*                                                                      */
/*      Replacement for GetLayerTypes function.                         */
/*      Extract the layer types based on the styling available.         */
/*      GetLayerTypes was costly in time when dealing in DB.            */
/************************************************************************/
function GetLayerTypesFromResourceContent($layer, $xmldoc = NULL)
{
Exemple #8
0
<?php

include "./lastRSS.php";
include 'var2json.php';
$rss = new lastRSS();
$rss->cache_dir = '';
$rss->cache_time = 0;
// $rss->cp = 'US-ASCII';
$rss->date_format = 'l';
$rssurl = $_REQUEST['url'];
if ($rs = $rss->get($rssurl)) {
    echo var2json($rs);
} else {
    echo '{error: "It is not possible to get $rssurl..."}';
}
Exemple #9
0
        $properties->{$layerName}->propertynames = array();
        $properties->{$layerName}->propertyvalues = array();
        $properties->{$layerName}->propertytypes = array();
        /*get first shape to get the attributes*/
        //$oRes = $oLayer->getResult(0);
        //$oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
        $oShape = $oLayer->getFeature(0);
        if ($oShape) {
            while (list($key, $val) = each($oShape->values)) {
                array_push($properties->{$layerName}->propertynames, $key);
                //TODO : we should define away to give alias to field names
                array_push($properties->{$layerName}->propertyvalues, $key);
                //TODO we do not know the types of the attributes in MS. Just output 0
                //we shouls possibly use OGR to get the attributes
                array_push($properties->{$layerName}->propertytypes, 0);
            }
        }
        $oLayer->close();
    }
    /*
    	if(isset($_SESSION['selection_array']->$layerName)){
    		if(isset($_SESSION['selection_array']->$layerName->values)){
    			$properties->$layerName->values = $_SESSION['selection_array']->$layerName->values;
    		}
    	}
    */
}
/*save selection in the session*/
//$_SESSION['selection_array'] = $properties;
echo var2json($properties);