I think i got the gist, but will this also work with fusion? I am currently using the fusion templates. I was wondering if i could also do this with .net to rebuild the mapdefinition or layer definition.
You have to manipulate MgMap/MgLayer objects, so you have to use a server-side script. It doesn't have to be .net. It could be in Java or PHP. But it has to be one of the 3 languages which can work with the MapGuide Web API.
Your script needs to take in mapname/sessionid and do the following:
- Opens the MgMap from the mapname - Finds the matching MgLayer in the map's layer collection by its layer name - Make a new MgLayer that points to your new layer definition - Replace the matching MgLayer with your new MgLayer - Insert the new MgLayer to the layer collection at the matching index of the old MgLayer - Remove the old MgLayer from the layer collection - Save the map state and trigger a map refresh back on the client-side
I have created layer definition from each maps on Maestro and just 1 MapDefinition, What i am trying to do is the just updated the layerdefinition of the mapdefinition to the specific selected map. I wanted to do it runtime. I cam currtently using fusion, is this possible to do on JS or just .net? And how? i am quite stuck now.
Also another option for me to do is the create mapdefinition on runtime, but still no success on doing this.
//if mapName is empty, I just want to work with session repository, no map operations
if (mapName != "")
map = new MgMap(siteConnection);
catch (Exception ex)
throw new Exception(ex.Message);
/// <summary> /// Set a filter to a Layer in session repository
/// </summary> /// Layer Name /// Filter condition /// <returns>Operation success</returns> public bool SetLayerFilter(string strLayerName, string strFilter)
// Set a filter to a temporary layer created based on an original one.
MgResourceIdentifier resId, resIdTemp;
MgLayerBase layer, layerTemp;
//Verify if Layer Name is the temporary layer. If It is, correct to original Layer Name.
if (strLayerName.IndexOf(strTempLayerSufix) > 0)
strLayerName = strLayerName.Replace(strTempLayerSufix, "");
//Use random name to avoid overwrites
strLayerNameForSession = strLayerName + this.strTempLayerSufix;
//Test if the original or temporary layers existis
if (GetLayerByName(map, strLayerName) == null && GetLayerByName(map, strLayerNameForSession) == null)
//Test if the filter is not null
if (strFilter == null)
strFilter = "";
//Get the temporary layer
layer = GetLayerByName(map, strLayerNameForSession);
//Get the original layer, if temporary later not exist
if (layer == null)
layer = GetLayerByName(map, strLayerName);
//If the temp resource was not created, read the original xml
tempResource = "Session:" + strSessionMap + "//" + strLayerNameForSession + "." + MgResourceType.LayerDefinition;
resIdTemp = new MgResourceIdentifier(tempResource);
//Read the resource original layer
resId = layer.GetLayerDefinition();
strXml = (resourceService.GetResourceContent(resId)).ToString();
Put in UtilMap class:
/// <summary> /// Refresh the Map in the Client using JavaScrit
/// </summary> /// Page Object calling this method public void RefreshMapClient(Page objPage)
string strScript = "";
The layer definition is a xml where you can modify all atributes, including featuresourceid , featureclassname, etc. Debug the code and examine the string xml layer read in the set filter method.
You read this xml, modify and write it back. This can be used to map definition, feature source definition, web layout definition.
Also, sorry for asking this here cause i know ive already posted this on a new thread.
Do you happen to know how to refresh the jxpanel? because it seems that when i replaces all the layers via the .net api's, the jxpanels doesnt work anymore with the changed map, the legends and the selections doesnt work anymore.
Back again, was able to make it work before with MapGuide 2.6.1 32bit now upgraded to 3.1.0 64bit.. Same code with changing layer at runtime.. funny thing now, nothing happens, but if select something on the map, it throws an error inside fusion-compressed.js, 'layerName' does not exists.
From the c# code layers.remove(layer) it did work it seems that the layer was really removed on the map.. but the mapwidget itself didnt refresh to the new layer, it still looks the same. did call the command. mapWidget.redraw, mapWidget.reloadMap(). but nothing happens.
Tried almost everything but its not working at all..
Have you experience that after doing this update of layer using ajax and
redraw a couple of time. Mapguide server breaks? because i suddenly get
session expired or magguide server is not responding.. Im on the site the
whole time and doing switching of layers to stress test it. But suddenly it
turned pink and got that message reload map and got that error.