[mapguide-users] new layer is not in the mapimage

Buscher, Shane Shane.Buscher at nngco.com
Thu Feb 8 17:16:40 EST 2007


Make sure that you refresh the map via the viewer api
(mapFrame.Refresh()) after you add and save it.  Also, there are some
known bugs with displaying layers created during runtime.  Here's the
workaround:
http://www.nabble.com/-Mapguide_users--FW%3A-Remove-layers-at-runtime-tf
2949430s16610.html#a8434534.  

-shane

-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of pribram
Sent: Thursday, February 08, 2007 6:40 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] new layer is not in the mapimage


Hi,
What I would like to do:
- remove all layers from the map in session
- change the xml definition for a layer and save it to session
repository
(remove the mMaxScale tag)
- add the new layer to the map in session repository
- use this map by getmapimage request

What's my problem:
when running the code bellow and then trying to get image by getmapimage
request to mapagent, the image is empty. I have tryied to loop through
the
maplayers in the map - the layer with the correct definition is there.

What's wrong here?

Thank's a lot for any idea.

MapGuideApi.MgInitializeWebTier(mgExtPath + "\\webconfig.ini");

string sessionId = null;
bool createSession = true;
MgUserInformation mgUserInfo;

//
mgUserInfo = new MgUserInformation();
if (sessionId != "" && sessionId != null)
{
	mgUserInfo.SetMgSessionId(sessionId);
	createSession = false;
}
else
{
	mgUserInfo.SetMgUsernamePassword("Anonymous", "");
}

//
if (createSession)
{
	MgSite mgSiteTmp = new MgSite();
	mgSiteTmp.Open(mgUserInfo);
	sessionId = mgSiteTmp.CreateSession();
}

//
mgUserInfo = new MgUserInformation(sessionId);
MgSiteConnection mgSite = new MgSiteConnection();
mgSite.Open(mgUserInfo);
MgResourceService mgResSrvc =
(MgResourceService)mgSite.CreateService(MgServiceType.ResourceService);

//
MgMap mgMapLib = new MgMap();
MgResourceIdentifier mgResIdMapInit = new MgResourceIdentifier(mapRes);
string mapNameInit = mgResIdMapInit.GetName();
mgMapLib.Create(mgResSrvc, mgResIdMapInit, mapNameInit);

//
MgSelection mgSelTmp = new MgSelection(mgMapLib);
mgSelTmp.Save(mgResSrvc, mapNameInit);

//
MgResourceIdentifier mgResIdMapSess = new
MgResourceIdentifier("Session:" +
sessionId + "//" + mapNameInit + "." + MgResourceType.Map);
mgMapLib.Save(mgResSrvc, mgResIdMapSess);

//
MgMap mgMapSess = new MgMap();
mgMapSess.Open(mgResSrvc, mgResIdMapSess);

//
MgLayerCollection mgLays = null;
MgLayer mgAcvLay = null;
MgResourceIdentifier mgResIdAcvLay = null;
string acvLayName = "";

mgLays = mgMapSess.GetLayers();
int cntLay = 0;
foreach (MgLayer mgLay in mgLays)
{
	if (cntLay == layOrder)
	{
		mgLay.Visible = true;
		mgResIdAcvLay = mgLay.GetLayerDefinition();
		acvLayName = mgLay.Name;
		mgAcvLay = mgLay;
	}
	cntLay++;
}

mgLays.Clear();
mgMapSess.Save(mgResSrvc);

if (mgAcvLay != null)
{
	//
	MgByteReader mgByteReader =
mgResSrvc.GetResourceContent(mgResIdAcvLay);
	String mapDefString = mgByteReader.ToString();
	XmlDocument xmlDoc = new XmlDocument();
	xmlDoc.LoadXml(mapDefString);

	//
	XmlNodeList xmlScaleRanges =
xmlDoc.GetElementsByTagName("VectorScaleRange");
	if (xmlScaleRanges.Count == 0)
	{
		xmlScaleRanges =
xmlDoc.GetElementsByTagName("GridScaleRange");
		if (xmlScaleRanges.Count == 0)
		{
			xmlScaleRanges =
xmlDoc.GetElementsByTagName("DrawingLayerDefinition");
		}
	}

	//
	for (int i = 0; i < xmlScaleRanges.Count; i++)
	{
		XmlElement xmlScaleRange =
(XmlElement)xmlScaleRanges[i];
		XmlNodeList xmlMaxScale =
xmlScaleRange.GetElementsByTagName("MaxScale");
		if (xmlMaxScale.Count > 0)
		{
			xmlScaleRange.RemoveChild(xmlMaxScale[0]);
		}
	}
	string xmlOut = xmlDoc.OuterXml;

	//
	MgByteSource mgByteSrc = new
MgByteSource(Encoding.UTF8.GetBytes(xmlOut),
xmlOut.Length);
	mgByteSrc.SetMimeType(MgMimeType.Xml);
	MgByteReader mgByteReaderOut = mgByteSrc.GetReader();
	MgResourceIdentifier mgResIdAcvLaySess = new
MgResourceIdentifier("Session:" + sessionId + "//" + acvLayName + "." +
MgResourceType.LayerDefinition);
	mgResSrvc.SetResource(mgResIdAcvLaySess, mgByteReaderOut, null);

	//
	MgLayer mgNewLay = new MgLayer(mgResIdAcvLaySess, mgResSrvc);
	mgNewLay.SetName("aaaaa");
	mgNewLay.SetVisible(true);
	mgNewLay.SetLegendLabel("");
	mgNewLay.DisplayInLegend = true;
	//mgNewLay.ForceRefresh();
	mgLays = mgMapSess.GetLayers();
	mgLays.Insert(0, mgNewLay);

	mgMapSess.Save(mgResSrvc);

	mgLays = mgMapSess.GetLayers();
}
-- 
View this message in context:
http://www.nabble.com/new-layer-is-not-in-the-mapimage-tf3193075s16610.h
tml#a8864579
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


More information about the mapguide-users mailing list