Пример #1
0
 function ShowSpatialFilter()
 {
     $result = true;
     $sdfResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//Filter.FeatureSource');
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $updateCommands = new MgFeatureCommandCollection();
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layer = null;
     $layers = $map->GetLayers();
     if ($layers->Contains('_QuerySpatialFilter')) {
         $layer = $layers->GetItem('_QuerySpatialFilter');
         $updateCommands->Add(new MgDeleteFeatures('Filter', "ID like '%'"));
     } else {
         // Create the Feature Source (SDF)
         $sdfSchema = $this->CreateFilterSchema();
         $sdfParams = new MgCreateSdfParams('MAPCS', $map->GetMapSRS(), $sdfSchema);
         $featureService->CreateFeatureSource($sdfResId, $sdfParams);
         // Create the Layer
         $layerResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//Filter.LayerDefinition');
         $layerDefinition = file_get_contents("templates/filterlayerdefinition.xml");
         $layerDefinition = sprintf($layerDefinition, $sdfResId->ToString());
         $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition));
         $resourceService->SetResource($layerResId, $byteSource->GetReader(), null);
         $layer = new MgLayer($layerResId, $resourceService);
         $layer->SetName('_QuerySpatialFilter');
         $layer->SetLegendLabel('_QuerySpatialFilter');
         $layer->SetDisplayInLegend(false);
         $layer->SetSelectable(false);
         $layers->Insert(0, $layer);
     }
     // Make the layer visible
     $layer->SetVisible(true);
     $map->Save($resourceService);
     // Add the geometry to the filter feature source
     $polygon = $this->CreatePolygonFromGeomText($this->args['GEOMTEXT']);
     $agfWriter = new MgAgfReaderWriter();
     $byteReader = $agfWriter->Write($polygon);
     $propertyValues = new MgPropertyCollection();
     $propertyValues->Add(new MgGeometryProperty('Geometry', $byteReader));
     $updateCommands->Add(new MgInsertFeatures('Filter', $propertyValues));
     $featureService->UpdateFeatures($sdfResId, $updateCommands, false);
     return $result;
 }
 public function CreateRuntimeMap($format)
 {
     $session = $this->app->request->params("session");
     $mapDefIdStr = $this->app->request->params("mapdefinition");
     $mapName = $this->app->request->params("targetmapname");
     $reqFeatures = $this->app->request->params("requestedfeatures");
     $iconFormat = $this->app->request->params("iconformat");
     $iconWidth = $this->app->request->params("iconwidth");
     $iconHeight = $this->app->request->params("iconheight");
     $iconsPerScaleRange = $this->app->request->params("iconsperscalerange");
     $this->EnsureAuthenticationForSite($session);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     if ($session == null) {
         $site = $siteConn->GetSite();
         $session = $site->CreateSession();
         $this->userInfo = new MgUserInformation($session);
         $siteConn->Open($this->userInfo);
     }
     $mdfId = new MgResourceIdentifier($mapDefIdStr);
     if ($mapName == null) {
         $mapName = $mdfId->GetName();
     }
     //Assign default values or coerce existing ones to their expected types
     if ($reqFeatures != null) {
         $reqFeatures = intval($reqFeatures);
     }
     if ($iconFormat == null) {
         $iconFormat = "PNG";
     }
     if ($iconWidth == null) {
         $iconWidth = 16;
     } else {
         $iconWidth = intval($iconWidth);
     }
     if ($iconHeight == null) {
         $iconHeight = 16;
     } else {
         $iconHeight = intval($iconHeight);
     }
     if ($iconsPerScaleRange == null) {
         $iconsPerScaleRange = 25;
     } else {
         $iconsPerScaleRange = intval($iconsPerScaleRange);
     }
     if ($format == null) {
         $format = "xml";
     } else {
         $format = strtolower($format);
     }
     /*
     $admin = new MgServerAdmin();
     $admin->Open($this->userInfo);
     $version = explode(".", $admin->GetSiteVersion());
     */
     $version = $this->app->MG_VERSION;
     $bCanUseNative = false;
     if (intval($version[0]) > 2) {
         //3.0 or greater
         $bCanUseNative = true;
     } else {
         if (intval($version[0]) == 2 && intval($version[1]) >= 6) {
             //2.6 or greater
             $bCanUseNative = true;
         }
     }
     if ($bCanUseNative) {
         $req = new MgHttpRequest("");
         $param = $req->GetRequestParam();
         $param->AddParameter("OPERATION", "CREATERUNTIMEMAP");
         //Hmmm, this may violate REST API design, but if we're on MGOS 3.0 or newer, we must return linked tile set
         //information to the client if applicable. Meaning this API could return 2 different results depending on the
         //underlying MGOS version.
         if (intval($version[0]) >= 3) {
             $param->AddParameter("VERSION", "3.0.0");
         } else {
             $param->AddParameter("VERSION", "2.6.0");
         }
         $param->AddParameter("SESSION", $session);
         $param->AddParameter("MAPDEFINITION", $mapDefIdStr);
         $param->AddParameter("TARGETMAPNAME", $mapName);
         $param->AddParameter("REQUESTEDFEATURES", $reqFeatures);
         $param->AddParameter("ICONSPERSCALERANGE", $iconsPerScaleRange);
         $param->AddParameter("ICONFORMAT", $iconFormat);
         $param->AddParameter("ICONWIDTH", $iconWidth);
         $param->AddParameter("ICONHEIGHT", $iconHeight);
         if ($format === "json") {
             $param->AddParameter("FORMAT", MgMimeType::Json);
         } else {
             $param->AddParameter("FORMAT", MgMimeType::Xml);
         }
         $this->ExecuteHttpRequest($req);
     } else {
         //Shim the response
         $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
         $mappingSvc = $siteConn->CreateService(MgServiceType::MappingService);
         $map = new MgMap($siteConn);
         $map->Create($mdfId, $mapName);
         $mapStateId = new MgResourceIdentifier("Session:{$session}//{$mapName}.Map");
         $sel = new MgSelection($map);
         $sel->Save($resSvc, $mapName);
         $map->Save($resSvc, $mapStateId);
         $br = $this->DescribeRuntimeMapXml($mapDefIdStr, $map, $session, $mapName, $iconFormat, $iconWidth, $iconHeight, $reqFeatures, $iconsPerScaleRange, $resSvc, $mappingSvc);
         if ($format == "json") {
             $this->OutputXmlByteReaderAsJson($br);
         } else {
             $this->OutputByteReader($br);
         }
     }
 }
