示例#1
0
    function GetMapLayerNames()
    {
        $layerNames = array();

        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);

        $map = new MgMap($this->site);
        $map->Open($this->args['MAPNAME']);
        $layers = $map->GetLayers();

        for ($i = 0; $i < $layers->GetCount(); $i++)
        {
            $layer = $layers->GetItem($i);

            //TODO: Exclude Raster and Drawing Layers???

            if((substr($layer->GetName(), 0, 1) != "_") && (substr(strtoupper($layer->GetFeatureSourceId()), 0, 7) != "SESSION") && ($layer->IsVisible()) && $layer->GetSelectable())
            {
                $layerNames[$layer->GetName()] = $layer->GetLegendLabel();
            }
        }
        asort($layerNames);

        return $layerNames;
    }
示例#2
0
function GenerateLegend()
{
    global $sessionID, $mapName, $width, $height, $offsetX, $offsetY, $xPad, $yPad, $iconWidth, $iconHeight, $xIndent, $groupIcon, $fontIndex, $textColor;
    $userInfo = new MgUserInformation($sessionID);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $scale = $map->GetViewScale();
    $image = imagecreatetruecolor($width, $height);
    $white = imagecolorallocate($image, 255, 255, 255);
    $textColor = imagecolorallocate($image, 0, 0, 0);
    imagefilledrectangle($image, 0, 0, $width, $height, $white);
    ProcessGroupsForLegend($mappingService, $resourceService, $map, $scale, NULL, $image);
    header("Content-type: image/png");
    imagepng($image);
    //Uncomment to see what PHP-isms get spewed out that may be tripping up rendering
    //Also replace instances of "////print_r" with "//print_r" to insta-uncomment all debugging calls
    /*
    ob_start();
    imagepng($image);
    $im = base64_encode(ob_get_contents());
    ob_end_clean();
    header("Content-type: text/html", true);
    echo "<img src='data:image/png;base64,".$im."' alt='legend image'></img>";
    */
    imagecolordeallocate($image, $white);
    imagecolordeallocate($image, $textColor);
    imagedestroy($image);
}
示例#3
0
function GenerateMap($size)
{
    global $sessionID, $mapName, $captureBox, $printSize, $normalizedCapture, $rotation, $scaleDenominator, $printDpi, $drawNorthArrow;
    $userInfo = new MgUserInformation($sessionID);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $selection = new MgSelection($map);
    // Calculate the generated picture size
    $envelope = $captureBox->Envelope();
    $normalizedE = $normalizedCapture->Envelope();
    $size1 = new Size($envelope->getWidth(), $envelope->getHeight());
    $size2 = new Size($normalizedE->getWidth(), $normalizedE->getHeight());
    $toSize = new Size($size1->width / $size2->width * $size->width, $size1->height / $size2->height * $size->height);
    $center = $captureBox->GetCentroid()->GetCoordinate();
    $map->SetDisplayDpi($printDpi);
    $colorString = $map->GetBackgroundColor();
    // The returned color string is in AARRGGBB format. But the constructor of MgColor needs a string in RRGGBBAA format
    $colorString = substr($colorString, 2, 6) . substr($colorString, 0, 2);
    $color = new MgColor($colorString);
    $mgReader = $renderingService->RenderMap($map, $selection, $center, $scaleDenominator, $toSize->width, $toSize->height, $color, "PNG", false);
    $tempImage = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "mgo" . uniqid();
    $mgReader->ToFile($tempImage);
    $image = imagecreatefrompng($tempImage);
    unlink($tempImage);
    // Rotate the picture back to be normalized
    $normalizedImg = imagerotate($image, -$rotation, 0);
    // Free the original image
    imagedestroy($image);
    // Crop the normalized image
    $croppedImg = imagecreatetruecolor($size->width, $size->height);
    imagecopy($croppedImg, $normalizedImg, 0, 0, (imagesx($normalizedImg) - $size->width) / 2, (imagesy($normalizedImg) - $size->height) / 2, $size->width, $size->height);
    // Free the normalized image
    imagedestroy($normalizedImg);
    if ($drawNorthArrow) {
        // Draw the north arrow on the map
        DrawNorthArrow($croppedImg);
    }
    header("Content-type: image/png");
    imagepng($croppedImg);
    //Uncomment to see what PHP-isms get spewed out that may be tripping up rendering
    //Also replace instances of "////print_r" with "//print_r" to insta-uncomment all debugging calls
    /*
    ob_start();
    imagepng($croppedImg);
    $im = base64_encode(ob_get_contents());
    ob_end_clean();
    header("Content-type: text/html", true);
    echo "<img src='data:image/png;base64,".$im."' alt='legend image'></img>";
    */
    imagedestroy($croppedImg);
}
示例#4
0
function GenerateMap($size)
{
    global $sessionID, $mapName, $captureBox, $printSize, $normalizedCapture, $rotation, $scaleDenominator, $printDpi;
    InitializeWebTier();
    $userInfo = new MgUserInformation($sessionID);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $selection = new MgSelection($map);
    // Calculate the generated picture size
    $envelope = $captureBox->Envelope();
    $normalizedE = $normalizedCapture->Envelope();
    $size1 = new Size($envelope->getWidth(), $envelope->getHeight());
    $size2 = new Size($normalizedE->getWidth(), $normalizedE->getHeight());
    $toSize = new Size($size1->width / $size2->width * $size->width, $size1->height / $size2->height * $size->height);
    $center = $captureBox->GetCentroid()->GetCoordinate();
    $map->SetDisplayDpi($printDpi);
    $colorString = $map->GetBackgroundColor();
    // The returned color string is in AARRGGBB format. But the constructor of MgColor needs a string in RRGGBBAA format
    $colorString = substr($colorString, 2, 6) . substr($colorString, 0, 2);
    $color = new MgColor($colorString);
    $mgReader = $renderingService->RenderMap($map, $selection, $center, $scaleDenominator, $toSize->width, $toSize->height, $color, "PNG", false);
    $tempImage = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "mgo" . uniqid();
    $mgReader->ToFile($tempImage);
    $image = imagecreatefrompng($tempImage);
    unlink($tempImage);
    // Rotate the picture back to be normalized
    $normalizedImg = imagerotate($image, -$rotation, 0);
    // Free the original image
    imagedestroy($image);
    // Crop the normalized image
    $croppedImg = imagecreatetruecolor($size->width, $size->height);
    imagecopy($croppedImg, $normalizedImg, 0, 0, (imagesx($normalizedImg) - $size->width) / 2, (imagesy($normalizedImg) - $size->height) / 2, $size->width, $size->height);
    // Free the normalized image
    imagedestroy($normalizedImg);
    // Draw the north arrow on the map
    DrawNorthArrow($croppedImg);
    header("Content-type: image/png");
    imagepng($croppedImg);
    imagedestroy($croppedImg);
}
示例#5
0
    <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
  </head>
  <body class="AppFrame">
    <h1 class="AppHeading">Layer Visibility</h1>
    <?php 
