[mapguide-users] SetSelectionXML Problem (Selection and Zoom to selected Feature)

Sicky Christian.Rueh at rostock.zgdv.de
Wed Feb 17 08:17:44 EST 2010


I'm using MGOS 2.0 on Windows XP SP3 with Java/JavaScript.

Here's what I want to do: I want to select a feature and then zoom to it (at
the moment I do this with a click on a link to the jsp in that taskFrame).
And these are my steps:
1. Get the selection XML using MapGuide Web API
2. Call the function SetSelectionXML(…) with the selection XML
3. Call the function ExecuteMapAction(10)

Point 1 wasn't a problem, when I give the selection out (String selText =
selection.ToXml()) it looks like this which should be fine (tested with a
working search script which has the same selectionxml-output):
<?xml version="1.0" encoding="UTF-8"?><FeatureSet
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FeatureSet-1.0.0.xsd"> <Layer
id="9b54b844-fdf2-102c-8002-00ff14671d25">  <Class
id="Default:alk_alk_flurstueck">   <ID>rwMAAA==</ID>  </Class>
</Layer></FeatureSet>

But Point 2 keeps on nagging me the whole day, I just can't get this to
work, i searched the list the whole day and tried the following things:
parent.mapFrame.SetSelectionXML(<%=selText%>);
parent.parent.mapFrame.SetSelectionXML(<%=selText%>);
parent.SetSelectionXML(<%=selText%>);
parent.parent.SetSelectionXML(<%=selText%>);

none of this works, it never selects a feature on the map, not even when I
refresh the map myself.
Since parent.parent.mapFrame.Refresh(); and
parent.parent.mapFrame.ZoomToScale(10000); work I thought that
parent.parent.mapFrame.SetSelectionXML(<%=selText%>); would work too, but
that's not the case.
I don't get an error in the MGOS error-log but FireBug reports 2 errors:
1. missing ) after argument list
here: parent.parent.SetSelectionXML(...)
2. OnPageLoad is not defined

When I comment the SetSelectionXML parts out the map refreshes and no errors
are reported.

Here's my whole code:
<html>
<%@ page import="org.osgeo.mapguide.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>

<%@ include file="../common/common.jsp" %>
  <head>
    <title>Ort einzeichnen</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta http-equiv="content-script-type" content="text/javascript">
    <meta http-equiv="content-style-type" content="text/css">
    <link href="../styles/globalStyles.css" rel="stylesheet" 
type="text/css">
    <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
    
  </head>
  <body class="AppFrame" onLoad="OnPageLoad();">
    <h4 class="AppHeading">bla blubb</h4>
    <%
      String sessionId = request.getParameter("SESSION");
      String mapName = request.getParameter("MAPNAME");
      String selText = "";
	  
    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);
  
      // Get an instance of the required service(s).
      
      MgResourceService resourceService = (MgResourceService)
siteConnection.CreateService(MgServiceType.ResourceService);

      MgMap map = new MgMap(); 
      map.Open(resourceService, mapName);

      MgLayer layer = (MgLayer)
map.GetLayers().GetItem("WFS_NWM_ALKFlurstueck_WFSExp");
      String layerID = layer.GetFeatureSourceId();
      MgResourceIdentifier featureResId = new MgResourceIdentifier(layerID);
      MgFeatureService featureService = (MgFeatureService)
siteConnection.CreateService(MgServiceType.FeatureService);
      
	  String className = layer.GetFeatureClassName();
      String layerId = layer.GetObjectId();
      MgFeatureQueryOptions layerQuery = new MgFeatureQueryOptions();
      layerQuery.SetFilter("flurstkenn = '130171-017-00215/002.00'");
      MgFeatureReader featureReader =
featureService.SelectFeatures(featureResId, className, layerQuery);

      MgSelection selection = new MgSelection(map);

      selection.AddFeatures(layer, featureReader, 0);

      selText = selection.ToXml();
      System.out.println(selText);
      
    }
    catch (MgLayerNotFoundException e)
    {
      out.println("<p>Layer not found</p>");
    }
    catch (MgObjectNotFoundException e)
    {
      out.println("<p>Object not found</p>");
    }
    catch (MgException e)
    {
      out.println(e.GetMessage());
      out.println(e.GetDetails());
    }
  %>
</body>
    <script language="javascript" type="text/javascript">
      function OnPageLoad()
      {
        parent.parent.mapFrame.Refresh();
        parent.parent.mapFrame.ZoomToScale(10000);
		//parent.mapFrame.SetSelectionXML(<%=selText%>);
		//parent.parent.mapFrame.SetSelectionXML(<%=selText%>);
		//parent.SetSelectionXML(<%=selText%>);
		parent.parent.SetSelectionXML(<%=selText%>);
		//parent.ExecuteMapAction(10);
      }
    </script>
</html>

All I read on this list that this should work like I've done it but it just
doesn't work. I'd be greatful for any idea on how to solve this problem.
Thanks in advance :)
-- 
View this message in context: http://n2.nabble.com/SetSelectionXML-Problem-Selection-and-Zoom-to-selected-Feature-tp4585892p4585892.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list