示例#1
0
function add_layer_resource_to_map($layerResourceID, $resourceService, $layerName, $layerLegendLabel, &$map)
{
    $newLayer = new MgLayer($layerResourceID, $resourceService);
    // Add the new layer to the map's layer collection
    $newLayer->SetName($layerName);
    $newLayer->SetVisible(true);
    $newLayer->SetLegendLabel($layerLegendLabel);
    $newLayer->SetDisplayInLegend(true);
    $layerCollection = $map->GetLayers();
    if (!$layerCollection->Contains($layerName)) {
        // Insert the new layer at position 0 so it is at the top
        // of the drawing order
        $layerCollection->Insert(0, $newLayer);
    }
    return $newLayer;
}
示例#2
0
文件: query.php 项目: kanbang/Colt
 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;
 }
示例#3
0
 function AddLayer($paramSet)
 {
     try {
         $this->CreateMapFromResource($paramSet);
         $this->unitTestParamVm->Execute("Select ParamValue from Params WHERE ParamSet={$paramSet} AND ParamName=\"LAYERDEFINITION\"");
         $layerDef = $this->unitTestParamVm->GetString("ParamValue");
         $this->unitTestParamVm->Execute("Select ParamValue from Params WHERE ParamSet={$paramSet} AND ParamName=\"GROUPNAME\"");
         $groupName = $this->unitTestParamVm->GetString("ParamValue");
         $layer = new MgLayer(new MgResourceIdentifier($layerDef), $this->resSrvc);
         if ($groupName != "") {
             $groups = $this->map->GetLayerGroups();
             $layer->SetGroup($groups->GetItem($groupName));
         }
         $layers = $this->map->GetLayers();
         $layers->Add($layer);
         return new Result($layers->GetCount(), "text/plain");
     } catch (MgException $e) {
         return new Result(get_class($e), "text/plain");
     }
 }
示例#4
0
 function OpenMarkup()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     // Create the Layer Groups
     $markupGroup = null;
     $layerGroups = $map->GetLayerGroups();
     if ($layerGroups->Contains('_Markup')) {
         $markupGroup = $layerGroups->GetItem('_Markup');
     } else {
         $markupGroup = new MgLayerGroup('_Markup');
         $markupGroup->SetVisible(true);
         $markupGroup->SetLegendLabel('Markup');
         $markupGroup->SetDisplayInLegend(true);
         $layerGroups->Add($markupGroup);
     }
     // Add the Markup Layer
     $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']);
     $markupLayer = new MgLayer($markupLayerResId, $resourceService);
     $markupLayer->SetName('_' . $markupLayerResId->GetName());
     $markupLayer->SetLegendLabel($markupLayerResId->GetName());
     $markupLayer->SetDisplayInLegend(true);
     $markupLayer->SetSelectable(true);
     $markupLayer->SetGroup($markupGroup);
     $map->GetLayers()->Insert(0, $markupLayer);
     $map->Save($resourceService);
 }
示例#5
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;
 }
示例#6
0
文件: buffer.php 项目: kanbang/Colt
     $prop = new MgDataPropertyDefinition("ID");
     $prop->SetDataType(MgPropertyType::Int32);
     $classDef->GetProperties()->Add($prop);
     //Set geometry property
     $prop = new MgGeometricPropertyDefinition("GEOM");
     //$prop->SetGeometryTypes(MgFeatureGeometricType::mfgtSurface); //TODO use the constant when exposed
     $prop->SetGeometryTypes(4);
     $classDef->GetProperties()->Add($prop);
     //Create the schema
     $schema = new MgFeatureSchema("BufferSchema", GetLocalizedString("BUFFERSCHEMADESCR", $locale));
     $schema->GetClasses()->Add($classDef);
     //finally, creation of the feature source
     $sdfParams = new MgCreateSdfParams("LatLong", $srsDefMap, $schema);
     $featureSrvc->CreateFeatureSource($dataSourceId, $sdfParams);
     //Add layer to map
     $layer = new MgLayer($layerDefId, $resourceSrvc);
     $layer->SetName($bufferName);
     $layer->SetLegendLabel($bufferName);
     $layer->SetDisplayInLegend(true);
     $layer->SetSelectable(true);
     $layers->Insert(0, $layer);
 } else {
     //data source already exist. clear its content
     //
     ClearDataSource($featureSrvc, $dataSourceId, $featureName);
 }
 $sel = new MgSelection($map, $selText);
 $selLayers = $sel->GetLayers();
 $agfRW = new MgAgfReaderWriter();
 $bufferGeometries = new MgGeometryCollection();
 $commands = new MgFeatureCommandCollection();