require_once '../common/common.php';
try {
    MgInitializeWebTier($webconfigFilePath);
    $args = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST : $_GET;
    $sessionId = $args['SESSION'];
    $mapName = $args['MAPNAME'];
    $userInfo = new MgUserInformation($sessionId);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    $map = new MgMap($siteConnection);
    $map->Open($mapName);
    $layers = $map->GetLayers();
    // Get layer collection
    echo "<p>Layers, in draw order:</p>";
    echo '<table class="taskPane" cellspacing="0">';
    echo '<tr><th class="rowHead">Layer</th><th>GetVisible()</th><th>IsVisible()</th></tr>';
    $count = $layers->GetCount();
    for ($i = 0; $i < $count; $i++) {
        $layer = $layers->GetItem($i);
        echo "<tr><td class=\"rowHead\">" . $layer->GetName() . "</td><td>" . ($layer->GetVisible() ? 'on' : 'off') . "</td><td>" . ($layer->IsVisible() ? 'on' : 'off') . "</td></tr>\n";
    }
    echo '</table>';
} catch (MgException $e) {
    echo "<p><strong>Error:</strong> ";
    echo $e->GetDetails();
    echo "</p>";
示例#6
0
文件: plotmain.php 项目: kanbang/Colt
$mgSessionId = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST['SESSION'] : $_GET['SESSION'];
$currentScale = 0;
try {
    // Initialize the Web Extensions and connect to the Server using
    // the Web Extensions session identifier stored in PHP session state.
    MgInitializeWebTier($configFilePath);
    $userInfo = new MgUserInformation($mgSessionId);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    // Create a ReserviceService object and use it to open the Map
    // object from the sessions repository. Use the Map object to
    // determine the current scale of the map for display on this
    // page.
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $map = new MgMap();
    $map->Open($resourceService, 'Sheboygan');
    $viewCenter = $map->GetViewCenter();
    $viewScale = $map->GetViewScale();
} catch (MgException $e) {
    echo $e->GetExceptionMessage();
    echo $e->GetDetails();
}
?>

<form id="plotForm" action="plot.php" method="get" target="_blank">
    <input name="SESSION" type="hidden" value="<?php 
echo $mgSessionId;
?>
">
    <input name="Scale" id="scaleValue" type="hidden" value="0">
    <input name="UseLayout" id="useLayoutValue" type="hidden" value="false">
示例#7
0
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/*****************************************************************************
 * Purpose: clear active selection from the map
 *****************************************************************************/
include "Common.php";
if (InitializationErrorOccurred()) {
    DisplayInitializationErrorText();
    exit;
}
try {
    $resourceSrvc = $siteConnection->CreateService(MgServiceType::ResourceService);
    $map = new MgMap();
    $map->Open($resourceSrvc, $mapName);
    $sel = new MgSelection($map);
    $sel->Save($resourceSrvc, $mapName);
} catch (MgException $e) {
    echo "ERROR: " . $e->GetExceptionMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "\n";
}
示例#8
0
 function GetOpenMarkup()
 {
     $openMarkup = array();
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layerGroups = $map->GetLayerGroups();
     if ($layerGroups->Contains('_Markup')) {
         $layers = $map->GetLayers();
         for ($i = 0; $i < $layers->GetCount(); $i++) {
             $layer = $layers->GetItem($i);
             if ($layer->GetGroup() != null and $layer->GetGroup()->GetName() == '_Markup') {
                 $openMarkup[$this->GetResourceIdPrefix() . $layer->GetLegendLabel() . '.LayerDefinition'] = $layer->GetLegendLabel();
             }
         }
         asort($openMarkup);
     }
     return $openMarkup;
 }
示例#9
0
文件: theme.php 项目: kanbang/Colt
 function ApplyTheme()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layers = $map->GetLayers();
     $layer = $layers->GetItem($this->args['LAYERNAME']);
     $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
     $layerDefResId = $layer->GetLayerDefinition();
     $byteReader = $resourceService->GetResourceContent($layerDefResId);
     // Load the Layer Definition and Navigate to the specified <VectorScaleRange>
     $doc = DOMDocument::loadXML($byteReader->ToString());
     $nodeList = $doc->getElementsByTagName('VectorScaleRange');
     $vectorScaleRangecElement = $nodeList->item($this->args['SCALERANGEINDEX']);
     $areaTypeStyle = $vectorScaleRangecElement->getElementsByTagName('AreaTypeStyle')->item(0);
     // Remove any existing <AreaRule> elements.
     $areaRuleList = $areaTypeStyle->getElementsByTagName('AreaRule');
     $ruleCount = $areaRuleList->length;
     for ($index = 0; $index < $ruleCount; $index++) {
         $areaTypeStyle->removeChild($areaRuleList->item(0));
     }
     // Now create the new <AreaRule> elements.
     $areaRuleTemplate = file_get_contents("templates/arearuletemplate.xml");
     $aggregateOptions = new MgFeatureAggregateOptions();
     $portion = 0.0;
     $increment = $this->args['NUMRULES'] > 1 ? $increment = 1.0 / ($this->args['NUMRULES'] - 1) : 1.0;
     if ($this->args['DISTRO'] == 'INDIV_DIST') {
         $aggregateOptions->AddFeatureProperty($this->args['PROPERTYNAME']);
         $aggregateOptions->SelectDistinct(true);
         $dataReader = $featureService->SelectAggregate($resId, $layer->GetFeatureClassName(), $aggregateOptions);
         while ($dataReader->ReadNext()) {
             $value = $this->GetFeaturePropertyValue($dataReader, $this->args['PROPERTYNAME']);
             $filterText = '&quot;' . $this->args['PROPERTYNAME'] . '&quot; = ';
             if ($this->args['DATATYPE'] == MgPropertyType::String) {
                 $filterText .= "'" . $value . "'";
             } else {
                 $filterText .= $value;
             }
             $areaRuleXML = sprintf($areaRuleTemplate, $this->args['PROPERTYNAME'] . ': ' . $value, $filterText, $this->InterpolateColor($portion, $this->args['FILLFROM'], $this->args['FILLTO'], $this->args['FILLTRANS']), $this->InterpolateColor($portion, $this->args['LINEFROM'], $this->args['LINETO'], 0));
             $areaDoc = DOMDocument::loadXML($areaRuleXML);
             $areaNode = $doc->importNode($areaDoc->documentElement, true);
             $areaTypeStyle->appendChild($areaNode);
             $portion += $increment;
         }
         $dataReader->Close();
     } else {
         $values = array();
         $aggregateOptions->AddComputedProperty('THEME_VALUE', $this->args['DISTRO'] . '("' . $this->args['PROPERTYNAME'] . '",' . $this->args['NUMRULES'] . ',' . $this->args['MINVALUE'] . ',' . $this->args['MAXVALUE'] . ')');
         $dataReader = $featureService->SelectAggregate($resId, $layer->GetFeatureClassName(), $aggregateOptions);
         while ($dataReader->ReadNext()) {
             $value = $this->GetFeaturePropertyValue($dataReader, 'THEME_VALUE');
             array_push($values, $value);
         }
         $dataReader->Close();
         for ($i = 0; $i < count($values) - 1; $i++) {
             $filterText = '&quot;' . $this->args['PROPERTYNAME'] . '&quot; &gt;= ' . $values[$i] . ' AND &quot;' . $this->args['PROPERTYNAME'];
             if ($i == count($values) - 1) {
                 $filterText .= '&quot; &lt;= ' . $values[$i + 1];
             } else {
                 $filterText .= '&quot; &lt; ' . $values[$i + 1];
             }
             $areaRuleXML = sprintf($areaRuleTemplate, $this->args['PROPERTYNAME'] . ': ' . $values[$i] . ' - ' . $values[$i + 1], $filterText, $this->InterpolateColor($portion, $this->args['FILLFROM'], $this->args['FILLTO'], $this->args['FILLTRANS']), $this->InterpolateColor($portion, $this->args['LINEFROM'], $this->args['LINETO'], 0));
             $areaDoc = DOMDocument::loadXML($areaRuleXML);
             $areaNode = $doc->importNode($areaDoc->documentElement, true);
             $areaTypeStyle->appendChild($areaNode);
             $portion += $increment;
         }
     }
     // Now save our new layer definition to the session and add it to the map.
     $layerDefinition = $doc->saveXML();
     $uniqueName = $this->MakeUniqueLayerName($map, $this->args['LAYERNAME'], $this->args['THEMENAME']);
     $legendLabel = $layer->GetLegendLabel();
     if (strlen(trim($this->args['THEMENAME'])) > 0) {
         $legendLabel .= ' (' . $this->args['THEMENAME'] . ')';
     }
     $layerResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//' . $uniqueName . '.LayerDefinition');
     $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition));
     $resourceService->SetResource($layerResId, $byteSource->GetReader(), null);
     $newLayer = new MgLayer($layerResId, $resourceService);
     $newLayer->SetName($uniqueName);
     $newLayer->SetLegendLabel($legendLabel);
     $newLayer->SetDisplayInLegend($layer->GetDisplayInLegend());
     $newLayer->SetVisible(true);
     $newLayer->SetSelectable($layer->GetLegendLabel());
     $layers->Insert($layers->IndexOf($layer), $newLayer);
     $map->Save($resourceService);
     return $uniqueName;
 }
