[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:


"Internal server error" in GetSelectionProperties.php

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

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

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

IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
	"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 =
	IVectorLayerDefinition vl =
	vl.FeatureName = featureClass;
	string ldfId = "Session:" + sessionId +
	conn.ResourceService.SaveResourceAs(layerFiltrato, ldfId);

	//	create a Session: Map
	MapDefinition rtmap =
	IMapLayer layerold = rtmap.GetLayerByName("Verticale");
	rtmap.AddLayer(layerold, "", "VerticaleFiltrato", ldfId);
	string MapId = "Session:" + sessionId +

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

	//	create the Session Flexible Layout
	ApplicationDefinitionType layoutRes =
	layoutRes.MapSet[0].Map[0].Extension.Any[0].InnerText = MapId;
	layoutRes.MapSet[0].Map[0].Extension.Any[0].InnerXml = MapId;
	string resId = "Session:" + sessionId +
	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(
	"Url", agent,
	"SessionId", session);

IMappingService mpSvc =
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 =
IVectorLayerDefinition vl = (IVectorLayerDefinition)ldf.SubLayer;

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

string ldfId = "Session:" + conn.SessionID +
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.Insert(layerIndex, replace);


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, 


More information about the mapguide-users mailing list