[mapguide-users] new layer is not in the mapimage
pribram
rryda at post.cz
Thu Feb 8 07:40:11 EST 2007
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.html#a8864579
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list