示例#10
0
 function GetSelectionXML()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $markupLayer = $map->GetLayers()->GetItem('_' . $this->GetMarkupName());
     $selection = new MgSelection($map);
     $className = $markupLayer->GetFeatureClassName();
     $ids = $this->args['MARKUPFEATURE'];
     if (is_array($ids)) {
         foreach ($ids as $id) {
             $selection->AddFeatureIdInt32($markupLayer, $className, (int) $id);
         }
     } else {
         $selection->AddFeatureIdInt32($markupLayer, $className, (int) $ids);
     }
     return $selection->ToXML();
 }
 public function GetSessionMapKml($sessionId, $mapName, $format = "kml")
 {
     $fmt = $this->ValidateRepresentation($format, array("kml", "kmz"));
     $native = $this->GetBooleanRequestParameter("native", "0") == "1";
     //Internal debugging flag
     $chunk = $this->GetBooleanRequestParameter("chunk", true);
     $this->EnsureAuthenticationForSite($sessionId, true);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $map = new MgMap($siteConn);
     $map->Open($mapName);
     if ($native) {
         $mdfId = $map->GetMapDefinition();
         $mdfIdStr = $mdfId->ToString();
         $selfUrl = MgUtils::GetSelfUrlRoot($this->app->config("SelfUrl"));
         $this->app->redirect("{$selfUrl}/../mapagent/mapagent.fcgi?OPERATION=GETMAPKML&VERSION=1.0.0&SESSION={$sessionId}&MAPDEFINITION={$mdfIdStr}&CLIENTAGENT=MapGuide REST Extension");
     } else {
         $this->_GetKmlForMap($map, $sessionId, $format, $chunk);
     }
 }