示例#7
0
function CreateParcelMarkerLayer($resourceService, $parcelMarkerDataResId, $sessionId)
{
    // Load the ParcelMarker layer definition template into
    // a PHP DOM object, find the "ResourceId" element, and
    // modify its content to reference the temporary
    // feature source.
    $doc = DOMDocument::load('parcelmarker.xml');
    $featureSourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
    $featureSourceNode->nodeValue = $parcelMarkerDataResId->ToString();
    // Get the updated layer definition from the DOM object
    // and save it to the session repository using the
    // ResourceService object.
    $layerDefinition = $doc->saveXML();
    $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition));
    $byteSource->SetMimeType(MgMimeType::Xml);
    $tempLayerResId = new MgResourceIdentifier("Session:" . $sessionId . "//ParcelMarker.LayerDefinition");
    $resourceService->SetResource($tempLayerResId, $byteSource->GetReader(), null);
    // Create an MgLayer object based on the new layer definition
    // and return it to the caller.
    $parcelMarkerLayer = new MgLayer($tempLayerResId, $resourceService);
    $parcelMarkerLayer->SetName("ParcelMarker");
    $parcelMarkerLayer->SetLegendLabel("ParcelMarker");
    $parcelMarkerLayer->SetDisplayInLegend(true);
    $parcelMarkerLayer->SetSelectable(false);
    return $parcelMarkerLayer;
}
示例#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));
     }
 }
示例#9
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;
    }
示例#10
0
文件: measure.php 项目: kanbang/Colt
         if ($units == "m") {
             $unitText = "DISTANCEMETERS";
         }
         $unitText = GetLocalizedString($unitText, $locale);
         $tip = sprintf("Concat(Concat(Concat('" . GetLocalizedString("MEASUREPARTIAL", $locale) . ": ', PARTIAL), Concat(', " . GetLocalizedString("MEASURETOTAL", $locale) . ": ', TOTAL)), ' (%s)')", $unitText);
         //Create the layer definition
         $layerDefContent = BuildLayerDefinitionContent($dataSource, $featureName, $tip);
         $resourceSrvc->SetResource($layerDefId, $layerDefContent, null);
     } else {
         //data source already exist. clear its content
         ClearDataSource($featureSrvc, $dataSourceId, $featureName);
     }
     //Add the layer to the map, if it's not already in it
     if ($layer == null) {
         $legendName = GetLocalizedString("MEASURELAYER", $locale);
         $layer = new MgLayer($layerDefId, $resourceSrvc);
         $layer->SetDisplayInLegend(true);
         $layer->SetLegendLabel($legendName);
         $layers->Insert(0, $layer);
     }
 }
 // create a feature representing this segment and insert it into the data source
 //
 $measureProps = new MgPropertyCollection();
 $partialProp = new MgDoubleProperty("PARTIAL", $distance);
 $measureProps->Add($partialProp);
 $totalProp = new MgDoubleProperty("TOTAL", $total);
 $measureProps->Add($totalProp);
 $agf = new MgAgfReaderWriter();
 $geomReader = $agf->Write($geom);
 $geomProp = new MgGeometryProperty("GEOM", $geomReader);