////////////////////////////////////////////////////////////////// // processes a GetMapLegendImage request from the Viewer and returns // an image of the specified maps legend. // MgByteReader* MgHtmlController::GetMapLegendImage(CREFSTRING mapName, CREFSTRING format, MgColor* backgroundColor, INT32 width, INT32 height) { // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService); // Create MgMap Ptr<MgMap> map = new MgMap(); map->Open(resourceService, mapName); // Make sure we clear any track changes - these are not applicable for AJAX. Ptr<MgNamedCollection> changeLists = map->GetChangeLists(); if (changeLists->GetCount() > 0) { map->ClearChanges(); map->Save(resourceService); } // Create Proxy Rendering Service instance Ptr<MgRenderingService> service = (MgRenderingService*)(GetService(MgServiceType::RenderingService)); // Call the C++ API return service->RenderMapLegend(map, width, height, backgroundColor, format); }
////////////////////////////////////////////////////////////////// // Processes a GetDynamicMapOverlayImage request from the Viewer and returns an image of the specified map. // MgByteReader* c_RestFetchImage::GetDynamicMapOverlayImage_ViewCommands(c_RestMgSiteConnection* MgSiteConn,CREFSTRING mapName, CREFSTRING format, bool bKeepSelection,MgPropertyCollection* mapViewCommands) { // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)MgSiteConn->CreateService(MgServiceType::ResourceService); // Create MgMap Ptr<MgMap> map = new MgMap(); map->Open(resourceService, mapName); // Apply map view commands ApplyMapViewCommands(map, mapViewCommands); // Make sure we clear any track changes - these are not applicable for AJAX. Ptr<MgNamedCollection> changeLists = map->GetChangeLists(); if (changeLists->GetCount() > 0) { map->ClearChanges(); map->Save(resourceService); } // Get the selection Ptr<MgSelection> selection = new MgSelection(map); selection->Open(resourceService, mapName); // Create Proxy Rendering Service instance Ptr<MgRenderingService> service = (MgRenderingService*)(MgSiteConn->CreateService(MgServiceType::RenderingService)); // Call the C++ API return service->RenderDynamicOverlay(map, selection, format, bKeepSelection); }//end of c_RestFetchImage::GetDynamicMapOverlayImage_ViewCommands
////////////////////////////////////////////////////////////////// // Processes a GetDynamicMapOverlayImage request from the Viewer and returns an image of the specified map. // MgByteReader* MgHtmlController::GetDynamicMapOverlayImage(CREFSTRING mapName, MgRenderingOptions* options, MgPropertyCollection* mapViewCommands) { // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService); // Create MgMap Ptr<MgMap> map = new MgMap(); map->Open(resourceService, mapName); // Make sure we clear any track changes - these are not applicable for AJAX. Ptr<MgNamedCollection> changeLists = map->GetChangeLists(); if (changeLists->GetCount() > 0) { map->ClearChanges(); map->Save(resourceService); } // Get the selection Ptr<MgSelection> selection = new MgSelection(map); selection->Open(resourceService, mapName); // Apply map view commands ApplyMapViewCommands(map, mapViewCommands); // Make sure we clear any track changes - these are not applicable for AJAX. map->ClearChanges(); // Save the MgMap state map->Save(resourceService); // Create Proxy Rendering Service instance Ptr<MgRenderingService> service = (MgRenderingService*)(GetService(MgServiceType::RenderingService)); // Call the C++ API return service->RenderDynamicOverlay(map, selection, options); }
////////////////////////////////////////////////////////////////// // Processes a QueryMapFeatures request from the Viewer // MgByteReader* MgHtmlController::QueryMapFeatures( CREFSTRING mapName, MgStringCollection* layerNames, MgGeometry* selectionGeometry, INT32 selectionVariant, CREFSTRING featureFilter, INT32 maxFeatures, bool persist, INT32 layerAttributeFilter) { // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService); // Create MgMap Ptr<MgMap> map = new MgMap(); map->Open(resourceService, mapName); // Make sure we clear any track changes - these are not applicable for AJAX. Ptr<MgNamedCollection> changeLists = map->GetChangeLists(); if (changeLists->GetCount() > 0) { map->ClearChanges(); map->Save(resourceService); } // Create Proxy Rendering Service instance Ptr<MgRenderingService> service = (MgRenderingService*)(GetService(MgServiceType::RenderingService)); // Call the C++ API Ptr<MgFeatureInformation> featureInfo = service->QueryFeatures(map, layerNames, selectionGeometry, selectionVariant, featureFilter, maxFeatures, layerAttributeFilter); if(persist) { //save the selection set in the session repository Ptr<MgSelection> selection = featureInfo->GetSelection(); if(!selection) selection = new MgSelection(map); selection->Save(resourceService, mapName); } // Return XML return featureInfo->ToXml(); }
////////////////////////////////////////////////////////////////// // Processes a GetVisibleMapExtent request from the Viewer and returns info on the specified map. // MgByteReader* MgHtmlController::GetVisibleMapExtent(CREFSTRING mapName, MgPropertyCollection* mapViewCommands) { // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService); // Open the MgMap Ptr<MgMap> map = new MgMap(); map->Open(resourceService, mapName); // Apply map view commands ApplyMapViewCommands(map, mapViewCommands); // Make sure we clear any track changes - these are not applicable for AJAX. map->ClearChanges(); // Save the MgMap state map->Save(resourceService); // Calculate mcs width and height double metersPerUnit = map->GetMetersPerUnit(); double mapScale = map->GetViewScale(); double devW = map->GetDisplayWidth(); double devH = map->GetDisplayHeight(); double metersPerPixel = 0.0254 / map->GetDisplayDpi(); double mcsW = mapScale * devW * metersPerPixel / metersPerUnit; double mcsH = mapScale * devH * metersPerPixel / metersPerUnit; // Make an envelope Ptr<MgPoint> center = map->GetViewCenter(); Ptr<MgCoordinate> coord = center->GetCoordinate(); Ptr<MgCoordinateXY> coord0 = new MgCoordinateXY(coord->GetX() - 0.5*mcsW, coord->GetY() - 0.5*mcsH); Ptr<MgCoordinateXY> coord1 = new MgCoordinateXY(coord->GetX() + 0.5*mcsW, coord->GetY() + 0.5*mcsH); Ptr<MgEnvelope> envelope = new MgEnvelope(coord0, coord1); // Return XML return envelope->ToXml(); }
////////////////////////////////////////////////////////////////// // Processes a QueryMapFeatures request from the Viewer // MgByteReader* MgHtmlController::QueryMapFeatures( CREFSTRING mapName, MgStringCollection* layerNames, MgGeometry* selectionGeometry, INT32 selectionVariant, CREFSTRING featureFilter, INT32 maxFeatures, bool persist, INT32 layerAttributeFilter, INT32 requestData, CREFSTRING selectionColor, CREFSTRING selectionFormat) { Ptr<MgByteReader> result; Ptr<MgFeatureInformation> featureInfo; Ptr<MgBatchPropertyCollection> attributes; Ptr<MgByteReader> inlineSelectionImg; Ptr<MgSelection> newSelection; // Create a Resource Service instance Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService); // Create MgMap Ptr<MgMap> map = new MgMap(m_siteConn); map->Open(mapName); // Make sure we clear any track changes - these are not applicable for AJAX. Ptr<MgNamedCollection> changeLists = map->GetChangeLists(); if (changeLists->GetCount() > 0) { map->ClearChanges(); map->Save(); } // Create Proxy Rendering Service instance Ptr<MgRenderingService> service = (MgRenderingService*)(GetService(MgServiceType::RenderingService)); // Call the C++ API, regardless of bitmask as any part of the mask will require information from this API featureInfo = service->QueryFeatures(map, layerNames, selectionGeometry, selectionVariant, featureFilter, maxFeatures, layerAttributeFilter); if (persist) { //save the selection set in the session repository Ptr<MgSelection> selection; if (NULL != featureInfo.p) selection = featureInfo->GetSelection(); if(!selection) selection = new MgSelection(map); selection->Save(resourceService, mapName); newSelection = SAFE_ADDREF(selection.p); //Needed for GetLayers() to work below newSelection->SetMap(map); } // Render an image of this selection if requested if (((requestData & REQUEST_INLINE_SELECTION) == REQUEST_INLINE_SELECTION) && NULL != newSelection.p) { Ptr<MgColor> selColor = new MgColor(selectionColor); Ptr<MgRenderingOptions> renderOpts = new MgRenderingOptions(selectionFormat, MgRenderingOptions::RenderSelection | MgRenderingOptions::KeepSelection, selColor); inlineSelectionImg = service->RenderDynamicOverlay(map, newSelection, renderOpts); } // Collect any attributes of selected features if ((requestData & REQUEST_ATTRIBUTES) == REQUEST_ATTRIBUTES) { // This could be chunky for big selections, but client applications can control this via MAXFEATURES, so the onus is on them attributes = service->QueryFeatureProperties(map, layerNames, selectionGeometry, selectionVariant, L"", maxFeatures, layerAttributeFilter, true); } result = CollectQueryMapFeaturesResult(resourceService, requestData, featureInfo, newSelection, attributes, inlineSelectionImg); // Return XML return result.Detach(); }