示例#12
0
 function GetSelectionXML()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $markupLayer = $map->GetLayers()->GetItem('_' . $this->GetMarkupName());
     $selection = new MgSelection($map);
     $selection->AddFeatureIdInt32($markupLayer, $markupLayer->GetFeatureClassName(), (int) $this->args['MARKUPFEATURE']);
     return $selection->ToXML();
 }
示例#13
0
 public function UpdateMapLayersAndGroups($sessionId, $mapName, $format)
 {
     //Check for unsupported representations
     $fmt = $this->ValidateRepresentation($format, array("xml", "json"));
     try {
         $this->EnsureAuthenticationForSite($sessionId);
         $siteConn = new MgSiteConnection();
         $siteConn->Open($this->userInfo);
         $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
         $map = new MgMap($siteConn);
         $map->Open($mapName);
         if ($fmt == "json") {
             $body = $this->app->request->getBody();
             $json = json_decode($body);
             if ($json == NULL) {
                 throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
             }
         } else {
             $body = $this->app->request->getBody();
             $jsonStr = MgUtils::Xml2Json($body);
             $json = json_decode($jsonStr);
         }
         if (!isset($json->UpdateMap)) {
             throw new Exception($this->app->localizer->getText("E_MALFORMED_JSON_BODY"));
         }
         /*
         Expected structure
         
         /UpdateMap
             /Operation [1...n]
                 /Type - [AddLayer|UpdateLayer|RemoveLayer|AddGroup|UpdateGroup|RemoveGroup]
                 /Name
                 /ResourceId
                 /SetLegendLabel
                 /SetDisplayInLegend
                 /SetExpandInLegend
                 /SetVisible
                 /SetSelectable
                 /InsertAt
         */
         $layers = $map->GetLayers();
         $groups = $map->GetLayerGroups();
         $um = $json->UpdateMap;
         $updateStats = new stdClass();
         $updateStats->AddedLayers = 0;
         $updateStats->UpdatedLayers = 0;
         $updateStats->RemovedLayers = 0;
         $updateStats->AddedGroups = 0;
         $updateStats->UpdatedGroups = 0;
         $updateStats->RemovedGroups = 0;
         $this->app->log->debug("Operations found: " . count($um->Operation));
         for ($i = 0; $i < count($um->Operation); $i++) {
             $op = $um->Operation[$i];
             switch ($op->Type) {
                 case "AddLayer":
                     $resId = new MgResourceIdentifier($op->ResourceId);
                     $layer = new MgLayer($resId, $resSvc);
                     $layer->SetName($op->Name);
                     self::ApplyCommonLayerProperties($layer, $op, $groups);
                     if (isset($op->InsertAt)) {
                         $layers->Insert(intval($op->InsertAt), $layer);
                     } else {
                         $layers->Add($layer);
                     }
                     $this->app->log->debug("Add Layer: " . $op->Name);
                     $updateStats->AddedLayers++;
                     break;
                 case "UpdateLayer":
                     $layer = $layers->GetItem($op->Name);
                     if (self::ApplyCommonLayerProperties($layer, $op, $groups)) {
                         $this->app->log->debug("Updated Layer: " . $op->Name);
                         $updateStats->UpdatedLayers++;
                     }
                     break;
                 case "RemoveLayer":
                     $layer = $layers->GetItem($op->Name);
                     if ($layers->Remove($layer)) {
                         $this->app->log->debug("Removed Layer: " . $op->Name);
                         $updateStats->RemovedLayers++;
                     }
                     break;
                 case "AddGroup":
                     $group = new MgLayerGroup($op->Name);
                     self::ApplyCommonGroupProperties($group, $op, $groups);
                     if (isset($op->InsertAt)) {
                         $groups->Insert(intval($op->InsertAt), $group);
                     } else {
                         $groups->Add($group);
                     }
                     $this->app->log->debug("Add Group: " . $op->Name);
                     $updateStats->AddedGroups++;
                     break;
                 case "UpdateGroup":
                     $gidx = $groups->IndexOf($op->Name);
                     if ($gidx < 0) {
                         if ($op->AddIfNotExists) {
                             $group = new MgLayerGroup($op->Name);
                             self::ApplyCommonGroupProperties($group, $op, $groups);
                             if (isset($op->InsertAt)) {
                                 $groups->Insert(intval($op->InsertAt), $group);
                             } else {
                                 $groups->Add($group);
                             }
                             $this->app->log->debug("Add Group: " . $op->Name);
                             $updateStats->AddedGroups++;
                         } else {
                             throw new Exception($this->app->localizer->getText("E_GROUP_NOT_FOUND", $op->Name));
                         }
                     } else {
                         $group = $groups->GetItem($gidx);
                         if (self::ApplyCommonGroupProperties($group, $op, $groups)) {
                             $this->app->log->debug("Updated Group: " . $op->Name);
                             $updateStats->UpdatedGroups++;
                         }
                     }
                     break;
                 case "RemoveGroup":
                     $group = $groups->GetItem($op->Name);
                     if ($groups->Remove($group)) {
                         $this->app->log->debug("Removed Group: " . $op->Name);
                         $updateStats->RemovedGroups++;
                     }
                     break;
             }
         }
         if ($updateStats->AddedLayers > 0 || $updateStats->UpdatedLayers > 0 || $updateStats->RemovedLayers > 0 || $updateStats->AddedGroups > 0 || $updateStats->UpdatedGroups > 0 || $updateStats->RemovedGroups > 0) {
             $map->Save();
         }
         $response = "<UpdateMapResult>";
         $response .= "<AddedLayers>";
         $response .= $updateStats->AddedLayers;
         $response .= "</AddedLayers>";
         $response .= "<UpdatedLayers>";
         $response .= $updateStats->UpdatedLayers;
         $response .= "</UpdatedLayers>";
         $response .= "<RemovedLayers>";
         $response .= $updateStats->RemovedLayers;
         $response .= "</RemovedLayers>";
         $response .= "<AddedGroups>";
         $response .= $updateStats->AddedGroups;
         $response .= "</AddedGroups>";
         $response .= "<UpdatedGroups>";
         $response .= $updateStats->UpdatedGroups;
         $response .= "</UpdatedGroups>";
         $response .= "<RemovedGroups>";
         $response .= $updateStats->RemovedGroups;
         $response .= "</RemovedGroups>";
         $response .= "</UpdateMapResult>";
         $bs = new MgByteSource($response, strlen($response));
         $bs->SetMimeType(MgMimeType::Xml);
         $br = $bs->GetReader();
         if ($format == "json") {
             $this->OutputXmlByteReaderAsJson($br);
         } else {
             $this->OutputByteReader($br);
         }
     } catch (MgException $ex) {
         $this->OnException($ex, $this->GetMimeTypeForFormat($format));
     }
 }
