<%@ page import="org.osgeo.mapguide.*" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="java.text.*" %> <%@ page import="javax.servlet.jsp.*" %> <%@ page import="javax.servlet.http.*" %> <%@ include file="../common/common.jsp" %> Rename layer

Rename Roads Layer

<% String sessionId = request.getParameter("SESSION"); String mapName = request.getParameter("MAPNAME"); try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP // session state. MapGuideJavaApi.MgInitializeWebTier(webconfigFilePath); // Get the user information using the session id, // and set up a connection to the site server. MgUserInformation userInfo = new MgUserInformation(sessionId); MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgMap map = new MgMap(siteConnection); map.Open(mapName); MgLayerCollection layers = map.GetLayers(); // Get layer collection MgLayer roadLayer = (MgLayer) layers.GetItem("Roads"); String roadLabel = roadLayer.GetLegendLabel(); String newLabel; if (roadLabel.equals("Roads")) newLabel = "Streets"; else newLabel = "Roads"; roadLayer.SetLegendLabel(newLabel); // You must save the updated map or the // changes will not be applied // Also be sure to refresh the map on page load. map.Save(); out.println("

Layer label has been changed to " + newLabel + ".

"); out.println("

Run again

"); } catch (MgLayerNotFoundException e) { out.println("

Layer not found

"); } catch (MgObjectNotFoundException e) { out.println("

Layer not found

"); } catch (MgException e) { out.println(e.GetExceptionMessage()); out.println(e.GetDetails()); } %>