Пример #3
0
 function CloseMarkup()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     // Add the Markup Layer
     $markupLayerResId = new MgResourceIdentifier($this->args['OPENMARKUP']);
     $index = $map->GetLayers()->IndexOf('_' . $markupLayerResId->GetName());
     $map->GetLayers()->RemoveAt($index);
     $map->Save($resourceService);
 }
Пример #4
0
                $commands = new MgFeatureCommandCollection();
                for ($bufferRing = 0; $bufferRing < $bufferRingCount; $bufferRing++) {
                    $bufferDist = $srs->ConvertMetersToCoordinateSystemUnits($bufferRingSize * ($bufferRing + 1));
                    $bufferGeometry = $mergedGeometries->Buffer($bufferDist, $srsMeasure);
                    $properties = new MgPropertyCollection();
                    $properties->Add(new MgGeometryProperty('BufferGeometry', $agfReaderWriter->Write($bufferGeometry)));
                    $commands->Add(new MgInsertFeatures('BufferClass', $properties));
                }
                // Old way, pre MapGuide OS 2.0
                //$featureService->UpdateFeatures($bufferFeatureResId, $commands, false);
                // New way, post MapGuide OS 2.0
                $bufferLayer->UpdateFeatures($commands);
                $bufferLayer->SetVisible(true);
                $bufferLayer->ForceRefresh();
                $bufferLayer->SetDisplayInLegend(true);
                $map->Save();
            }
        }
    } else {
        echo 'No selected layers';
    }
    echo '</p>';
} catch (MgException $e) {
    echo '<p>' . $e->GetExceptionMessage() . '</p>';
    echo '<p>' . $e->GetDetails() . '</p>';
}
?>

    <p>The buffer has been created.</p>

  </body>
