[mapguide-users] set filter on layer at runtime make selection tools not work

Franco Caloni franco.caloni at stacec.com
Tue Jul 1 09:03:43 PDT 2014


Hi all,
following the samples in Maestro SDK (ModifyParcelsFilter.cs), I'm setting a
filter on a layer at runtime.
The filter works and the features become filtered, but then when I try to
select the features on the filtered layer I got this error:

http://prntscr.com/3ycbja

"Internal server error" in GetSelectionProperties.php

This is what I do:
before the app starts I create "Session:" objects (layer, map &
FlexibleLayout)

-------------------	startup    -----------------------
string cnfg = ConfigurationManager.AppSettings["mgwebinipath"].ToString();
MapGuideApi.MgInitializeWebTier(cnfg);
MgUserInformation userInfo = new MgUserInformation("theuser",
"thepassword");
MgSite site = new MgSite();
site.Open(userInfo);
var sessionId = site.CreateSession();

string agent = "http://localhost/mapguide/mapagent/mapagent.fcgi";

IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
	"Maestro.Http",
	"Url", agent,
	"SessionId", sessionId.ToString());

var layoutMio = "Library://Demo/Layouts/L1.ApplicationDefinition";
var layerVerticale = "Library://Demo/Layers/Verticale.LayerDefinition";
var mappaMia = "Library://Demo/Mappe/MappaDemo.MapDefinition";
var featureClass = "Default:vimpianti";
var wrkmappa = mappaMia;
if (conn.ResourceService.ResourceExists(wrkmappa))
{
	//	create a Session: Layer
	ILayerDefinition layerFiltrato =
(ILayerDefinition)conn.ResourceService.GetResource(layerVerticale);
	IVectorLayerDefinition vl =
(IVectorLayerDefinition)layerFiltrato.SubLayer;
	vl.FeatureName = featureClass;
	string ldfId = "Session:" + sessionId +
"//VerticaleRuntime.LayerDefinition";
	conn.ResourceService.SaveResourceAs(layerFiltrato, ldfId);


	//	create a Session: Map
	MapDefinition rtmap =
(MapDefinition)conn.ResourceService.GetResource(mappaMia);
	IMapLayer layerold = rtmap.GetLayerByName("Verticale");
	rtmap.AddLayer(layerold, "", "VerticaleFiltrato", ldfId);
	rtmap.MapLayer.RemoveAt(2);
	string MapId = "Session:" + sessionId +
"//MappaRunTime.MapDefinition";

	rtmap.Name = "MappaF";
	conn.ResourceService.SaveResourceAs(rtmap, MapId);


	//	create the Session Flexible Layout
	ApplicationDefinitionType layoutRes =
(ApplicationDefinitionType)conn.ResourceService.GetResource(layoutMio);
	layoutRes.MapSet[0].Map[0].Extension.Any[0].InnerText = MapId;
	layoutRes.MapSet[0].Map[0].Extension.Any[0].InnerXml = MapId;
	string resId = "Session:" + sessionId +
"//SessionLayout.ApplicationDefinition";
	conn.ResourceService.SaveResourceAs(layoutRes, resId);

	// go to the application page
	Response.Redirect("/cartografia.aspx?ApplicationDefinition=" + resId
+ "&SESSION=" + sessionId);
}
------------------- end of startup    -----------------------


To set the filter at runtime (in the Task pane):


string agent = "http://localhost/mapguide/mapagent/mapagent.fcgi";
string cnfg = ConfigurationManager.AppSettings["mgwebinipath"].ToString();
var session = Request.Params["SESSION"];
var mapName = Request.Params["MAPNAME"];

IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
	"Maestro.Http",
	"Url", agent,
	"SessionId", session);

IMappingService mpSvc =
(IMappingService)conn.GetService((int)ServiceType.Mapping);
string rtMapId = "Session:" + conn.SessionID + "//" + mapName + ".Map";

RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
int layerIndex = rtMap.Layers.IndexOf("VerticaleFiltrato");
RuntimeMapLayer layer = rtMap.Layers[layerIndex];

ILayerDefinition ldf =
(ILayerDefinition)conn.ResourceService.GetResource(layer.LayerDefinitionID);
IVectorLayerDefinition vl = (IVectorLayerDefinition)ldf.SubLayer;

if (string.IsNullOrEmpty(vl.Filter))
	vl.Filter = "rid = 10265";
else
	vl.Filter = "";

string ldfId = "Session:" + conn.SessionID +
"//VerticaleFiltered.LayerDefinition";
conn.ResourceService.SaveResourceAs(ldf, ldfId);

ldf.ResourceID = ldfId;

RuntimeMapLayer replace = mpSvc.CreateMapLayer(rtMap, ldf);
replace.ExpandInLegend = layer.ExpandInLegend;
replace.Group = layer.Group;
replace.LegendLabel = layer.LegendLabel;
replace.Name = layer.Name;
replace.Selectable = layer.Selectable;
replace.ShowInLegend = layer.ShowInLegend;
replace.Visible = layer.Visible;

rtMap.Layers.RemoveAt(layerIndex);
rtMap.Layers.Insert(layerIndex, replace);
replace.ForceRefresh();

rtMap.Save();


Selecting features on other layers give no error, so I suppose the problem
is in the runtime filtered layer, but don't know what I'm doing wrong here

Thanks for your help, 

Franco




More information about the mapguide-users mailing list