示例#14
0
文件: query.php 项目: kanbang/Colt
 function GetSelectionXML()
 {
     $json = new Services_JSON();
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layer = $map->GetLayers()->GetItem($this->args['LAYERNAME']);
     $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
     $featureClass = $layer->GetFeatureClassName();
     $schemaAndClass = explode(":", $featureClass);
     $classDef = $featureService->GetClassDefinition($resId, $schemaAndClass[0], $schemaAndClass[1]);
     $properties = new MgPropertyCollection();
     $idList = $json->decode($this->args['IDLIST']);
     foreach ($idList as $key => $value) {
         switch ($classDef->GetProperties()->GetItem($key)->GetDataType()) {
             case MgPropertyType::Boolean:
                 $properties->Add(new MgBooleanProperty($key, $value));
                 break;
             case MgPropertyType::Byte:
                 $properties->Add(new MgByteProperty($key, $value));
                 break;
             case MgPropertyType::Single:
                 $properties->Add(new MgSingleProperty($key, $value));
                 break;
             case MgPropertyType::Double:
                 $properties->Add(new MgDoubleProperty($key, $value));
                 break;
             case MgPropertyType::Int16:
                 $properties->Add(new MgInt16Property($key, $value));
                 break;
             case MgPropertyType::Int32:
                 $properties->Add(new MgInt32Property($key, $value));
                 break;
             case MgPropertyType::Int64:
                 $properties->Add(new MgInt64Property($key, $value));
                 break;
             case MgPropertyType::String:
                 $properties->Add(new MgStringProperty($key, $value));
                 break;
             case MgPropertyType::DateTime:
                 $properties->Add(new MgDateTimeProperty($key, $value));
                 break;
             case MgPropertyType::Null:
             case MgPropertyType::Blob:
             case MgPropertyType::Clob:
             case MgPropertyType::Feature:
             case MgPropertyType::Geometry:
             case MgPropertyType::Raster:
                 break;
         }
     }
     $selection = new MgSelection($map);
     $selection->AddFeatureIds($layer, $featureClass, $properties);
     return $selection->ToXml();
 }
 public function GeneratePlot($sessionId, $mapName, $format)
 {
     $fmt = $this->ValidateRepresentation($format, array("dwf", "pdf"));
     $this->EnsureAuthenticationForSite($sessionId);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $map = new MgMap($siteConn);
     $map->Open($mapName);
     $mappingSvc = $siteConn->CreateService(MgServiceType::MappingService);
     $title = $this->GetRequestParameter("title", "");
     $paperSize = $this->GetRequestParameter("papersize", 'A4');
     $orientation = $this->GetRequestParameter("orientation", 'P');
     $marginLeft = floatval($this->GetRequestParameter("marginleft", 0.5));
     $marginRight = floatval($this->GetRequestParameter("marginright", 0.5));
     $marginTop = floatval($this->GetRequestParameter("margintop", $title == "" ? 0.5 : 1.0));
     $marginBottom = floatval($this->GetRequestParameter("marginbottom", 0.5));
     if ($fmt == "dwf") {
         $size = MgUtils::GetPaperSize($this->app, $paperSize);
         //If landscape, flip the width/height
         $width = $orientation == 'L' ? MgUtils::MMToIn($size[1]) : MgUtils::MMToIn($size[0]);
         $height = $orientation == 'L' ? MgUtils::MMToIn($size[0]) : MgUtils::MMToIn($size[1]);
         $printLayoutStr = $this->GetRequestParameter("printlayout", null);
         $dwfVersion = new MgDwfVersion("6.01", "1.2");
         $plotSpec = new MgPlotSpecification($width, $height, MgPageUnitsType::Inches);
         $plotSpec->SetMargins($marginLeft, $marginTop, $marginRight, $marginBottom);
         $layout = null;
         if ($printLayoutStr != null) {
             $layoutRes = new MgResourceIdentifier($printLayoutStr);
             $layout = new MgLayout($layoutRes, $title, MgPageUnitsType::Inches);
         }
         $br = $mappingSvc->GeneratePlot($map, $plotSpec, $layout, $dwfVersion);
         //Apply download headers
         $downloadFlag = $this->app->request->params("download");
         if ($downloadFlag && ($downloadFlag === "1" || $downloadFlag === "true")) {
             $name = $this->app->request->params("downloadname");
             if (!$name) {
                 $name = "download";
             }
             $name .= ".dwf";
             $this->app->response->header("Content-Disposition", "attachment; filename=" . $name);
         }
         $this->OutputByteReader($br);
     } else {
         //pdf
         $bLayered = $this->app->request->params("layeredpdf");
         if ($bLayered == null) {
             $bLayered = false;
         } else {
             $bLayered = $bLayered == "1" || $bLayered == "true";
         }
         $renderingService = $siteConn->CreateService(MgServiceType::RenderingService);
         $plotter = new MgPdfPlotter($this->app, $renderingService, $map);
         $plotter->SetTitle($title);
         $plotter->SetPaperType($paperSize);
         $plotter->SetOrientation($orientation);
         $plotter->ShowCoordinates(true);
         $plotter->ShowNorthArrow(true);
         $plotter->ShowScaleBar(true);
         $plotter->ShowDisclaimer(true);
         $plotter->SetLayered($bLayered);
         $plotter->SetMargins($marginTop, $marginBottom, $marginLeft, $marginRight);
         $mapCenter = $map->GetViewCenter();
         //Apply download headers
         $downloadFlag = $this->app->request->params("download");
         if ($downloadFlag && ($downloadFlag === "1" || $downloadFlag === "true")) {
             $name = $this->app->request->params("downloadname");
             if (!$name) {
                 $name = "download";
             }
             $name .= ".pdf";
             $plotter->Plot($mapCenter->GetCoordinate(), $map->GetViewScale(), $name);
         } else {
             $plotter->Plot($mapCenter->GetCoordinate(), $map->GetViewScale());
         }
     }
 }