Пример #5
0
 $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
 // Get a runtime map from a map definition
 if (isset($_REQUEST['mapid'])) {
     $mapid = $_REQUEST['mapid'];
     //echo $mapid;
     $resourceID = new MgResourceIdentifier($mapid);
     $map = new MgMap();
     $mapTitle = $resourceID->GetName();
     //echo "<br> maname $mapName <br>";
     $map->Create($resourceService, $resourceID, $mapTitle);
     $mapName = uniqid($mapTitle);
     $mapStateId = new MgResourceIdentifier("Session:" . $sessionID . "//" . $mapName . "." . MgResourceType::Map);
     //create an empty selection object and store it in the session repository
     $sel = new MgSelection($map);
     $sel->Save($resourceService, $mapName);
     $map->Save($resourceService, $mapStateId);
 } else {
     $map = new MgMap();
     $map->Open($resourceService, $mapName);
     $mapTitle = $map->GetName();
     $mapid = $map->GetMapDefinition()->ToString();
 }
 //$sessionId =  $map->GetSessionId();
 //$mapName = $map->GetName() ;
 $extents = $map->GetMapExtent();
 @($oMin = $extents->GetLowerLeftCoordinate());
 @($oMax = $extents->GetUpperRightCoordinate());
 @($srs = $map->GetMapSRS());
 if ($srs != "") {
     @($csFactory = new MgCoordinateSystemFactory());
     @($cs = $csFactory->Create($srs));
Пример #6
0
            $mapLayers->RemoveAt($i);
            $mapLayers->Insert($found, $layerToMove);
        } else {
            $mapLayers->RemoveAt($i);
        }
        break;
    }
    /*
    $nLayers = count($layers);
    $layerDefs = array();
    for ($i=0; $i<$nLayers; $i++) {
        $layer = $mapLayers->GetItem($layers[$i]);
        array_push($layerDefs, $layer->GetLayerDefinition() );
    }
    $mapLayers->Clear();
    
    $nLayers = count($layerDefs);
    for ($i=0; $i<$nLayers; $i++) {
        $layer = new MgLayer(new MgResourceIdentifier($layerDefs[$i]), $resourceService);
        $mapLayers->Add($layer);
    }
    */
    $map->Save($resourceService);
    echo "success: true";
} catch (MgException $e) {
    echo "ERROR: '" . $e->GetExceptionMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "',\n";
    echo "success: false, layerindex: [" . $_REQUEST['layerindex'] . "]";
}
echo "}";
Пример #7
0
        if (strlen($bgColor) == 8) {
            $bgColor = '#' . substr($bgColor, 2);
        } else {
            $bgColor = "white";
        }
        $scaleCreationCode = "";
        $scales = array();
        for ($i = 0; $i < $map->GetFiniteDisplayScaleCount(); $i++) {
            $scales[$i] = $map->GetFiniteDisplayScaleAt($i);
        }
        sort($scales);
        for ($i = 0; $i < count($scales); $i++) {
            $scaleCreationCode = $scaleCreationCode . "scales[" . $i . "]=" . str_replace(",", ".", $scales[$i]) . "; ";
        }
        $mapStateId = new MgResourceIdentifier("Session:" . $sessionId . "//" . $mapName . "." . MgResourceType::Map);
        $map->Save($resourceSrvc, $mapStateId);
        $templ = Localize(file_get_contents("../viewerfiles/ajaxmappane.templ"), $locale, GetClientOS());
        $vpath = GetSurroundVirtualPath();
        printf($templ, $tileSizeX, $tileSizeY, GetRootVirtualFolder() . "/mapagent/mapagent.fcgi", $mapName, $mapDefinition, $infoWidth, $showLegend ? "true" : "false", $showProperties ? "true" : "false", $sessionId, $llExtent->GetX(), $llExtent->GetY(), $urExtent->GetX(), $urExtent->GetY(), $metersPerUnit, $unitsType, $bgColor, $hlTgt, $hlTgtName, $vpath . "setselection.php", $showSlider ? "true" : "false", $locale, $scaleCreationCode, $selectionColor, $mapImgFormat, $selImgFormat, $pointBufferSize, $vpath . "ajaxviewerabout.php", $vpath . "legendctrl.php", urlencode($mapName), $sessionId, $locale, $vpath . "propertyctrl.php", $locale);
    } catch (MgException $e) {
        $errorMsg = EscapeForHtml($e->GetDetails());
        echo $errorMsg;
    }
}
//load ajax template code and format it
function GetParameters($params)
{
    global $mapDefinition, $type;
    global $infoWidth, $showLegend, $showProperties, $sessionId;
    global $locale, $hlTgt, $hlTgtName, $showSlider;
    global $selectionColor, $mapImgFormat, $selImgFormat, $pointBufferSize;
Пример #8
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));
     }
 }