示例#16
0
文件: SaveMap.php 项目: kanbang/Colt
    DisplayInitializationErrorText();
    exit;
}
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'PNG';
$layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : null;
$scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : null;
$imgWidth = isset($_REQUEST['width']) ? $_REQUEST['width'] : null;
$imgHeight = isset($_REQUEST['height']) ? $_REQUEST['height'] : null;
$pageHeight = isset($_REQUEST['pageheight']) ? $_REQUEST['pageheight'] : 11;
$pageWidth = isset($_REQUEST['pagewidth']) ? $_REQUEST['pagewidth'] : 8.5;
$aMargins = isset($_REQUEST['margins']) ? explode(',', $_REQUEST['margins']) : array(0, 0, 0, 0);
try {
    $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
    $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $selection = new MgSelection($map);
    $selection->Open($resourceService, $mapName);
    //get current center as a coordinate
    $center = $map->GetViewCenter()->GetCoordinate();
    //plot with the passed scale, if provided
    $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : $map->GetViewScale();
    if ($format == 'DWF') {
        $oLayout = null;
        if ($layout) {
            $layoutId = new MgResourceIdentifier($layout);
            $layoutId->Validate();
            $oLayout = new MgLayout($layoutId, 'Map', 'meters');
        }
        $oPlotSpec = new MgPlotSpecification($pageWidth, $pageHeight, MgPageUnitsType::Inches, $aMargins[0], $aMargins[1], $aMargins[2], $aMargins[3]);
        $dwfVersion = new MgDwfVersion('6.01', '1.2');
示例#17
0
    function ApplyTheme()
    {
        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
        $featureService = $this->site->CreateService(MgServiceType::FeatureService);

        $map = new MgMap($this->site);
        $map->Open($this->args['MAPNAME']);
        $layers = $map->GetLayers();
        $layer = $layers->GetItem($this->args['LAYERNAME']);

        $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
        $layerDefResId = $layer->GetLayerDefinition();
        $byteReader = $resourceService->GetResourceContent($layerDefResId);
        
        $filter = $layer->GetFilter();

        // Load the Layer Definition and Navigate to the specified <VectorScaleRange>

        $doc = new DOMDocument();
        $doc->loadXML($byteReader->ToString());
        $version = $doc->documentElement->getAttribute('version');
        $template = 'templates/arearuletemplate-'.$version.'.xml';
        $layerDefList = $doc->getElementsByTagName('VectorLayerDefinition');
        $layerDef = $layerDefList->item(0);
        $nodeList = $layerDef->getElementsByTagName('VectorScaleRange');

        $vectorScaleRangecElement = $nodeList->item($this->args['SCALERANGEINDEX']);
        $listLength = $nodeList->length;
        for($index = 0; $index < $listLength; $index++)
        {
            $layerDef->removeChild($nodeList->item(0));
        }
        $layerDef->appendChild($vectorScaleRangecElement);
        $areaTypeStyle = $vectorScaleRangecElement->getElementsByTagName('AreaTypeStyle')->item(0);
        
        // Remove any existing <AreaRule> elements.
        if($areaTypeStyle != null)
        {
            $areaRuleList = $areaTypeStyle->getElementsByTagName('AreaRule');
            $ruleCount = $areaRuleList->length;
            for($index = 0; $index < $ruleCount; $index++)
            {
                $areaTypeStyle->removeChild($areaRuleList->item(0));
            }

            $hasChild = $areaTypeStyle->hasChildNodes();
            if($hasChild)
            {
              $element = $areaTypeStyle->childNodes->item(0);
            }
        }

        $CompositeTypeStyles = $vectorScaleRangecElement->getElementsByTagName('CompositeTypeStyle');
        $isEnhancedStyle = ($CompositeTypeStyles->length != 0);
        // Remove any existing <CompositeTypeStyle> elements with Polygon <GeometryContext>.
        if($isEnhancedStyle)
        {
            $template = 'templates/arearuletemplate-'.$version.'-Enhanced.xml';
            $styleCount = $CompositeTypeStyles->length;
            for($index = 0; $index < $styleCount; $index++)
            {

                $CompositeTypeStyle = $CompositeTypeStyles->item($index);
                $GeometryContexts = $CompositeTypeStyle->getElementsByTagName('GeometryContext');
                $contextCount = $GeometryContexts->length;

                for($i = 0; $i < $contextCount; $i++)
                {
                    $GeometryContext = $GeometryContexts->item($i);
                    if($GeometryContext->nodeValue == 'Polygon')
                    {
                        $vectorScaleRangecElement->removeChild($CompositeTypeStyle);
                        $index--;
                        $styleCount--;
                        break;
                    }
                }
            }
        }

        // Now create the new <AreaRule> or <CompositeTypeStyle> elements.
        $areaRuleTemplate = file_get_contents($template);
        $aggregateOptions = new MgFeatureAggregateOptions();

        $portion = 0.0;
        $increment = ($this->args['NUMRULES'] > 1) ? $increment = 1.0 / ($this->args['NUMRULES'] - 1) : 1.0;

        if ($this->args['DISTRO'] == 'INDIV_DIST')
        {
            $values = array();
            
            $aggregateOptions->AddComputedProperty('THEME_VALUE', 'UNIQUE("' . $this->args['PROPERTYNAME'] . '")');
            if($filter != '')
                $aggregateOptions->SetFilter($filter);
            $dataReader = $layer->SelectAggregate($aggregateOptions);
            while ($dataReader->ReadNext())
            {
                $value = $this->GetFeaturePropertyValue($dataReader, 'THEME_VALUE');
                array_push($values, $value);
            }
            $dataReader->Close();
            
            if ($this->args['DATATYPE'] == MgPropertyType::String)
                sort($values, SORT_STRING);
            else
                sort($values, SORT_NUMERIC);

            for ($i = 0; $i < count($values); $i++)
            {
                $filterText = '&quot;' . $this->args['PROPERTYNAME'] . '&quot; = ';
                if ($this->args['DATATYPE'] == MgPropertyType::String)
                    $filterText .= "'" . $values[$i] . "'";
                else
                    $filterText .= $values[$i];
                    
                $areaRuleXML = sprintf($areaRuleTemplate,
                    $this->args['PROPERTYNAME'] . ': ' . $values[$i],
                    $filterText,
                    $this->InterpolateColor($portion, $this->args['FILLFROM'], $this->args['FILLTO'], $this->args['FILLTRANS']),
                    $this->InterpolateColor($portion, $this->args['LINEFROM'], $this->args['LINETO'], 0));

                $areaDoc = new DOMDocument();
                $areaDoc->loadXML($areaRuleXML);
                $areaNode = $doc->importNode($areaDoc->documentElement, true);
                if($areaTypeStyle != null)
                {
                    if($hasChild)
                    {
                      $areaTypeStyle->insertBefore($areaNode, $element);
                    }
                    else
                    {
                      $areaTypeStyle->appendChild($areaNode);
                    }
                }
                if($isEnhancedStyle)
                {
                    $compositeTypeStyle = $doc->createElement('CompositeTypeStyle');
                    $compositeTypeStyle->appendChild($areaNode);
                    $vectorScaleRangecElement->appendChild($compositeTypeStyle);
                }

                $portion += $increment;
            }
        }
        else
        {
            $values = array();

            $aggregateOptions->AddComputedProperty('THEME_VALUE',
                $this->args['DISTRO'] . '("' . $this->args['PROPERTYNAME'] . '",' . $this->args['NUMRULES'] . ',' . $this->args['MINVALUE'] . ',' . $this->args['MAXVALUE'] . ')');
            if($filter != '')
                $aggregateOptions->SetFilter($filter);

            $dataReader = $layer->SelectAggregate($aggregateOptions);
            while ($dataReader->ReadNext())
            {
                $value = $this->GetFeaturePropertyValue($dataReader, 'THEME_VALUE');
                array_push($values, $value);
            }
            $dataReader->Close();

            for ($i = 0; $i < count($values) - 1; $i++)
            {
                $filterText = '&quot;' . $this->args['PROPERTYNAME'] . '&quot; &gt;= ' . $values[$i] . ' AND &quot;' . $this->args['PROPERTYNAME'];
                if ($i == count($values) - 2)
                    $filterText .= '&quot; &lt;= ' . $values[$i + 1];
                else
                    $filterText .= '&quot; &lt; ' . $values[$i + 1];

                $areaRuleXML = sprintf($areaRuleTemplate,
                    $this->args['PROPERTYNAME'] . ': ' . $values[$i] . ' - ' . $values[$i + 1],
                    $filterText,
                    $this->InterpolateColor($portion, $this->args['FILLFROM'], $this->args['FILLTO'], $this->args['FILLTRANS']),
                    $this->InterpolateColor($portion, $this->args['LINEFROM'], $this->args['LINETO'], 0));

                $areaDoc = new DOMDocument();
                $areaDoc->loadXML($areaRuleXML);
                $areaNode = $doc->importNode($areaDoc->documentElement, true);
                if($areaTypeStyle != null)
                {
                    if($hasChild)
                    {
                      $areaTypeStyle->insertBefore($areaNode, $element);
                    }
                    else
                    {
                      $areaTypeStyle->appendChild($areaNode);
                    }
                }
                if($isEnhancedStyle)
                {
                    $compositeTypeStyle = $doc->createElement('CompositeTypeStyle');
                    $compositeTypeStyle->appendChild($areaNode);
                    $vectorScaleRangecElement->appendChild($compositeTypeStyle);
                }

                $portion += $increment;
            }

        }

        // Now save our new layer definition to the session and add it to the map.

        $layerDefinition = $doc->saveXML();
        $uniqueName = $this->MakeUniqueLayerName($map, $this->args['LAYERNAME'], $this->args['THEMENAME']);
        $legendLabel = $layer->GetLegendLabel();
        if (strlen(trim($this->args['THEMENAME'])) > 0 )
            $legendLabel .= ' (' . $this->args['THEMENAME'] . ')';

        $layerResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//' . $uniqueName . '.LayerDefinition');

        $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition));
        $resourceService->SetResource($layerResId, $byteSource->GetReader(), null);

        $newLayer = new MgLayer($layerResId, $resourceService);
        $newLayer->SetName($uniqueName);
        $newLayer->SetLegendLabel($legendLabel);
        $newLayer->SetDisplayInLegend($layer->GetDisplayInLegend());
        $newLayer->SetVisible(true);
        $newLayer->SetSelectable($layer->GetLegendLabel());
        $layers->Insert($layers->IndexOf($layer), $newLayer);

        $map->Save();

        return $uniqueName;
    }