[mapguide-commits] r10291 - in branches/4.0/MgDev/Doc/samples/javasamples: . analyzing_features common custom_output digitizing_features hello_map hello_viewer interacting_with_layers modifying_maps_and_layers viewerfiles working_with_feature_data
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Nov 18 07:26:40 PST 2026
Author: jng
Date: 2026-11-18 07:26:37 -0800 (Wed, 18 Nov 2026)
New Revision: 10291
Added:
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferfunctions.jsp
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferlayerdefinition.xml
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/createbuffer.jsp
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/parcelmarker.xml
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/selectfeaturesinbuffer.jsp
branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/common/mapinfo.jsp
branches/4.0/MgDev/Doc/samples/javasamples/common/viewresourcecontent.jsp
branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.jsp
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/createmapimage.jsp
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/eplot.jsp
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/multiplot.jsp
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/property_report.jsp
branches/4.0/MgDev/Doc/samples/javasamples/custom_output/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/clear_lines.jsp
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/draw_line.jsp
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_digitizing.jsp
branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_redlining.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/RecentlyBuilt.LayerDefinition
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/change_layers_via_dom.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_line_layer_definition.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_point_layer_definition.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_squarefootage_layer_definition.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/layer_functions.jsp
branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/arearule.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/areatypestyle.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/layerdefinition.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linerule.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linetypestyle.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/marksymbol.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointrule.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointtypestyle.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/scalerange.templ
branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/textsymbol.templ
branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/
branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/listselection.jsp
branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/queryfeatures.jsp
branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/selectfeatures.jsp
branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/task_pane.jsp
Removed:
branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.php
Modified:
branches/4.0/MgDev/Doc/samples/javasamples/common/common.jsp
branches/4.0/MgDev/Doc/samples/javasamples/hello_map/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/gotopoint.jsp
branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/index.jsp
branches/4.0/MgDev/Doc/samples/javasamples/interacting_with_layers/task_pane.jsp
branches/4.0/MgDev/Doc/samples/javasamples/readme.txt
Log:
Bring javasamples to parity with PHP and .net. Fixes #2902
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferfunctions.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferfunctions.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferfunctions.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,171 @@
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../modifying_maps_and_layers/layer_functions.jsp" %>
+<%!
+public static class BufferHelper
+{
+ private final File pageDir;
+
+ public BufferHelper(HttpServletRequest request)
+ {
+ // The layer definition templates used here live beside this sample group.
+ this.pageDir = new File(request.getServletContext().getRealPath(request.getServletPath())).getParentFile();
+ }
+
+ public void createBufferFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier bufferFeatureResId)
+ {
+ MgClassDefinition bufferClass = new MgClassDefinition();
+ bufferClass.setName("BufferClass");
+ MgPropertyDefinitionCollection properties = bufferClass.getProperties();
+
+ MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
+ idProperty.setDataType(MgPropertyType.Int32);
+ idProperty.setReadOnly(true);
+ idProperty.setNullable(false);
+ idProperty.setAutoGeneration(true);
+ properties.add(idProperty);
+
+ MgGeometricPropertyDefinition polygonProperty = new MgGeometricPropertyDefinition("BufferGeometry");
+ polygonProperty.setGeometryTypes(MgFeatureGeometricType.Surface);
+ polygonProperty.setHasElevation(false);
+ polygonProperty.setHasMeasure(false);
+ polygonProperty.setReadOnly(false);
+ polygonProperty.setSpatialContextAssociation("defaultSrs");
+ properties.add(polygonProperty);
+
+ MgPropertyDefinitionCollection idProperties = bufferClass.getIdentityProperties();
+ idProperties.add(idProperty);
+
+ bufferClass.setDefaultGeometryPropertyName("BufferGeometry");
+
+ MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", "temporary schema to hold a buffer");
+ bufferSchema.getClasses().add(bufferClass);
+
+ MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "defaultSrs", wkt, bufferSchema);
+
+ featureService.createFeatureSource(bufferFeatureResId, sdfParams);
+ }
+
+ public MgLayer createBufferLayer(MgResourceService resourceService, MgResourceIdentifier bufferFeatureResId, String sessionId) throws Exception
+ {
+ // Load the layer definition template into
+ // a DOM document, find the "ResourceId" element, and
+ // modify its content to reference the temporary
+ // feature source.
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(pageDir, "bufferlayerdefinition.xml"));
+ Node featureSourceNode = doc.getElementsByTagName("ResourceId").item(0);
+ featureSourceNode.setTextContent(bufferFeatureResId.toString());
+
+ // Get the updated layer definition from the DOM document
+ // and save it to the session repository using the
+ // ResourceService object.
+
+ byte[] layerDefinition = LayerFunctions.documentToBytes(doc);
+ MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.length);
+ byteSource.setMimeType(MgMimeType.Xml);
+
+ MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.LayerDefinition");
+
+ resourceService.setResource(tempLayerResId, byteSource.getReader(), null);
+
+ // Create an MgLayer object based on the new layer definition
+ // and return it to the caller.
+
+ MgLayer bufferLayer = new MgLayer(tempLayerResId, resourceService);
+ bufferLayer.setName("Buffer");
+ bufferLayer.setLegendLabel("Buffer");
+ bufferLayer.setDisplayInLegend(true);
+ bufferLayer.setSelectable(false);
+
+ return bufferLayer;
+ }
+
+ public void createParcelMarkerFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier parcelMarkerDataResId)
+ {
+ MgClassDefinition parcelClass = new MgClassDefinition();
+ parcelClass.setName("ParcelMarkerClass");
+ MgPropertyDefinitionCollection properties = parcelClass.getProperties();
+
+ MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
+ idProperty.setDataType(MgPropertyType.Int32);
+ idProperty.setReadOnly(true);
+ idProperty.setNullable(false);
+ idProperty.setAutoGeneration(true);
+ properties.add(idProperty);
+
+ MgGeometricPropertyDefinition pointProperty = new MgGeometricPropertyDefinition("ParcelLocation");
+ pointProperty.setGeometryTypes(MgGeometryType.Point);
+ pointProperty.setHasElevation(false);
+ pointProperty.setHasMeasure(false);
+ pointProperty.setReadOnly(false);
+ pointProperty.setSpatialContextAssociation("defaultSrs");
+ properties.add(pointProperty);
+
+ MgPropertyDefinitionCollection idProperties = parcelClass.getIdentityProperties();
+ idProperties.add(idProperty);
+
+ parcelClass.setDefaultGeometryPropertyName("ParcelLocation");
+
+ MgFeatureSchema parcelSchema = new MgFeatureSchema("ParcelLayerSchema", "temporary schema to hold parcel markers");
+ parcelSchema.getClasses().add(parcelClass);
+
+ MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "defaultSrs", wkt, parcelSchema);
+
+ featureService.createFeatureSource(parcelMarkerDataResId, sdfParams);
+ }
+
+ public MgLayer createParcelMarkerLayer(MgResourceService resourceService, MgResourceIdentifier parcelMarkerDataResId, String sessionId) throws Exception
+ {
+ // Load the ParcelMarker layer definition template into
+ // a DOM document, find the "ResourceId" element, and
+ // modify its content to reference the temporary
+ // feature source.
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(pageDir, "parcelmarker.xml"));
+ Node featureSourceNode = doc.getElementsByTagName("ResourceId").item(0);
+ featureSourceNode.setTextContent(parcelMarkerDataResId.toString());
+
+ // Get the updated layer definition from the DOM document
+ // and save it to the session repository using the
+ // ResourceService object.
+
+ byte[] layerDefinition = LayerFunctions.documentToBytes(doc);
+ MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.length);
+ byteSource.setMimeType(MgMimeType.Xml);
+
+ MgResourceIdentifier tempLayerResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.LayerDefinition");
+
+ resourceService.setResource(tempLayerResId, byteSource.getReader(), null);
+
+ // Create an MgLayer object based on the new layer definition
+ // and return it to the caller.
+
+ MgLayer parcelMarkerLayer = new MgLayer(tempLayerResId, resourceService);
+ parcelMarkerLayer.setName("ParcelMarker");
+ parcelMarkerLayer.setLegendLabel("ParcelMarker");
+ parcelMarkerLayer.setDisplayInLegend(true);
+ parcelMarkerLayer.setSelectable(false);
+
+ return parcelMarkerLayer;
+ }
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferlayerdefinition.xml
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferlayerdefinition.xml (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/bufferlayerdefinition.xml 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+ <LayerDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="LayerDefinition-1.1.0.xsd" version="1.1.0">
+ <VectorLayerDefinition>
+ <ResourceId></ResourceId>
+ <FeatureName>BufferClass</FeatureName>
+ <FeatureNameType>FeatureClass</FeatureNameType>
+ <Geometry>BufferGeometry</Geometry>
+ <VectorScaleRange>
+ <AreaTypeStyle>
+ <AreaRule>
+ <LegendLabel>Buffer</LegendLabel>
+ <AreaSymbolization2D>
+ <Fill>
+ <FillPattern>Solid</FillPattern>
+ <ForegroundColor>22AA00AA</ForegroundColor>
+ <BackgroundColor>FF000000</BackgroundColor>
+ </Fill>
+ <Stroke>
+ <LineStyle>Solid</LineStyle>
+ <Thickness>0</Thickness>
+ <Color>FF666666</Color>
+ <Unit>Inches</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ </Stroke>
+ </AreaSymbolization2D>
+ </AreaRule>
+ </AreaTypeStyle>
+ </VectorScaleRange>
+ </VectorLayerDefinition>
+ </LayerDefinition>
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/createbuffer.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/createbuffer.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/createbuffer.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,195 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<!--
+This sample has been updated to reflect simplified usage patterns enabled by convenience APIs
+introduced in MapGuide OS 2.0 by allowing you to query and insert features directly from
+the MgLayer objects themselves and the ability to get a MgFeatureReader directly from the MgSelection
+object
+-->
+
+<%@ page import="java.io.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="bufferfunctions.jsp" %>
+<html>
+<head>
+ <title>Viewer Sample Application - Create Buffer</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">
+
+ <script language="javascript">
+ function OnPageLoad() {
+ parent.parent.Refresh();
+ }
+ </script>
+
+</head>
+<body class="AppFrame" onload="OnPageLoad()">
+ <h1 class="AppHeading">Create buffer</h1>
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ String selectionXml = request.getParameter("SELECTION");
+ selectionXml = (selectionXml != null && selectionXml.length() > 0) ? URLDecoder.decode(selectionXml, "UTF-8") : "";
+
+ try
+ {
+ // Initialize the Web Extensions and connect to the Server.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.createService(MgServiceType.FeatureService);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // Check for selection data passed via HTTP POST
+
+ MgSelection selection = null;
+ MgReadOnlyLayerCollection selectedLayers = null;
+ if (selectionXml.length() > 0)
+ {
+ selection = new MgSelection(map, selectionXml);
+ selectedLayers = selection.getLayers();
+ }
+
+ if (selectedLayers != null)
+ {
+ int bufferRingSize = 100; // measured in metres
+ int bufferRingCount = 5;
+
+ // Set up some objects for coordinate conversion
+
+ String mapWktSrs = map.getMapSRS();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
+ MgCoordinateSystem srs = coordinateSystemFactory.create(mapWktSrs);
+ MgMeasure srsMeasure = srs.getMeasure();
+
+ BufferHelper helper = new BufferHelper(request);
+
+ // Check for a buffer layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the buffer.
+
+ MgLayer bufferLayer = null;
+ int layerIndex = map.getLayers().indexOf("Buffer");
+ if (layerIndex < 0)
+ {
+ // The layer does not exist and must be created.
+
+ MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
+ helper.createBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
+ bufferLayer = helper.createBufferLayer(resourceService, bufferFeatureResId, sessionId);
+ map.getLayers().insert(0, bufferLayer);
+ }
+ else
+ {
+ bufferLayer = (MgLayer)map.getLayers().getItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.add(new MgDeleteFeatures("BufferClass", "ID like '%'"));
+
+ bufferLayer.updateFeatures(commands);
+ }
+
+ for (int i = 0; i < selectedLayers.getCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+
+ MgLayer layer = (MgLayer)selectedLayers.getItem(i);
+
+ if (layer.getName().equals("Parcels"))
+ {
+ // Get the selected features from the MgSelection object
+ MgFeatureReader featureReader = selection.getSelectedFeatures(layer, layer.getFeatureClassName(), false);
+
+ // Process each item in the MgFeatureReader. Get the
+ // geometries from all the selected features and
+ // merge them into a single geometry.
+
+ MgGeometryCollection inputGeometries = new MgGeometryCollection();
+ while (featureReader.readNext())
+ {
+ MgByteReader featureGeometryData = featureReader.getGeometry("SHPGEOM");
+ MgGeometry featureGeometry = agfReaderWriter.read(featureGeometryData);
+
+ inputGeometries.add(featureGeometry);
+ }
+
+ MgGeometryFactory geometryFactory = new MgGeometryFactory();
+ MgGeometry mergedGeometries = geometryFactory.createMultiGeometry(inputGeometries);
+
+ // Add buffer features to the temporary feature source.
+ // Create multiple concentric buffers to show area.
+ // If the stylization for the layer draws the features
+ // partially transparent, the concentric rings will be
+ // progressively darker towards the center.
+ // The stylization is set in the layer template file, which
+ // is used in createBufferLayer().
+
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++)
+ {
+ double bufferDist = srs.convertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1));
+ MgGeometry bufferGeometry = mergedGeometries.buffer(bufferDist, srsMeasure);
+
+ MgPropertyCollection properties = new MgPropertyCollection();
+ properties.add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.write(bufferGeometry)));
+
+ commands.add(new MgInsertFeatures("BufferClass", properties));
+ }
+
+ bufferLayer.updateFeatures(commands);
+
+ bufferLayer.setVisible(true);
+ bufferLayer.forceRefresh();
+ bufferLayer.setDisplayInLegend(true);
+ map.save();
+
+ }
+ }
+ }
+ else
+ out.print("No selected layers");
+ out.print("</p>");
+
+ }
+ catch (MgException e)
+ {
+ out.print("<p>" + e.getExceptionMessage() + "</p>");
+ out.print("<p>" + e.getDetails() + "</p>");
+ }
+ catch (Exception e)
+ {
+ out.print("<p>" + e.toString() + "</p>");
+ }
+ %>
+ <p>The buffer has been created.</p>
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/parcelmarker.xml
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/parcelmarker.xml (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/parcelmarker.xml 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LayerDefinition version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="LayerDefinition-1.1.0.xsd">
+ <VectorLayerDefinition>
+ <ResourceId></ResourceId>
+ <FeatureName>ParcelMarkerClass</FeatureName>
+ <FeatureNameType>FeatureClass</FeatureNameType>
+ <Geometry>ParcelLocation</Geometry>
+ <VectorScaleRange>
+ <MinScale>0</MinScale>
+ <MaxScale>10000</MaxScale>
+ <PointTypeStyle>
+ <DisplayAsText>false</DisplayAsText>
+ <AllowOverpost>false</AllowOverpost>
+ <PointRule>
+ <LegendLabel></LegendLabel>
+ <PointSymbolization2D>
+ <Mark>
+ <Unit>Inches</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ <SizeX>.1</SizeX>
+ <SizeY>.1</SizeY>
+ <Rotation>0</Rotation>
+ <Shape>X</Shape>
+ <Fill>
+ <FillPattern>Solid</FillPattern>
+ <ForegroundColor>FFFF0000</ForegroundColor>
+ <BackgroundColor>ff000000</BackgroundColor>
+ </Fill>
+ <Edge>
+ <LineStyle>Solid</LineStyle>
+ <Thickness>0.0</Thickness>
+ <Color>ff000000</Color>
+ <Unit>Centimeters</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ </Edge>
+ </Mark>
+ </PointSymbolization2D>
+ </PointRule>
+ </PointTypeStyle>
+ </VectorScaleRange>
+ </VectorLayerDefinition>
+</LayerDefinition>
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/selectfeaturesinbuffer.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/selectfeaturesinbuffer.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/selectfeaturesinbuffer.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,262 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<!--
+This sample has been updated to reflect simplified usage patterns enabled by convenience APIs
+introduced in MapGuide OS 2.0 by allowing you to query and insert features directly from
+the MgLayer objects themselves and the ability to get a MgFeatureReader directly from the MgSelection
+object.
+-->
+
+<%@ page import="java.io.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="bufferfunctions.jsp" %>
+<html>
+<head>
+ <title>Viewer Sample Application - Select Within Buffer</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">
+
+ <script language="javascript">
+ function OnPageLoad() {
+ parent.parent.Refresh();
+ }
+ </script>
+
+</head>
+<body class="AppFrame" onload="OnPageLoad()">
+ <h1 class="AppHeading">
+ Select within buffer area</h1>
+ <%
+
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ String selectionXml = request.getParameter("SELECTION");
+ selectionXml = (selectionXml != null && selectionXml.length() > 0) ? URLDecoder.decode(selectionXml, "UTF-8") : "";
+
+ try
+ {
+ // Initialize the Web Extensions and connect to the Server.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.createService(MgServiceType.FeatureService);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // Check for selection data passed via HTTP POST
+
+ MgSelection selection = null;
+ MgReadOnlyLayerCollection selectedLayers = null;
+ if (selectionXml.length() > 0)
+ {
+ selection = new MgSelection(map, selectionXml);
+ selectedLayers = selection.getLayers();
+ }
+
+ if (selectedLayers != null)
+ {
+ int bufferRingSize = 500; // measured in metres
+
+ // Set up some objects for coordinate conversion
+
+ String mapWktSrs = map.getMapSRS();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
+ MgCoordinateSystem srs = coordinateSystemFactory.create(mapWktSrs);
+ MgMeasure srsMeasure = srs.getMeasure();
+
+ // Check for a buffer layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the buffer.
+
+ BufferHelper helper = new BufferHelper(request);
+ MgLayer bufferLayer = null;
+ int layerIndex = map.getLayers().indexOf("Buffer");
+ if (layerIndex < 0)
+ {
+ // The layer does not exist and must be created.
+
+ MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
+ helper.createBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
+ bufferLayer = helper.createBufferLayer(resourceService, bufferFeatureResId, sessionId);
+ map.getLayers().insert(0, bufferLayer);
+ }
+ else
+ {
+ bufferLayer = (MgLayer)map.getLayers().getItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.add(new MgDeleteFeatures("BufferClass", "ID like '%'"));
+
+ bufferLayer.updateFeatures(commands);
+ }
+
+ // Check for a parcel marker layer. If it exists, delete
+ // the current features.
+ // If it does not exist, create a feature source and
+ // a layer to hold the parcel markers.
+
+ MgLayer parcelMarkerLayer = null;
+ layerIndex = map.getLayers().indexOf("ParcelMarker");
+ if (layerIndex < 0)
+ {
+ MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
+ helper.createParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
+ parcelMarkerLayer = helper.createParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
+ map.getLayers().insert(0, parcelMarkerLayer);
+ }
+ else
+ {
+ parcelMarkerLayer = (MgLayer)map.getLayers().getItem(layerIndex);
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.add(new MgDeleteFeatures("ParcelMarkerClass", "ID like '%'"));
+
+ parcelMarkerLayer.updateFeatures(commands);
+ }
+
+ // Check each layer in the selection.
+
+ for (int i = 0; i < selectedLayers.getCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+
+ MgLayer layer = (MgLayer)selectedLayers.getItem(i);
+
+ if (layer.getName().equals("Parcels"))
+ {
+
+ out.print( "Marking all parcels inside the buffer that are of type 'MFG'");
+
+ MgFeatureReader featureReader = selection.getSelectedFeatures(layer, layer.getFeatureClassName(), false);
+
+ // Process each item in the MgFeatureReader. Get the
+ // geometries from all the selected features and
+ // merge them into a single geometry.
+
+ MgGeometryCollection inputGeometries = new MgGeometryCollection();
+ while (featureReader.readNext())
+ {
+ MgByteReader featureGeometryData = featureReader.getGeometry("SHPGEOM");
+ MgGeometry featureGeometry = agfReaderWriter.read(featureGeometryData);
+
+ inputGeometries.add(featureGeometry);
+ }
+
+ MgGeometryFactory geometryFactory = new MgGeometryFactory();
+ MgGeometry mergedGeometries = geometryFactory.createMultiGeometry(inputGeometries);
+
+ // Create a buffer from the merged geometries
+
+ double bufferDist = srs.convertMetersToCoordinateSystemUnits(bufferRingSize);
+ MgGeometry bufferGeometry = mergedGeometries.buffer(bufferDist, srsMeasure);
+
+ // Create a filter to select parcels within the buffer. Combine
+ // a basic filter and a spatial filter to select all parcels
+ // within the buffer that are of type "MFG".
+
+ MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
+ queryOptions.setFilter("RTYPE = 'MFG'");
+ queryOptions.setSpatialFilter("SHPGEOM", bufferGeometry, MgFeatureSpatialOperations.Inside);
+
+ featureReader = layer.selectFeatures(queryOptions);
+
+ // Get the features from the feature source,
+ // determine the centroid of each selected feature, and
+ // add a point to the ParcelMarker layer to mark the
+ // centroid.
+ // Collect all the points into an MgFeatureCommandCollection,
+ // so they can all be added in one operation.
+
+ MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
+ while (featureReader.readNext())
+ {
+ MgByteReader byteReader = featureReader.getGeometry("SHPGEOM");
+ MgGeometry geometry = agfReaderWriter.read(byteReader);
+ MgPoint point = geometry.getCentroid();
+
+ // Create an insert command for this parcel.
+ MgPropertyCollection properties = new MgPropertyCollection();
+ properties.add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.write(point)));
+ parcelMarkerCommands.add(new MgInsertFeatures("ParcelMarkerClass", properties));
+ }
+ featureReader.close();
+
+ if (parcelMarkerCommands.getCount() > 0)
+ {
+ parcelMarkerLayer.updateFeatures(parcelMarkerCommands);
+ }
+ else
+ {
+ out.print("</p><p>No parcels within the buffer area match.");
+ }
+
+ // Create a feature in the buffer feature source to show the area covered by the buffer.
+
+ MgPropertyCollection props = new MgPropertyCollection();
+ props.add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.write(bufferGeometry)));
+
+ MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
+ commands.add(new MgInsertFeatures("BufferClass", props));
+
+ bufferLayer.updateFeatures(commands);
+
+ // Ensure that the buffer layer is visible and in the legend.
+
+ bufferLayer.setVisible(true);
+ bufferLayer.forceRefresh();
+ bufferLayer.setDisplayInLegend(true);
+ parcelMarkerLayer.setVisible(true);
+ parcelMarkerLayer.forceRefresh();
+
+ map.save();
+
+ }
+ }
+ }
+ else
+ {
+ out.print( "No selected layers");
+ out.print( "</p>");
+ }
+
+ }
+ catch (MgException e)
+ {
+ out.print( "<p>" + e.getExceptionMessage() + "</p>");
+ out.print( "<p>" + e.getDetails() + "</p>");
+ }
+ catch (Exception e)
+ {
+ out.print( "<p>" + e.toString() + "</p>");
+ }
+ %>
+ <p>Done.</p>
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/task_pane.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/analyzing_features/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,85 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <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">
+ <script language=javascript>
+ function submitBufferRequest(pageUrl)
+ {
+ xmlSel = parent.parent.mapFrame.GetSelectionXML();
+ if (xmlSel.length > 0)
+ {
+ params = new Array("SESSION", parent.parent.mapFrame.GetSessionId(),
+ "MAPNAME", parent.parent.mapFrame.GetMapName(),
+ "SELECTION", encodeURIComponent(xmlSel));
+ parent.parent.formFrame.Submit(pageUrl, params, "taskPaneFrame");
+ }
+ else {
+ alert ("Please select a parcel");
+ }
+ }
+
+ function OnPageLoad()
+ {
+ parent.parent.mapFrame.Refresh();
+ parent.parent.mapFrame.ZoomToScale(9999);
+ }
+ </script>
+ </head>
+ <body onLoad="OnPageLoad()" class="AppFrame">
+ <h1 class="AppHeading">Analyzing Features</h1>
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <ul>
+ <li>
+ <a href="#" onClick="submitBufferRequest('/mapguide/javasamples/analyzing_features/createbuffer.jsp'); return false;">
+ Create buffer</a>
+ <br/>Create a buffer around a selected parcel.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "createbuffer.jsp") %>" >View source</a>
+ </li>
+
+ <li>
+ <a href="#" onClick="submitBufferRequest('/mapguide/javasamples/analyzing_features/selectfeaturesinbuffer.jsp'); return false;">
+ Find features in buffer</a>
+ <br/>Create a buffer around a selected parcel, then mark parcels inside the buffer that are
+ of type "MFG".
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "selectfeaturesinbuffer.jsp") %>" >View source</a>
+ </li>
+
+ </ul>
+
+ <p>View source for support files:</p>
+ <ul>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane.jsp") %>">task_pane.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "bufferfunctions.jsp") %>">bufferfunctions.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "bufferlayerdefinition.xml") %>">bufferlayerdefinition.xml</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "parcelmarker.xml") %>">parcelmarker.xml</a></li>
+ </ul>
+ </body>
+</html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/common/common.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/common/common.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/common/common.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -1,57 +1,99 @@
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="java.text.*" %>
+<%@ page import="java.util.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="javax.servlet.jsp.*" %>
+<%@ page import="javax.servlet.http.*" %>
<%
-// Copyright (C) 2004-2006 Autodesk, Inc.
+// Define some commonly used directories and files.
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of version 2.1 of the GNU Lesser
-// General Public License as published by the Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+// The samples are installed into the web tier's document root, so every path is derived
+// from where this page is deployed rather than hard-coded:
+// <install>/webserverextensions/www/ <- the web tier's document root
+// <install>/webserverextensions/www/javasamples
+// <install>/webserverextensions/www/viewerfiles
+// <install>/webserverextensions/www/webconfig.ini
+// <install>/server/Schema/
-// Define some commonly used directories and files
+File mgWebRoot = new File(getServletContext().getRealPath("/"));
+File mgWebExtensions = mgWebRoot.getParentFile();
+File mgInstallRoot = mgWebExtensions.getParentFile();
-// -----------------------------------------------------------------------------------
-// Use the following for Windows installations
-// -----------------------------------------------------------------------------------
-String webExtensionsDirectory = "C:\\Program Files\\OSGeo\\MapGuide\\Web\\";
-
-String MapGuideServerDirectory = "C:\\Program Files\\OSGeo\\MapGuide\\Server\\";
-
-String viewerFilesDirectory = webExtensionsDirectory + "www\\viewerfiles\\";
-
-String schemaDirectory = MapGuideServerDirectory + "Schema\\";
-
-String webconfigDirectory = webExtensionsDirectory + "www\\";
+String webExtensionsDirectory = mgWebExtensions.getPath() + File.separator;
-String webconfigFilePath = webconfigDirectory + "webconfig.ini";
-// -----------------------------------------------------------------------------------
-// End of Windows configuration
-// -----------------------------------------------------------------------------------
+String MapGuideServerDirectory = new File(mgInstallRoot, "server").getPath() + File.separator;
-// -----------------------------------------------------------------------------------
-// Use the following for Linux installations
-// -----------------------------------------------------------------------------------
-/*************************************************************************************
-String webExtensionsDirectory = "/usr/local/mapguideopensource/web/";
-
-String MapGuideServerDirectory = "/usr/local/mapguideopensource/server/";
-
-String viewerFilesDirectory = webExtensionsDirectory + "www/viewerfiles/";
-
-String schemaDirectory = MapGuideServerDirectory + "Schema/";
-
-String webconfigDirectory = webExtensionsDirectory + "www/";
+String schemaDirectory = new File(MapGuideServerDirectory, "Schema").getPath() + File.separator;
-String webconfigFilePath = webconfigDirectory + "webconfig.ini";
-*************************************************************************************/
-// -----------------------------------------------------------------------------------
-// End of Linux configuration
-// -----------------------------------------------------------------------------------
+String viewerFilesDirectory = new File(mgWebRoot, "viewerfiles").getPath() + File.separator;
-%>
\ No newline at end of file
+String webconfigDirectory = mgWebRoot.getPath() + File.separator;
+
+String webconfigFilePath = new File(mgWebRoot, "webconfig.ini").getPath();
+%>
+<%!
+// Escapes a string so that it can be placed in HTML text or in an attribute value.
+public static String htmlEncode(String value)
+{
+ if (value == null)
+ return "";
+
+ StringBuilder encoded = new StringBuilder(value.length());
+ for (int i = 0; i < value.length(); i++)
+ {
+ char c = value.charAt(i);
+ switch (c)
+ {
+ case '&': encoded.append("&"); break;
+ case '<': encoded.append("<"); break;
+ case '>': encoded.append(">"); break;
+ case '"': encoded.append("""); break;
+ case '\'': encoded.append("'"); break;
+ default: encoded.append(c); break;
+ }
+ }
+ return encoded.toString();
+}
+
+// Names a file of the samples by its path relative to the samples root, so that a
+// "view source" link never carries a physical path.
+public static String samplePath(HttpServletRequest request, String fileName)
+{
+ File currentPath = new File(request.getServletContext().getRealPath(request.getServletPath()));
+ return currentPath.getParentFile().getName() + "/" + fileName;
+}
+
+// Copies the contents of a byte reader to the response.
+public static void outputReaderContent(HttpServletResponse response, MgByteReader byteReader) throws Exception
+{
+ ByteArrayOutputStream memBuf = new ByteArrayOutputStream();
+
+ byte[] byteBuffer = new byte[1024];
+ int numBytes = byteReader.read(byteBuffer, 1024);
+ while (numBytes > 0)
+ {
+ memBuf.write(byteBuffer, 0, numBytes);
+ numBytes = byteReader.read(byteBuffer, 1024);
+ }
+
+ byte[] content = memBuf.toByteArray();
+ response.setContentLength(content.length);
+ response.setContentType(byteReader.getMimeType());
+ response.getOutputStream().write(content);
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/common/mapinfo.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/common/mapinfo.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/common/mapinfo.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,137 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="common.jsp" %>
+<html>
+ <head>
+ <title>Map Info</title>
+ <style type="text/css">
+ body, html { margin: 0; padding: 0 }
+ body { font-family: Verdana; font-size: 0.6em; }
+
+ </style>
+ </head>
+ <body>
+ <%
+ //---------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+ %>
+ <p>Map Name: <%= map.getName() %></p>
+ <p>Object Id: <%= map.getObjectId() %></p>
+ <p>Map Definition: <%= map.getMapDefinition().toString() %></p>
+ <hr />
+ <p>Display DPI: <%= map.getDisplayDpi() %></p>
+ <p>Display Height: <%= map.getDisplayHeight() %></p>
+ <p>Display Width: <%= map.getDisplayWidth() %></p>
+ <hr />
+ <p>View Center: (<%= map.getViewCenter().getCoordinate().getX() %>, <%= map.getViewCenter().getCoordinate().getY() %>)</p>
+ <p>View Scale: <%= map.getViewScale() %></p>
+ <hr />
+ <%
+ MgEnvelope dataExtents = map.getDataExtent();
+ MgCoordinate ll = dataExtents.getLowerLeftCoordinate();
+ MgCoordinate ur = dataExtents.getUpperRightCoordinate();
+ %>
+ <h3>Data Extents</h3>
+ <p>Lower Left: (<%= ll.getX() %>, <%= ll.getY() %>)</p>
+ <p>Upper Left: (<%= ur.getX() %>, <%= ur.getY() %>)</p>
+ <hr />
+ <%
+ MgLayerCollection layers = map.getLayers();
+ %>
+ <h3>Layers (<%= layers.getCount() %>)</h3>
+ <table border="1">
+ <tr>
+ <th>Name</th>
+ <th>Group</th>
+ <th>Label</th>
+ <th>Legend Visible</th>
+ <th>Potential Visible</th>
+ <th>Actual Visible</th>
+ <th>Expand In Legend</th>
+ <th>Layer Type</th>
+ <th>Layer Definition</th>
+ <th>Feature Source Id</th>
+ <th>Object Id</th>
+ <th>Needs Refresh</th>
+ </tr>
+ <%
+ for (int i = 0; i < layers.getCount(); i++) {
+ MgLayerBase layer = layers.getItem(i);
+ MgLayerGroup group = layer.getGroup();
+ %>
+ <tr>
+ <td><%= layer.getName() %></td>
+ <td><%= group == null ? "" : group.getName() %></td>
+ <td><%= layer.getLegendLabel() %></td>
+ <td><%= layer.getDisplayInLegend() %></td>
+ <td><%= layer.getVisible() %></td>
+ <td><%= layer.isVisible() %></td>
+ <td><%= layer.getExpandInLegend() %></td>
+ <td><%= layer.getLayerType() %></td>
+ <td><a target="_blank" href="viewresourcecontent.jsp?SESSION=<%= sessionId %>&RESOURCEID=<%= layer.getLayerDefinition().toString() %>"><%= layer.getLayerDefinition().toString() %></a></td>
+ <td><a target="_blank" href="viewresourcecontent.jsp?SESSION=<%= sessionId %>&RESOURCEID=<%= layer.getFeatureSourceId() %>"><%= layer.getLayerDefinition().toString() %></a></td>
+ <td><%= layer.getObjectId() %></td>
+ <td><%= layer.needsRefresh() %></td>
+ </tr>
+ <% } %>
+ </table>
+ <hr />
+ <%
+ MgLayerGroupCollection layerGroups = map.getLayerGroups();
+ %>
+ <h3>Layer Groups (<%= layerGroups.getCount() %>)</h3>
+ <table border="1">
+ <tr>
+ <th>Name</th>
+ <th>Group</th>
+ <th>Label</th>
+ <th>Legend Visible</th>
+ <th>Potential Visible</th>
+ <th>Actual Visible</th>
+ <th>Expand In Legend</th>
+ <th>Group Type</th>
+ </tr>
+ <%
+ for (int i = 0; i < layerGroups.getCount(); i++) {
+ MgLayerGroup group = layerGroups.getItem(i);
+ MgLayerGroup parent = group.getGroup();
+ %>
+ <tr>
+ <td><%= group.getName() %></td>
+ <td><%= parent == null ? "" : parent.getName() %></td>
+ <td><%= group.getLegendLabel() %></td>
+ <td><%= group.getDisplayInLegend() %></td>
+ <td><%= group.getVisible() %></td>
+ <td><%= group.isVisible() %></td>
+ <td><%= group.getExpandInLegend() %></td>
+ <td><%= group.getLayerGroupType() %></td>
+ </tr>
+ <% } %>
+ </table>
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/common/viewresourcecontent.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/common/viewresourcecontent.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/common/viewresourcecontent.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,48 @@
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="common.jsp" %>
+<html>
+<head></head>
+<body>
+<pre>
+<%
+try
+{
+ //---------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ MgResourceIdentifier resourceId = new MgResourceIdentifier(request.getParameter("RESOURCEID"));
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgResourceService resSvc = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgByteReader content = resSvc.getResourceContent(resourceId);
+
+ out.print(htmlEncode(content.toString()));
+}
+catch (MgException e)
+{
+ out.print(htmlEncode(e.getExceptionMessage()));
+ out.print(htmlEncode(e.getDetails()));
+}
+%>
+</pre>
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,83 @@
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="java.nio.charset.StandardCharsets" %>
+<%@ page import="java.nio.file.Files" %>
+<%@ page import="java.util.Locale" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="common.jsp" %>
+<%!
+// The samples link here with a file path relative to the samples root, which is the directory
+// above this page's own: "hello_map/task_pane.jsp", never a physical path. Resolve the name
+// against that root and require the result to stay there, so neither an absolute path nor a
+// traversal sequence can name a file outside the samples.
+public static File resolveSourceFile(HttpServletRequest request, String fileName) throws IOException
+{
+ if (fileName == null || fileName.length() == 0)
+ throw new FileNotFoundException("No FILENAME was given");
+
+ fileName = fileName.replace('\\', '/');
+ if (fileName.startsWith("/") || new File(fileName).isAbsolute() || fileName.matches("^[A-Za-z][A-Za-z0-9+.-]*:.*"))
+ throw new FileNotFoundException("FILENAME must be relative to the samples directory");
+
+ File pageDir = new File(request.getServletContext().getRealPath(request.getServletPath())).getParentFile();
+ File samplesRoot = pageDir.getParentFile().getCanonicalFile();
+ File resolved = new File(samplesRoot, fileName).getCanonicalFile();
+
+ String samplesRootPrefix = samplesRoot.getPath() + File.separator;
+ if (!resolved.getPath().toLowerCase(Locale.ROOT).startsWith(samplesRootPrefix.toLowerCase(Locale.ROOT)) || !resolved.isFile())
+ throw new FileNotFoundException("File is outside the samples directory");
+
+ return resolved;
+}
+%>
+<%
+ String sourcePath = request.getParameter("FILENAME");
+ File sourceFile = null;
+ String fileContents = null;
+
+ try
+ {
+ sourceFile = resolveSourceFile(request, sourcePath);
+ String text = new String(Files.readAllBytes(sourceFile.toPath()), StandardCharsets.UTF_8);
+ if (text.length() > 0 && text.charAt(0) == '\uFEFF')
+ text = text.substring(1);
+ fileContents = htmlEncode(text);
+ }
+ catch (FileNotFoundException e)
+ {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
+ return;
+ }
+ catch (IOException e)
+ {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
+ return;
+ }
+%>
+<html>
+ <head>
+ <title>Source of <%= htmlEncode(sourceFile.getName()) %></title>
+ </head>
+
+ <body>
+ <p><strong><%= htmlEncode(sourcePath) %></strong></p>
+ <pre style="background-color: #f8f8f8; padding: 10px; border: 2px solid black">
+<code><%= fileContents %>
+</code>
+ </pre>
+ </body>
+</html>
Deleted: branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.php
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.php 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/common/viewsource.php 2026-11-18 15:26:37 UTC (rev 10291)
@@ -1,67 +0,0 @@
-<?php
-// Copyright (C) 2004-2006 Autodesk, Inc.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of version 2.1 of the GNU Lesser
-// General Public License as published by the Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- $sourceFile = isset($_GET['FILENAME']) ? $_GET['FILENAME'] : "";
- if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['FILENAME']))
- $sourceFile = $_POST['FILENAME'];
-
- if (DIRECTORY_SEPARATOR == '/')
- $sourceFile = str_replace('\\', '/', $sourceFile);
- else
- $sourceFile = str_replace('/', '\\', $sourceFile);
-
- $sourcePath = $sourceFile;
-
- // Reject an absolute path or a URL, then resolve the relative name against the samples root
- // and require the result to stay there, so a traversal sequence cannot name another file.
- $firstChar = substr($sourceFile, 0, 1);
- if ($firstChar == '/' || $firstChar == '\\' || preg_match('#^[A-Za-z][A-Za-z0-9+.-]*:#', $sourceFile))
- {
- header('HTTP/1.1 403 Forbidden');
- echo 'FILENAME must be relative to the samples directory';
- return;
- }
-
- $samplesRoot = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . "..");
- $sourceFile = realpath($samplesRoot . DIRECTORY_SEPARATOR . $sourceFile);
- if ($samplesRoot === false || $sourceFile === false || !is_file($sourceFile) ||
- strncmp($sourceFile, $samplesRoot . DIRECTORY_SEPARATOR, strlen($samplesRoot) + 1) != 0)
- {
- header('HTTP/1.1 403 Forbidden');
- echo 'File is outside the samples directory';
- return;
- }
-
- $testForUtf = pack("ccc", 0xEF, 0xBB, 0xBF);
- $fileContents = file_get_contents($sourceFile);
- if (substr($fileContents, 0, 3) == $testForUtf)
- $fileContents = htmlentities(utf8_decode(substr($fileContents, 3)));
- else
- $fileContents = htmlentities($fileContents);
-?>
-<html>
- <head>
- <title>Source of <?= htmlentities(basename($sourceFile)) ?></title>
- </head>
-
- <body>
- <p><strong><?= htmlentities($sourcePath) ?></strong></p>
- <pre style="background-color: #f8f8f8; padding: 10px; border: 2px solid black">
-<code><?= $fileContents ?>
-</code>
- </pre>
- </body>
-</html>
\ No newline at end of file
Added: branches/4.0/MgDev/Doc/samples/javasamples/custom_output/createmapimage.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/custom_output/createmapimage.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/custom_output/createmapimage.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,101 @@
+<%--
+//
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+--%>
+<%@ page trimDirectiveWhitespaces="true" %>
+<%@ page import="java.io.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%
+// This page writes an image, so it must emit no content of its own before the image bytes.
+
+String sessionId = request.getParameter("SESSION");
+String xmlSelection = request.getParameter("SELECTION");
+xmlSelection = (xmlSelection != null && xmlSelection.length() > 0) ? URLDecoder.decode(xmlSelection, "UTF-8") : "";
+String mapName = request.getParameter("MAPNAME");
+double mapScale = Double.parseDouble(request.getParameter("SCALE"));
+int imageHeight = Integer.parseInt(request.getParameter("HEIGHT"));
+int imageWidth = Integer.parseInt(request.getParameter("WIDTH"));
+double mapCenterX = Double.parseDouble(request.getParameter("CENTERX"));
+double mapCenterY = Double.parseDouble(request.getParameter("CENTERY"));
+
+try
+{
+ // Initialize the Web Extensions and connect to the Server.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ // Create the necessary services.
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgRenderingService renderingService = (MgRenderingService)siteConnection.createService(MgServiceType.RenderingService);
+
+ // Open the map and get its SRS
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+ String srsWkt = map.getMapSRS();
+ MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
+ MgCoordinateSystem srs = coordinateSystemFactory.create(srsWkt);
+
+ MgSelection selection = null;
+ if (xmlSelection.length() > 0)
+ {
+ selection = new MgSelection(map, xmlSelection);
+ }
+ else
+ {
+ selection = new MgSelection(map);
+ }
+
+ MgColor color = new MgColor((short)205, (short)189, (short)156);
+
+ // Convert the height in pixels to map units.
+ // Create an envelope that contains the image area to display.
+
+ double displayInInches = imageHeight / 96;
+ double displayInMeters = displayInInches * .0254;
+ double mapHeightInMeters = displayInMeters * mapScale;
+ double mapHeightInMapUnits = srs.convertMetersToCoordinateSystemUnits(mapHeightInMeters);
+ double envelopeOffsetY = mapHeightInMapUnits / 2;
+ double envelopeOffsetX = imageWidth / imageHeight * envelopeOffsetY;
+ MgEnvelope envelope = new MgEnvelope(mapCenterX - envelopeOffsetX,
+ mapCenterY - envelopeOffsetY, mapCenterX + envelopeOffsetX,
+ mapCenterY + envelopeOffsetY);
+
+ // Render the image and send it to the browser.
+
+ MgByteReader byteReader = renderingService.renderMap(map, selection, envelope, imageWidth, imageHeight, color, "PNG");
+ outputReaderContent(response, byteReader);
+}
+catch (MgException e)
+{
+ out.print("<p>" + e.getExceptionMessage() + "</p>");
+ out.print("<p>" + e.getDetails() + "</p>");
+}
+catch (Exception e)
+{
+ out.print("<p>" + e.toString() + "</p>");
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/custom_output/eplot.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/custom_output/eplot.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/custom_output/eplot.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,75 @@
+<%--
+//
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+--%>
+<%@ page trimDirectiveWhitespaces="true" %>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%
+// This page writes a DWF, so it must emit no content of its own before the plot bytes.
+
+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.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ // Create an instance of ResourceService and use that to open the
+ // current map instance stored in the session.
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ MgMappingService mappingService = (MgMappingService)siteConnection.createService(MgServiceType.MappingService);
+
+ MgDwfVersion dwfVersion = new MgDwfVersion("6.01", "1.2");
+
+ MgPlotSpecification plotSpec = new MgPlotSpecification(8.5f, 11.0f, MgPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);
+
+ MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
+ MgLayout layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
+
+ MgByteReader byteReader = mappingService.generatePlot(map, plotSpec, layout, dwfVersion);
+
+ // Now output the resulting DWF
+ outputReaderContent(response, byteReader);
+
+}
+catch (MgException e)
+{
+ String result = e.getExceptionMessage() + "<br><br>" + e.getDetails();
+
+ response.setContentType("text/html");
+ out.print(result);
+}
+catch (Exception e)
+{
+ response.setContentType("text/html");
+ out.print(e.toString());
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/custom_output/multiplot.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/custom_output/multiplot.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/custom_output/multiplot.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,90 @@
+<%--
+//
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+--%>
+<%@ page trimDirectiveWhitespaces="true" %>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%
+// This page writes a DWF, so it must emit no content of its own before the plot bytes.
+
+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.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ // Create an instance of ResourceService and use that to open the
+ // current map instance stored in the session.
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ MgMappingService mappingService = (MgMappingService)siteConnection.createService(MgServiceType.MappingService);
+
+ MgDwfVersion dwfVersion = new MgDwfVersion("6.01", "1.2");
+
+ MgPlotSpecification plotSpec = new MgPlotSpecification(8.5f, 11.0f, MgPageUnitsType.Inches, 0.5f, 0.5f, 0.5f, 0.5f);
+
+ MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
+ MgLayout layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
+
+ MgMapPlotCollection plotCollection = new MgMapPlotCollection();
+
+ MgMapPlot plot1 = new MgMapPlot(map, plotSpec, layout);
+ plot1.setCenterAndScale(map.getViewCenter().getCoordinate(), map.getViewScale() * 2);
+ plotCollection.add(plot1);
+
+ // Create a second map for the second sheet in the DWF. This second sheet uses the print layout
+ // to display a page title and legend.
+
+ MgMap map2 = new MgMap(siteConnection);
+ map2.create(map.getMapDefinition(), "Sheet 2");
+ MgMapPlot plot2 = new MgMapPlot(map2, plotSpec, layout);
+ plot2.setCenterAndScale(map.getViewCenter().getCoordinate(), map.getViewScale());
+ plotCollection.add(plot2);
+
+ MgByteReader byteReader = mappingService.generateMultiPlot(plotCollection, dwfVersion);
+
+ // Now output the resulting DWF.
+ outputReaderContent(response, byteReader);
+
+}
+catch (MgException e)
+{
+ String result = e.getExceptionMessage() + "<br><br>" + e.getDetails();
+
+ response.setContentType("text/html");
+ out.print(result);
+}
+catch (Exception e)
+{
+ response.setContentType("text/html");
+ out.print(e.toString());
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/custom_output/property_report.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/custom_output/property_report.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/custom_output/property_report.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,139 @@
+<%--
+//
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<%
+
+String sessionId = request.getParameter("SESSION");
+String xmlSelection = request.getParameter("SELECTION");
+xmlSelection = (xmlSelection != null && xmlSelection.length() > 0) ? URLDecoder.decode(xmlSelection, "UTF-8") : "";
+String mapName = request.getParameter("MAPNAME");
+double mapScale = Double.parseDouble(request.getParameter("SCALE"));
+int imageHeight = Integer.parseInt(request.getParameter("HEIGHT"));
+int imageWidth = Integer.parseInt(request.getParameter("WIDTH"));
+double mapCenterX = Double.parseDouble(request.getParameter("CENTERX"));
+double mapCenterY = Double.parseDouble(request.getParameter("CENTERY"));
+
+String owner = "";
+String address = "";
+String billingAddress = "";
+String description = "";
+
+try
+{
+ // Initialize the Web Extensions and connect to the Server.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ // If any parcels have been selected, recenter the image on the first selected parcel.
+ if (xmlSelection.length() > 0)
+ {
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ MgSelection selection = new MgSelection(map, xmlSelection);
+ MgReadOnlyLayerCollection layers = selection.getLayers();
+
+ if (layers != null)
+ {
+ for (int i = 0; i < layers.getCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+ MgLayer layer = (MgLayer)layers.getItem(i);
+ if (layer != null && layer.getName().equals("Parcels"))
+ {
+ // Get the feature reader for the selected features on this layer
+
+ String layerClassName = layer.getFeatureClassName();
+ MgFeatureReader featureReader = selection.getSelectedFeatures(layer, layerClassName, false);
+
+ // Create the report details using the first selected parcel. Position the image so the
+ // centroid of the selected parcel is in the center of the map.
+
+ featureReader.readNext();
+ MgByteReader featureAgfGeometry = featureReader.getGeometry("SHPGEOM");
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgGeometry featureGeometry = agfReaderWriter.read(featureAgfGeometry);
+ MgPoint centroid = featureGeometry.getCentroid();
+ mapCenterX = centroid.getCoordinate().getX();
+ mapCenterY = centroid.getCoordinate().getY();
+
+ owner = featureReader.getString("RNAME");
+ address = featureReader.getString("RPROPAD");
+ billingAddress = featureReader.getString("RBILAD");
+ description = featureReader.getString("RLDESCR1") + "<br/>" + featureReader.getString("RLDESCR2") + "<br/>" + featureReader.getString("RLDESCR3") + "<br/>";
+
+ }
+ }
+ }
+ }
+
+}
+catch (MgException e)
+{
+ out.print("<p>" + e.getExceptionMessage() + "</p>");
+ out.print("<p>" + e.getDetails() + "</p>");
+}
+catch (Exception e)
+{
+ out.print("<p>" + e.toString() + "</p>");
+}
+
+String selectionEncoded = URLEncoder.encode(xmlSelection, "UTF-8");
+String imageUrl = "createmapimage.jsp?SESSION=" + sessionId + "&SELECTION=" + selectionEncoded + "&MAPNAME=" + mapName + "&SCALE=" + mapScale + "&HEIGHT=" + imageHeight + "&WIDTH=" + imageWidth + "&CENTERX=" + mapCenterX + "&CENTERY=" + mapCenterY;
+
+%>
+<html>
+ <head>
+ <title>Property Report</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">
+ <style>
+ img {float: left; margin-right: 10px; border: 1px solid #999; padding: 4px}
+ </style>
+ </head>
+ <body>
+ <h1>Property Report</h1>
+ <p><img id="propertyImage" src="<%= imageUrl %>" width="<%=imageWidth%>" height="<%= imageHeight %>" />
+ <%
+ if (xmlSelection.length() == 0)
+ {
+ out.print("No properties selected.");
+ }
+ else
+ {
+ out.print("Owner: " + owner + "<br/>\n");
+ out.print("Address: " + address + "<br/>\n");
+ out.print("Billing Address: " + billingAddress + "<br/>\n");
+ out.print("Description: " + description + "<br/>\n");
+ }
+ %>
+ </p>
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/custom_output/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/custom_output/task_pane.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/custom_output/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <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">
+ <script language=javascript>
+ function submitRequest(pageUrl)
+ {
+ xmlSel = parent.parent.mapFrame.GetSelectionXML();
+ mapScale = parent.parent.mapFrame.GetScale();
+ mapHeight = 300;
+ mapWidth = 300;
+ mapCenter = parent.parent.mapFrame.GetCenter();
+ params = new Array("SESSION", parent.parent.mapFrame.GetSessionId(),
+ "MAPNAME", parent.parent.mapFrame.GetMapName(),
+ "SELECTION", encodeURIComponent(xmlSel),
+ "SCALE", mapScale,
+ "HEIGHT", mapHeight,
+ "WIDTH", mapWidth,
+ "CENTERX", mapCenter.X,
+ "CENTERY", mapCenter.Y
+ );
+ parent.parent.formFrame.Submit(pageUrl, params, "_blank");
+ }
+
+ function OnPageLoad()
+ {
+ parent.parent.mapFrame.Refresh();
+ parent.parent.mapFrame.ZoomToScale(9999);
+ }
+ </script>
+ </head>
+ <body onLoad="OnPageLoad()" class="AppFrame">
+ <h1 class="AppHeading">Custom Output</h1>
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <ul>
+ <li>
+ (Select one parcel and then click the link below.)<BR>
+ <a href="#" onClick="submitRequest('/mapguide/javasamples/custom_output/property_report.jsp'); return false;">
+ Property report</a>
+ <br/>Create a printable page with an inset image of the selected property.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "property_report.jsp") %>" >View source</a>
+ </li>
+
+ <li>
+ <a target="_blank" href="eplot.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" >
+ ePlot</a>
+ <br/>Create and display an ePlot. Requires Autodesk DWF Viewer or Autodesk Design Review on the client system.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "eplot.jsp") %>" >View source</a>
+ </li>
+
+ <li>
+ <a target="_blank" href="multiplot.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" >
+ Multi-plot</a>
+ <br/>Create and display a multi-plot ePlot. Requires Autodesk DWF Viewer or Autodesk Design Review on the client system.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "multiplot.jsp") %>" >View source</a>
+ </li>
+
+ </ul>
+
+ <p>View source for support files:</p>
+ <ul>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "createmapimage.jsp") %>" >createmapimage.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane.jsp") %>" >task_pane.jsp</a></li>
+ </ul>
+
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/clear_lines.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/clear_lines.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/clear_lines.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <title>Clear Lines</title>
+
+ <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">
+ <meta http-equiv="content-script-type" content="text/javascript">
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ }
+ </script>
+ </head>
+
+ <body onLoad="OnPageLoad()">
+ <%
+ try
+ {
+ // --------------------------------------------------//
+ // Basic initialization
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ // Get the information passed from the viewer
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+
+ // 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);
+
+ // --------------------------------------------------//
+ String featureSourceName = "Session:" + sessionId + "//TemporaryLines.FeatureSource";
+ MgResourceIdentifier resourceID = new MgResourceIdentifier(featureSourceName);
+
+ resourceService.deleteResource(resourceID);
+ }
+ catch (MgException e)
+ {
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.getExceptionMessage() + " \"); \n");
+ out.print("</script> \n");
+ }
+ %>
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/draw_line.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/draw_line.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/draw_line.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,250 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="../modifying_maps_and_layers/layer_functions.jsp" %>
+<%!
+///////////////////////////////////////////////////////////////////////////////////
+MgPropertyCollection makeLine(String name, String x0, String y0, String x1, String y1)
+{
+ MgPropertyCollection propertyCollection = new MgPropertyCollection();
+ MgStringProperty nameProperty = new MgStringProperty("NAME", name);
+ propertyCollection.add(nameProperty);
+
+ MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+
+ MgGeometry geometry = wktReaderWriter.read("LINESTRING XY (" + x0 + " " + y0 + ", " + x1 + " " + y1 + ")");
+ MgByteReader geometryByteReader = agfReaderWriter.write(geometry);
+ MgGeometryProperty geometryProperty = new MgGeometryProperty("SHPGEOM", geometryByteReader);
+ propertyCollection.add(geometryProperty);
+
+ return propertyCollection;
+}
+
+///////////////////////////////////////////////////////////////////////////////////
+boolean doesResourceExist(MgResourceIdentifier resourceIdentifier, MgResourceService resourceService)
+// Returns true if the resource already exists, or false otherwise
+{
+ return resourceService.resourceExists(resourceIdentifier);
+}
+
+///////////////////////////////////////////////////////////////////////////////////
+boolean doesLayerExist(String layerName, MgMap map)
+// Returns true if the layer already exists, or false otherwise
+{
+ MgLayerCollection layerCollection = map.getLayers();
+ return layerCollection.contains(layerName);
+}
+%>
+<html>
+<head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <title>Draw a Line</title>
+
+ <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">
+ <meta http-equiv="content-script-type" content="text/javascript">
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ }
+ </script>
+</head>
+
+<body onLoad="OnPageLoad()">
+ <%
+
+ // Get the parameters passed in from the task pane
+ String x0 = request.getParameter("x0");
+ String y0 = request.getParameter("y0");
+ String x1 = request.getParameter("x1");
+ String y1 = request.getParameter("y1");
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+
+ try
+ {
+ // --------------------------------------------------//
+ // Basic initialization needs to be done every time.
+ 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);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.createService(MgServiceType.FeatureService);
+
+ //---------------------------------------------------//
+ // Open the map
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ String layerName = "Lines";
+ String layerLegendLabel = "New Lines";
+ String groupName = "Analysis";
+ String groupLegendLabel = "Analysis";
+
+ //---------------------------------------------------//
+ // Does the temporary feature source already exist?
+ // If not, create it
+ String featureSourceName = "Session:" + sessionId + "//TemporaryLines.FeatureSource";
+ MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);
+
+ boolean featureSourceExists = doesResourceExist(resourceIdentifier, resourceService);
+ if (! featureSourceExists)
+ {
+ // Create a temporary feature source to draw the lines on
+
+ // Create a feature class definition for the new feature
+ // source
+ MgClassDefinition classDefinition = new MgClassDefinition();
+ classDefinition.setName("Lines");
+ classDefinition.setDescription("Lines to display.");
+ String geometryPropertyName = "SHPGEOM";
+ classDefinition.setDefaultGeometryPropertyName(geometryPropertyName);
+
+ // Create an identify property
+ MgDataPropertyDefinition identityProperty = new MgDataPropertyDefinition("KEY");
+ identityProperty.setDataType(MgPropertyType.Int32);
+ identityProperty.setAutoGeneration(true);
+ identityProperty.setReadOnly(true);
+ // Add the identity property to the class definition
+ classDefinition.getIdentityProperties().add(identityProperty);
+ classDefinition.getProperties().add(identityProperty);
+
+ // Create a name property
+ MgDataPropertyDefinition nameProperty = new MgDataPropertyDefinition("NAME");
+ nameProperty.setDataType(MgPropertyType.String);
+ // Add the name property to the class definition
+ classDefinition.getProperties().add(nameProperty);
+
+ // Create a geometry property
+ MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition(geometryPropertyName);
+ geometryProperty.setGeometryTypes(MgFeatureGeometricType.Surface);
+ // Add the geometry property to the class definition
+ classDefinition.getProperties().add(geometryProperty);
+
+ // Create a feature schema
+ MgFeatureSchema featureSchema = new MgFeatureSchema("SHP_Schema", "Line schema");
+ // Add the feature schema to the class definition
+ featureSchema.getClasses().add(classDefinition);
+
+ // Create the feature source
+ String wkt = map.getMapSRS();
+ MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "spatial context", wkt, featureSchema);
+ featureService.createFeatureSource(resourceIdentifier, sdfParams);
+ }
+
+ // Add the line to the feature source
+ MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
+ MgPropertyCollection propertyCollection = makeLine("Line A", x0, y0, x1, y1);
+ batchPropertyCollection.addItem(propertyCollection);
+
+ // Add the batch property collection to the feature source
+ MgInsertFeatures cmd = new MgInsertFeatures(layerName, batchPropertyCollection);
+ MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
+ featureCommandCollection.add(cmd);
+
+ // Execute the "add" commands
+ featureService.updateFeatures(resourceIdentifier, featureCommandCollection, false);
+
+ //---------------------------------------------------//
+ boolean layerExists = doesLayerExist(layerName, map);
+ if (! layerExists )
+ {
+ // Create a new layer which uses that feature source
+
+ // Create a line rule to stylize the lines
+ String ruleLegendLabel = "Lines Rule";
+ String filter = "";
+ String color = "FF0000FF";
+ LayerDefinitionFactory factory = new LayerDefinitionFactory(request);
+ String lineRule = factory.createLineRule(ruleLegendLabel, filter, color);
+
+ // Create a line type style
+ String lineTypeStyle = factory.createLineTypeStyle(lineRule);
+
+ // Create a scale range
+ String minScale = "0";
+ String maxScale = "1000000000000";
+ String lineScaleRange = factory.createScaleRange(minScale, maxScale, lineTypeStyle);
+
+ // Create the layer definiton
+ String featureName = "SHP_Schema:Lines";
+ String geometry = "SHPGEOM";
+ String layerDefinition = factory.createLayerDefinition(featureSourceName, featureName, geometry, lineScaleRange);
+
+ //---------------------------------------------------//
+ // Add the layer to the map
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new org.xml.sax.InputSource(new StringReader(layerDefinition)));
+ MgLayer newLayer = LayerFunctions.addLayerDefinitionToMap(doc, layerName, layerLegendLabel, sessionId, resourceService, map);
+ // Add the layer to a layer group
+ LayerFunctions.addLayerToGroup(newLayer, groupName, groupLegendLabel, map);
+ }
+
+ // --------------------------------------------------//
+ // Turn on the visibility of this layer.
+ // (If the layer does not already exist in the map, it will be visible by default when it is added.
+ // But if the user has already run this script, he or she may have set the layer to be invisible.)
+ MgLayerCollection layerCollection = map.getLayers();
+ if (layerCollection.contains(layerName))
+ {
+ MgLayer linesLayer = (MgLayer)layerCollection.getItem(layerName);
+ linesLayer.setVisible(true);
+ }
+
+ MgLayerGroupCollection groupCollection = map.getLayerGroups();
+ if (groupCollection.contains(groupName))
+ {
+ MgLayerGroup analysisGroup = groupCollection.getItem(groupName);
+ analysisGroup.setVisible(true);
+ }
+
+ //---------------------------------------------------//
+ // Save the map back to the session repository
+ map.save();
+
+ //---------------------------------------------------//
+
+ }
+ catch (MgException e)
+ {
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.getExceptionMessage() + " \"); \n");
+ out.print("</script> \n");
+ }
+ catch (Exception e)
+ {
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.toString() + " \"); \n");
+ out.print("</script> \n");
+ }
+ %>
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <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">
+ <script src="../common/pageLoadFunctions.js" type="text/javascript" language="JavaScript">
+ </script>
+ </head>
+ <body class="AppFrame">
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <h1 class="AppHeading">Digitizing & Redlining</h1>
+ <ul>
+ <li>
+ <a href="task_pane_digitizing.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Digitizing Sample</a>
+ <br/>Show digitizing functions.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane_digitizing.jsp") %>" >View source</a>
+ </li>
+ <li>
+ <a href="task_pane_redlining.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Redlining Sample</a>
+ <br/>Draw lines on the map.
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane_redlining.jsp") %>" >View source</a>
+ </li>
+ </ul>
+ <p>View source for support files:</p>
+ <ul>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "draw_line.jsp") %>">draw_line.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "clear_lines.jsp") %>">clear_lines.jsp</a></li>
+ </ul>
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_digitizing.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_digitizing.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_digitizing.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,119 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>Digitizing</title>
+
+ <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">
+ <meta http-equiv="content-script-type" content="text/javascript">
+ <script language="javascript" type="text/javascript">
+ function DigitizePoint() {
+ // ShowResults("");
+ parent.parent.mapFrame.DigitizePoint(OnPointDigitized);
+ }
+ function OnPointDigitized(point) {
+ ShowResults("X: " + point.X + ", Y: " + point.Y);
+ }
+ function DigitizeLine() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizeLine(OnLineDigitized);
+ }
+ function OnLineDigitized(line) {
+ ShowResults(FormatLineResults(line));
+ }
+ function DigitizeMultiLine() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizeMultiLine(OnMultiLineDigitized);
+ }
+ function DigitizeLineString() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizeLineString(OnDigitizeLineString);
+ }
+ function OnDigitizeLineString(line) {
+ ShowResults(FormatLineResults(line));
+ }
+
+ function DigitizeCircle() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizeCircle(OnCircleDigitized);
+ }
+ function OnCircleDigitized(circle) {
+ ShowResults("Center X: " + circle.Center.X + ", Y: " + circle.Center.Y + "\nRadius: " + circle.Radius);
+ }
+ function DigitizeRectangle() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizeRectangle(OnRectangleDigitized);
+ }
+ function OnRectangleDigitized(rect) {
+ str = "X1: " + rect.Point1.X + ", Y1: " + rect.Point1.Y + "\n";
+ str += "X2: " + rect.Point2.X + ", Y1: " + rect.Point2.Y + "\n";
+
+ ShowResults(str);
+ }
+ function DigitizePolygon() {
+ ShowResults("");
+ parent.parent.mapFrame.DigitizePolygon(OnPolygonDigitized);
+ }
+ function OnPolygonDigitized(poly) {
+ ShowResults(FormatLineResults(poly));
+ }
+ function FormatLineResults(line) {
+ str = "Points: " + line.Count + "\n";
+ for(var i = 0; i < line.Count; i++) {
+ pt = line.Point(i);
+ str += "X" + i + ": " + pt.X + ", Y" + i + ": " + pt.Y + "\n";
+ }
+ return str;
+ }
+ function ShowResults(res) {
+ document.getElementById("res").value = res;
+ }
+ </script>
+ </head>
+ <body class="AppFrame">
+ <h1 class="AppHeading">Digitizing</h1>
+ <p>
+ Click button then click on map:
+ </p>
+ <input type="button" value=" Point " onclick="DigitizePoint();">
+ <br>
+ <input type="button" value=" LineString " onclick="DigitizeLineString();">
+ <br>
+ <input type="button" value=" Polygon " onclick="DigitizePolygon();">
+ <hr>
+
+ <p>Click button then drag on map:
+ </p>
+ <input type="button" value=" Line " onclick="DigitizeLine();">
+ <br>
+ <input type="button" value=" Rectangle " onclick="DigitizeRectangle();">
+ <br>
+ <input type="button" value=" Circle " onclick="DigitizeCircle();">
+
+ <hr>
+ Result:<br>
+ <textarea id="res" rows="10" cols="32" name="results">
+ </textarea>
+
+ <hr>
+
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_redlining.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_redlining.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/digitizing_features/task_pane_redlining.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+// Copyright (C) 2004-2011 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-->
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <title>Redlining</title>
+
+ <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">
+ <meta http-equiv="content-script-type" content="text/javascript">
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <script language="javascript" type="text/javascript">
+ function DigitizeLine() {
+ parent.parent.mapFrame.DigitizeLine(OnLineDigitized);
+ }
+ function OnLineDigitized(line) {
+ // Send the Javascript variables to 'draw_line.jsp',
+ // via the form frame
+ var params = new Array("x0", line.Point(0).X,
+ "y0", line.Point(0).Y,
+ "x1", line.Point(1).X,
+ "y1", line.Point(1).Y,
+ "SESSION", "<%= sessionId %>",
+ "MAPNAME", "<%= mapName %>");
+ parent.parent.formFrame.Submit("/mapguide/javasamples/digitizing_features/draw_line.jsp", params, "scriptFrame");
+ }
+ </script>
+ </head>
+ <body class="AppFrame">
+
+ <h1 class="AppHeading">Redlining</h1>
+
+ <!-- "Draw a Line" button -->
+ <p>Click the button, and then drag a line on the map.</p>
+ <input type="button" value="Draw a Line" onclick="DigitizeLine();" />
+ <p>To draw another line, click the button again and drag another line.</p>
+
+ <!-- "Clear Lines" button -->
+ <hr>
+ <form target="scriptFrame" action="clear_lines.jsp" method="post">
+ <input type="submit" value="Clear Lines" />
+ <input type="hidden" name="SESSION" value="<%= sessionId %>" />
+ <input type="hidden" name="MAPNAME" value="<%= mapName %>" />
+ </form>
+
+ </body>
+</html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/hello_map/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/hello_map/task_pane.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/hello_map/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -15,8 +15,9 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-->
-<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
@@ -40,26 +41,14 @@
<a href="display_spatial_reference.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Display Spatial Reference</a>
<br/>Connect to MapGuide session and display basic information.
<br/>
- <%
- String fileName = "display_spatial_reference.jsp";
- ServletContext context = session.getServletContext();
- File currentPath = new File(context.getRealPath(request.getServletPath()));
- String dir = currentPath.getParentFile().getName();
- String fullPath = java.net.URLEncoder.encode(dir + "/" + fileName);
- %>
- <!-- Not implemented yet
- <a target="_blank" href="../common/viewsource.php?FILENAME=<%= fullPath %>" >View source</a>
- -->
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "display_spatial_reference.jsp") %>" >View source</a>
</li>
</ul>
-
- <!-- Not implemented yet
<p>View source for support files:</p>
<ul>
- <li><a target="_blank" href="../common/viewsource.php?FILENAME=main.jsp">main.jsp</a> (wrapper for Viewer frames)</li>
- <li><a target="_blank" href="../common/viewsource.php?FILENAME=<%= dir %>/task_pane.jsp">task_pane.jsp</a> (this task pane page)</li>
- <li><a target="_blank" href="../common/viewsource.php?FILENAME=common/common.jsp">common.jsp</a> (directory paths)</li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=main.jsp">main.jsp</a> (wrapper for Viewer frames)</li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane.jsp") %>">task_pane.jsp</a> (this task pane page)</li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=common/common.jsp">common.jsp</a> (directory paths)</li>
</ul>
- -->
</body>
</html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/gotopoint.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/gotopoint.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/gotopoint.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -1,5 +1,4 @@
-<?php
-
+<%--
//
// Copyright (C) 2004-2006 Autodesk, Inc.
//
@@ -17,7 +16,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-?>
+--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/task_pane.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/hello_viewer/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -15,8 +15,9 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-->
-<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
@@ -44,44 +45,30 @@
<p><strong>2.</strong> Click <a href="gotopoint.jsp?X=-87.724520&Y=43.768387&Scale=5000" target="scriptFrame">this link</a>
to display a different location. This loads a page into the hidden script frame.</p>
- <%
- ServletContext context = session.getServletContext();
- File currentPath = new File(context.getRealPath(request.getServletPath()));
- String dir = currentPath.getParentFile().getName();
- String fullPath = java.net.URLEncoder.encode(dir);
- %>
- <!-- Not implemented yet
<p>View source for support file:</p>
<ul>
- <li><a target="_blank" href="../common/viewsource.php?FILENAME=<%= fullPath %>/gotopoint.jsp">gotopoint.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "gotopoint.jsp") %>">gotopoint.jsp</a></li>
</ul>
- -->
<p><strong>3.</strong> Click <a href="#" onclick="parent.parent.ZoomToView(-87.707416, 43.747860, 5000, true);">this link</a>
to display a third location. This uses <code>onclick</code> to call JavaScript directly from the task pane.</p>
-
- <!-- Not implemented yet
<p>View source for this file:</p>
<ul>
- <li><a target="_blank" href="../common/viewsource.php?FILENAME=<%= fullPath %>/task_pane.jsp">task_pane.jsp</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane.jsp") %>">task_pane.jsp</a></li>
</ul>
- -->
<p><strong>4.</strong> The home task pane loads JavaScript from an external file. The script runs when the map first loads. It disables
the task pane and waits until the map has completed loading before enabling the pane. It does this by hooking into
the <code>OnMapLoaded()</code> function of the main frame.</p>
-
- <!-- Not implemented yet
<p>View files:</p>
<ul>
<li>
- <a target="_blank" href="../common/viewsource.php?FILENAME=index.jsp" >index.jsp</a>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=index.jsp" >index.jsp</a>
</li>
<li>
- <a target="_blank" href="../common/viewsource.php?FILENAME=common/pageLoadFunctions.js" >pageLoadFunctions.js</a>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=common/pageLoadFunctions.js" >pageLoadFunctions.js</a>
</li>
</ul>
- -->
</body>
</html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/index.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/index.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/index.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -48,14 +48,11 @@
<li><a href="hello_map/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Hello Map</a></li>
<li><a href="hello_viewer/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Hello Viewer</a></li>
<li><a href="interacting_with_layers/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Interacting With Layers</a></li>
-
- <!-- Not implemented yet
<li><a href="working_with_feature_data/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Working With Feature Data</a></li>
<li><a href="modifying_maps_and_layers/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Modifying Maps and Layers</a></li>
<li><a href="analyzing_features/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Analyzing Features</a></li>
<li><a href="digitizing_features/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Digitizing and Redlining</a></li>
<li><a href="custom_output/task_pane.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Custom Output</a></li>
- -->
</ul>
<h1>
Viewer Samples
Modified: branches/4.0/MgDev/Doc/samples/javasamples/interacting_with_layers/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/interacting_with_layers/task_pane.jsp 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/interacting_with_layers/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -15,8 +15,9 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-->
-<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
@@ -37,24 +38,13 @@
<a href="layer_visibility.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Layer Visibility</a>
<br/>List layers and visibility status
<br/>
- <%
- ServletContext context = session.getServletContext();
- File currentPath = new File(context.getRealPath(request.getServletPath()));
- String dir = currentPath.getParentFile().getName();
- String fullPath = java.net.URLEncoder.encode(dir);
- %>
-
- <!-- Not implemented yet
- <a target="_blank" href="../common/viewsource.php?FILENAME=<%= fullPath %>/layer_visibility.jsp" >view source</a>
- -->
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "layer_visibility.jsp") %>" >View source</a>
</li>
<li>
<a href="toggle_roads_label.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Rename Roads Layer</a>
<br/>Toggle the name of the Roads layer
<br/>
- <!-- Not implemented yet
- <a target="_blank" href="../common/viewsource.php?FILENAME=<%= fullPath %>/toggle_roads_label.jsp" >View source</a>
- -->
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "toggle_roads_label.jsp") %>" >View source</a>
</li>
</ul>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/RecentlyBuilt.LayerDefinition
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/RecentlyBuilt.LayerDefinition (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/RecentlyBuilt.LayerDefinition 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LayerDefinition xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LayerDefinition-1.3.0.xsd">
+ <VectorLayerDefinition>
+ <ResourceId>Library://Samples/Sheboygan/Data/Parcels.FeatureSource</ResourceId>
+ <FeatureName>SHP_Schema:Parcels</FeatureName>
+ <FeatureNameType>FeatureClass</FeatureNameType>
+ <PropertyMapping>
+ <Name>NAME</Name>
+ <Value>NAME</Value>
+ </PropertyMapping>
+ <PropertyMapping>
+ <Name>ID</Name>
+ <Value>ID</Value>
+ </PropertyMapping>
+ <PropertyMapping>
+ <Name>YRBUILT</Name>
+ <Value>YRBUILT</Value>
+ </PropertyMapping>
+ <Geometry>SHPGEOM</Geometry>
+ <VectorScaleRange>
+ <MaxScale>10000</MaxScale>
+ <AreaTypeStyle>
+ <AreaRule>
+ <LegendLabel>Built after 1950</LegendLabel>
+ <Filter>YRBUILT > 1950</Filter>
+ <Label>
+ <Unit>Points</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ <SizeX>0.3</SizeX>
+ <SizeY>10</SizeY>
+ <Text>YRBUILT</Text>
+ <FontName>Arial</FontName>
+ <ForegroundColor>FF000000</ForegroundColor>
+ <BackgroundColor>FFFFFFFF</BackgroundColor>
+ <BackgroundStyle>Transparent</BackgroundStyle>
+ <HorizontalAlignment>'Center'</HorizontalAlignment>
+ <VerticalAlignment>'Baseline'</VerticalAlignment>
+ </Label>
+ <AreaSymbolization2D>
+ <Fill>
+ <FillPattern>Solid</FillPattern>
+ <ForegroundColor>FFFFFF00</ForegroundColor>
+ <BackgroundColor>FF000000</BackgroundColor>
+ </Fill>
+ <Stroke>
+ <LineStyle>Solid</LineStyle>
+ <Thickness>0</Thickness>
+ <Color>FF000000</Color>
+ <Unit>Inches</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ </Stroke>
+ </AreaSymbolization2D>
+ </AreaRule>
+ </AreaTypeStyle>
+ </VectorScaleRange>
+ </VectorLayerDefinition>
+</LayerDefinition>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/change_layers_via_dom.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/change_layers_via_dom.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/change_layers_via_dom.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,156 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="layer_functions.jsp" %>
+<html>
+
+<head>
+ <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">
+
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ parent.mapFrame.ZoomToScale(9999);
+ }
+ </script>
+</head>
+
+<body onLoad="OnPageLoad()">
+
+<%
+try
+{
+ // --------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+
+ // --------------------------------------------------//
+ // Open the map
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // ...
+ // --------------------------------------------------//
+ // Load a layer from XML, and use the DOM to change it
+
+ // Load the prototype layer definition into a DOM document.
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ File pageDir = new File(getServletContext().getRealPath(request.getServletPath())).getParentFile();
+ File layerDefPath = new File(pageDir, "RecentlyBuilt.LayerDefinition");
+ if (!layerDefPath.exists())
+ {
+ out.print("The layer definition 'RecentlyBuilt.LayerDefinition' could not be found.<BR>\n");
+ return;
+ }
+ Document domDocument = builder.parse(layerDefPath);
+
+ // Get a list of all the <AreaRule><Filter> elements in
+ // the XML.
+ NodeList nodes = domDocument.getElementsByTagName("Filter");
+ // Find the correct node and change it
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node node = nodes.item(i);
+ if (node.getTextContent().equals("YRBUILT > 1950"))
+ {
+ node.setTextContent("YRBUILT > 1980");
+ }
+ }
+
+ // Get a list of all the <LegendLabel> elements in the
+ // XML.
+ nodes = domDocument.getElementsByTagName("LegendLabel");
+ // Find the correct node and change it
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node node = nodes.item(i);
+ if (node.getTextContent().equals("Built after 1950"))
+ {
+ node.setTextContent("Built after 1980");
+ }
+ }
+
+ // --------------------------------------------------//
+ // ...
+
+ // Add the layer to the map
+ MgLayer newLayer = LayerFunctions.addLayerDefinitionToMap(domDocument, "RecentlyBuilt", "Built after 1980", sessionId, resourceService, map);
+ LayerFunctions.addLayerToGroup(newLayer, "Analysis", "Analysis", map);
+
+ // --------------------------------------------------//
+ // Turn off the "Square Footage" themed layer (if it
+ // exists) so it does not hide this layer.
+ MgLayerCollection layerCollection = map.getLayers();
+ if (layerCollection.contains("SquareFootage"))
+ {
+ MgLayerBase squareFootageLayer = layerCollection.getItem("SquareFootage");
+ squareFootageLayer.setVisible(false);
+ }
+
+ // --------------------------------------------------//
+ // Turn on the visibility of this layer.
+ // (If the layer does not already exist in the map, it will be visible by default when it is added.
+ // But if the user has already run this script, he or she may have set the layer to be invisible.)
+ layerCollection = map.getLayers();
+ if (layerCollection.contains("RecentlyBuilt"))
+ {
+ MgLayerBase recentlyBuiltLayer = layerCollection.getItem("RecentlyBuilt");
+ recentlyBuiltLayer.setVisible(true);
+ }
+
+ // --------------------------------------------------//
+ // Save the map back to the session repository
+ map.save();
+
+ // --------------------------------------------------//
+
+
+}
+catch (MgException e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ String message = e.getExceptionMessage().replace("\n", " ");
+ out.print(" alert(\" " + message + " \"); \n");
+ out.print("</script> \n");
+}
+catch (Exception e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.toString() + " \"); \n");
+ out.print("</script> \n");
+}
+%>
+
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_line_layer_definition.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_line_layer_definition.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_line_layer_definition.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,129 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="layer_functions.jsp" %>
+<html>
+
+<head>
+ <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">
+
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ parent.mapFrame.ZoomToScale(40000);
+ }
+ </script>
+</head>
+
+<body onLoad="OnPageLoad()">
+
+<%
+try
+{
+ //---------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+
+ // --------------------------------------------------//
+ // Open the map
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // ...
+ //---------------------------------------------------//
+ // Create a new layer
+
+ LayerDefinitionFactory factory = new LayerDefinitionFactory(request);
+
+ // Create a line rule.
+ String legendLabel = "";
+ String filter = "";
+ String color = "FF0000FF";
+ String lineRule = factory.createLineRule(legendLabel, filter, color);
+
+ // Create a line type style.
+ String lineTypeStyle = factory.createLineTypeStyle(lineRule);
+
+ // Create a scale range.
+ String minScale = "0";
+ String maxScale = "1000000000000";
+ String lineScaleRange = factory.createScaleRange(minScale, maxScale, lineTypeStyle);
+
+ // Create the layer definiton.
+ String featureClass = "Library://Samples/Sheboygan/Data/HydrographicLines.FeatureSource";
+ String featureName = "SHP_Schema:HydrographicLines";
+ String geometry = "SHPGEOM";
+ String layerDefinition = factory.createLayerDefinition(featureClass, featureName, geometry, lineScaleRange);
+
+ //---------------------------------------------------//
+ // ...
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new org.xml.sax.InputSource(new StringReader(layerDefinition)));
+ // Add the layer to the map
+ MgLayer newLayer = LayerFunctions.addLayerDefinitionToMap(doc, "Hydro", "Hydro", sessionId, resourceService, map);
+ LayerFunctions.addLayerToGroup(newLayer, "Analysis", "Analysis", map);
+
+ // --------------------------------------------------//
+ // Turn on the visibility of this layer.
+ // (If the layer does not already exist in the map, it will be visible by default when it is added.
+ // But if the user has already run this script, he or she may have set the layer to be invisible.)
+ MgLayerCollection layerCollection = map.getLayers();
+ if (layerCollection.contains("Hydro"))
+ {
+ MgLayerBase hydroLayer = layerCollection.getItem("Hydro");
+ hydroLayer.setVisible(true);
+ }
+
+ //---------------------------------------------------//
+ // Save the map back to the session repository
+ map.save();
+
+ //---------------------------------------------------//
+
+}
+catch (MgException e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.getExceptionMessage() + " \"); \n");
+ out.print("</script> \n");
+}
+catch (Exception e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.toString() + " \"); \n");
+ out.print("</script> \n");
+}
+%>
+
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_point_layer_definition.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_point_layer_definition.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_point_layer_definition.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,228 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="layer_functions.jsp" %>
+<%!
+///////////////////////////////////////////////////////////////////////////////////
+MgPropertyCollection makePoint(String name, double x, double y)
+{
+ MgPropertyCollection propertyCollection = new MgPropertyCollection();
+ MgStringProperty nameProperty = new MgStringProperty("NAME", name);
+ propertyCollection.add(nameProperty);
+
+ MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+
+ MgGeometry geometry = wktReaderWriter.read("POINT XY (" + x + " " + y + ")");
+ MgByteReader geometryByteReader = agfReaderWriter.write(geometry);
+ MgGeometryProperty geometryProperty = new MgGeometryProperty("GEOM", geometryByteReader);
+ propertyCollection.add(geometryProperty);
+
+ return propertyCollection;
+}
+%>
+<html>
+
+<head>
+ <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">
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ parent.mapFrame.ZoomToScale(40000);
+ }
+ </script>
+</head>
+
+<body onLoad="OnPageLoad()">
+
+<%
+try
+{
+ //---------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+ MgFeatureService featureService = (MgFeatureService)siteConnection.createService(MgServiceType.FeatureService);
+
+ //---------------------------------------------------//
+ // Open the map
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ //---------------------------------------------------//
+ // Create a feature source with point data.
+ // (The Sheboygan sample data does not contain such data,
+ // so we'll create it.)
+
+ // Create a feature class definition for the new feature source
+ MgClassDefinition classDefinition = new MgClassDefinition();
+ classDefinition.setName("Points");
+ classDefinition.setDescription("Feature class with point data.");
+ classDefinition.setDefaultGeometryPropertyName("GEOM");
+
+ MgPropertyDefinitionCollection idProps = classDefinition.getIdentityProperties();
+ MgPropertyDefinitionCollection clsProps = classDefinition.getProperties();
+
+ // Create an identify property
+ MgDataPropertyDefinition identityProperty = new MgDataPropertyDefinition("KEY");
+ identityProperty.setDataType(MgPropertyType.Int32);
+ identityProperty.setAutoGeneration(true);
+ identityProperty.setReadOnly(true);
+ // Add the identity property to the class definition
+ clsProps.add(identityProperty);
+ idProps.add(identityProperty);
+
+ // Create a name property
+ MgDataPropertyDefinition nameProperty = new MgDataPropertyDefinition("NAME");
+ nameProperty.setDataType(MgPropertyType.String);
+ // Add the name property to the class definition
+ clsProps.add(nameProperty);
+
+ // Create a geometry property
+ MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition("GEOM");
+ geometryProperty.setGeometryTypes(MgFeatureGeometricType.Point);
+ // Add the geometry property to the class definition
+ clsProps.add(geometryProperty);
+
+ // Create a feature schema
+ MgFeatureSchema featureSchema = new MgFeatureSchema("PointSchema", "Point schema");
+ MgClassDefinitionCollection classes = featureSchema.getClasses();
+ // Add the feature schema to the class definition
+ classes.add(classDefinition);
+
+ // Create the feature source
+ String featureSourceName = "Library://Samples/DevGuide/Data/points.FeatureSource";
+ MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);
+ String wkt = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";
+ MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "LatLong", wkt, featureSchema);
+ featureService.createFeatureSource(resourceIdentifier, sdfParams);
+
+ // We need to add some data to the sdf before using it. The spatial context
+ // reader must have an extent.
+ MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
+
+ // Make four points
+ batchPropertyCollection.addItem(makePoint("Point A", -87.727, 43.748));
+
+ batchPropertyCollection.addItem(makePoint("Point B", -87.728, 43.730));
+
+ batchPropertyCollection.addItem(makePoint("Point C", -87.726, 43.750));
+
+ batchPropertyCollection.addItem(makePoint("Point D", -87.728, 43.750));
+
+ // Add the batch property collection to the feature source
+ MgInsertFeatures cmd = new MgInsertFeatures("Points", batchPropertyCollection);
+ MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
+ featureCommandCollection.add(cmd);
+
+ // Execute the "add" commands
+ featureService.updateFeatures(resourceIdentifier, featureCommandCollection, false);
+
+ // ...
+ //---------------------------------------------------//
+ // Create a new layer
+
+ LayerDefinitionFactory factory = new LayerDefinitionFactory(request);
+
+ // Create a mark symbol
+ String resourceId = "Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary";
+ String symbolName = "PushPin";
+ String width = "24"; // unit = points
+ String height = "24"; // unit = points
+ String color = "FFFF0000";
+ String markSymbol = factory.createMarkSymbol(resourceId, symbolName, width, height, color);
+
+ // Create a text symbol
+ String text = "ID";
+ String fontHeight = "12";
+ String foregroundColor = "FF000000";
+ String textSymbol = factory.createTextSymbol(text, fontHeight, foregroundColor);
+
+ // Create a point rule.
+ String legendLabel = "trees";
+ String filter = "";
+ String pointRule = factory.createPointRule(legendLabel, filter, textSymbol, markSymbol);
+
+ // Create a point type style.
+ String pointTypeStyle = factory.createPointTypeStyle(pointRule);
+
+ // Create a scale range.
+ String minScale = "0";
+ String maxScale = "1000000000000";
+ String pointScaleRange = factory.createScaleRange(minScale, maxScale, pointTypeStyle);
+
+ // Create the layer definiton.
+ String featureName = "PointSchema:Points";
+ String geometry = "GEOM";
+ String layerDefinition = factory.createLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange);
+ //---------------------------------------------------//
+ // ...
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new org.xml.sax.InputSource(new StringReader(layerDefinition)));
+ // Add the layer to the map
+ MgLayer newLayer = LayerFunctions.addLayerDefinitionToMap(doc, "Points", "Points of Interest", sessionId, resourceService, map);
+ LayerFunctions.addLayerToGroup(newLayer, "Analysis", "Analysis", map);
+
+ // --------------------------------------------------//
+ // Turn on the visibility of this layer.
+ // (If the layer does not already exist in the map, it will be visible by default when it is added.
+ // But if the user has already run this script, he or she may have set the layer to be invisible.)
+ MgLayerCollection layerCollection = map.getLayers();
+ if (layerCollection.contains("Points"))
+ {
+ MgLayerBase pointsLayer = layerCollection.getItem("Points");
+ pointsLayer.setVisible(true);
+ }
+
+ //---------------------------------------------------//
+ // Save the map back to the session repository
+ map.save();
+
+ //---------------------------------------------------//
+}
+catch (MgException e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.getExceptionMessage() + " \"); \n");
+ out.print("</script> \n");
+}
+catch (Exception e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.toString() + " \"); \n");
+ out.print("</script> \n");
+}
+
+%>
+
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_squarefootage_layer_definition.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_squarefootage_layer_definition.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/create_new_squarefootage_layer_definition.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,142 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.parsers.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.*" %>
+<%@ include file="../common/common.jsp" %>
+<%@ include file="layer_functions.jsp" %>
+<html>
+
+<head>
+ <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">
+
+ <script language="javascript" type="text/javascript">
+ function OnPageLoad()
+ {
+ parent.mapFrame.Refresh();
+ parent.mapFrame.ZoomToScale(9999);
+ }
+ </script>
+</head>
+
+<body onLoad="OnPageLoad()">
+
+<%
+try
+{
+ //---------------------------------------------------//
+ // Initialize
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+ MgResourceService resourceService = (MgResourceService)siteConnection.createService(MgServiceType.ResourceService);
+
+ // --------------------------------------------------//
+ // Open the map
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+
+ // ...
+ //---------------------------------------------------//
+ // Create a new layer
+ LayerDefinitionFactory factory = new LayerDefinitionFactory(request);
+
+ /// Create three area rules for three different
+ // scale ranges.
+ String areaRule1 = factory.createAreaRule("1 to 800",
+ "SQFT >= 1 AND SQFT < 800", "FFFFFF00");
+ String areaRule2 = factory.createAreaRule("800 to 1600",
+ "SQFT >= 800 AND SQFT < 1600", "FFFFBF20");
+ String areaRule3 = factory.createAreaRule("1600 to 2400",
+ "SQFT >= 1600 AND SQFT < 2400", "FFFF8040");
+
+ // Create an area type style.
+ String areaTypeStyle = factory.createAreaTypeStyle(areaRule1 + areaRule2 + areaRule3);
+
+ // Create a scale range.
+ String minScale = "0";
+ String maxScale = "10000";
+ String areaScaleRange = factory.createScaleRange(minScale, maxScale, areaTypeStyle);
+
+ // Create the layer definiton.
+ String featureClass = "Library://Samples/Sheboygan/Data/Parcels.FeatureSource";
+ String featureName = "SHP_Schema:Parcels";
+ String geometry = "SHPGEOM";
+ String layerDefinition = factory.createLayerDefinition(featureClass, featureName, geometry, areaScaleRange);
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new org.xml.sax.InputSource(new StringReader(layerDefinition)));
+
+ //---------------------------------------------------//
+ // ...
+
+ // Add the layer to the map
+ MgLayer newLayer = LayerFunctions.addLayerDefinitionToMap(doc, "SquareFootage", "Square Footage", sessionId, resourceService, map);
+ LayerFunctions.addLayerToGroup(newLayer, "Analysis", "Analysis", map);
+
+ //---------------------------------------------------//
+ // Turn off the "Recently Built" themed layer (if it exists) so it does not hide this layer.
+ MgLayerCollection layerCollection = map.getLayers();
+ if (layerCollection.contains("RecentlyBuilt"))
+ {
+ MgLayerBase recentlyBuiltLayer = layerCollection.getItem("RecentlyBuilt");
+ recentlyBuiltLayer.setVisible(false);
+ }
+
+ // --------------------------------------------------//
+ // Turn on the visibility of this layer.
+ // (If the layer does not already exist in the map, it will be visible by default when it is added.
+ // But if the user has already run this script, he or she may have set the layer to be invisible.)
+ layerCollection = map.getLayers();
+ if (layerCollection.contains("SquareFootage"))
+ {
+ MgLayerBase squareFootageLayer = layerCollection.getItem("SquareFootage");
+ squareFootageLayer.setVisible(true);
+ }
+
+ //---------------------------------------------------//
+ // Save the map back to the session repository
+ map.save();
+
+ //---------------------------------------------------//
+}
+catch (MgException e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.getExceptionMessage() + " \"); \n");
+ out.print("</script> \n");
+}
+catch (Exception e)
+{
+ out.print("<script language=\"javascript\" type=\"text/javascript\"> \n");
+ out.print(" alert(\" " + e.toString() + " \"); \n");
+ out.print("</script> \n");
+}
+%>
+
+</body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/layer_functions.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/layer_functions.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/layer_functions.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,263 @@
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="java.nio.charset.StandardCharsets" %>
+<%@ page import="java.nio.file.Files" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="javax.xml.transform.*" %>
+<%@ page import="javax.xml.transform.dom.*" %>
+<%@ page import="javax.xml.transform.stream.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ page import="org.w3c.dom.Document" %>
+<%!
+public static class LayerFunctions
+{
+ // Adds the layer definition (XML) to the map.
+ // Returns the layer.
+ public static MgLayer addLayerDefinitionToMap(Document domDocument, String layerName, String layerLegendLabel, String sessionId, MgResourceService resourceService, MgMap map) throws Exception
+ {
+ // Save the layer definition to the session repository. Java writes no byte order
+ // mark, so the content is used exactly as serialized.
+ byte[] layerDefinition = documentToBytes(domDocument);
+
+ MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.length);
+ MgResourceIdentifier resourceID = new MgResourceIdentifier("Session:" + sessionId + "//" + layerName + ".LayerDefinition");
+ resourceService.setResource(resourceID, byteSource.getReader(), null);
+
+ MgLayer newLayer = addLayerResourceToMap(resourceID, resourceService, layerName, layerLegendLabel, map);
+ return newLayer;
+ }
+
+ //////////////////////////////////////////////////////////////
+ // Adds a layer to a layer group. If necessary, it creates the layer group.
+ public static void addLayerToGroup(MgLayer layer, String layerGroupName, String layerGroupLegendLabel, MgMap map)
+ {
+ // Get the layer group
+ MgLayerGroupCollection layerGroupCollection = map.getLayerGroups();
+ MgLayerGroup layerGroup = null;
+ if (layerGroupCollection.contains(layerGroupName))
+ {
+ layerGroup = layerGroupCollection.getItem(layerGroupName);
+ }
+ else
+ {
+ // It does not exist, so create it
+ layerGroup = new MgLayerGroup(layerGroupName);
+ layerGroup.setVisible(true);
+ layerGroup.setDisplayInLegend(true);
+ layerGroup.setLegendLabel(layerGroupLegendLabel);
+ layerGroupCollection.add(layerGroup);
+ }
+
+ // Add the layer to the group
+ layer.setGroup(layerGroup);
+ }
+
+ //////////////////////////////////////////////////////////////
+ // Adds a layer defition (which can be stored either in the Library or a session
+ // repository) to the map.
+ // Returns the layer.
+ public static MgLayer addLayerResourceToMap(MgResourceIdentifier layerResourceID, MgResourceService resourceService, String layerName, String layerLegendLabel, MgMap map)
+ {
+ MgLayer newLayer = new MgLayer(layerResourceID, resourceService);
+
+ // Add the new layer to the map's layer collection
+ newLayer.setName(layerName);
+ newLayer.setVisible(true);
+ newLayer.setLegendLabel(layerLegendLabel);
+ newLayer.setDisplayInLegend(true);
+ MgLayerCollection layerCollection = map.getLayers();
+ if (!layerCollection.contains(layerName))
+ {
+ // Insert the new layer at position 0 so it is at the top
+ // of the drawing order
+ layerCollection.insert(0, newLayer);
+ }
+
+ return newLayer;
+ }
+
+ //////////////////////////////////////////////////////////////
+ // Serializes a DOM document to UTF-8 encoded bytes.
+ public static byte[] documentToBytes(Document document) throws Exception
+ {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ StringWriter writer = new StringWriter();
+ transformer.transform(new DOMSource(document), new StreamResult(writer));
+ return writer.toString().getBytes("UTF-8");
+ }
+}
+
+public static class LayerDefinitionFactory
+{
+ private final File viewerFilesDir;
+
+ public LayerDefinitionFactory(HttpServletRequest request)
+ {
+ // The layer definition templates are shared by all the samples, and live beside
+ // this sample group rather than inside it.
+ File pageDir = new File(request.getServletContext().getRealPath(request.getServletPath())).getParentFile();
+ File samplesRoot = pageDir.getParentFile();
+ this.viewerFilesDir = new File(samplesRoot, "viewerfiles");
+ }
+
+ // Reads one of the layer definition templates.
+ private String readTemplate(String fileName) throws IOException
+ {
+ byte[] contents = Files.readAllBytes(new File(viewerFilesDir, fileName).toPath());
+ return new String(contents, StandardCharsets.UTF_8);
+ }
+
+ // Substitutes the values into a template: "%s" consumes the next value, "%%" produces
+ // a single "%", and any other "%x" produces "@" so that a template which does not match
+ // the values it is given yields content that is obviously wrong.
+ private static String substitute(String templ, String[] vals)
+ {
+ StringBuilder res = new StringBuilder();
+ int index = 0, val = 0;
+ boolean found;
+ do
+ {
+ found = false;
+ int i = templ.indexOf('%', index);
+ if (i != -1)
+ {
+ found = true;
+ res.append(templ.substring(index, i));
+ if (i < templ.length() - 1)
+ {
+ if (templ.charAt(i + 1) == '%')
+ res.append('%');
+ else if (templ.charAt(i + 1) == 's')
+ res.append(vals[val ++]);
+ else
+ res.append('@'); //add a character illegal in jscript so we know the template was incorrect
+ index = i + 2;
+ }
+ }
+ } while (found);
+ res.append(templ.substring(index));
+ return res.toString();
+ }
+
+ //Creates Area Rule
+ //Parameters:
+ // legendLabel - string for the legend label
+ // filterText - filter string
+ // fillColor - fill color
+ public String createAreaRule(String legendLabel, String filterText, String fillColor) throws IOException
+ {
+ String areaRule = readTemplate("arearule.templ");
+ return substitute(areaRule, new String[] { legendLabel, filterText, fillColor });
+ }
+
+ //Creates AreaTypeStyle.
+ //Parameters:
+ //areaRules - call createAreaRule to create area rules
+ public String createAreaTypeStyle(String areaRules) throws IOException
+ {
+ String style = readTemplate("areatypestyle.templ");
+ return substitute(style, new String[] { areaRules });
+ }
+
+ //Creates line rule
+ //Parameters:
+ //color - color code for the line
+ //legendLabel - string for the legend label
+ //filter - filter string
+ public String createLineRule(String legendLabel, String filter, String color) throws IOException
+ {
+ String lineRule = readTemplate("linerule.templ");
+ return substitute(lineRule, new String[] { legendLabel, filter, color });
+ }
+
+ //Creates LineTypeStyle
+ //Parameters:
+ //lineRules - call createLineRule to create line rules
+ public String createLineTypeStyle(String lineRules) throws IOException
+ {
+ String lineStyle = readTemplate("linetypestyle.templ");
+ return substitute(lineStyle, new String[] { lineRules });
+ }
+
+ //Creates mark symbol
+ //Parameters:
+ //resourceId - resource identifier for the resource to be used
+ //symbolName - the name of the symbol
+ //width - the width of the symbol
+ //height - the height of the symbol
+ //color - color code for the symbol color
+ public String createMarkSymbol(String resourceId, String symbolName, String width, String height, String color) throws IOException
+ {
+ String markSymbol = readTemplate("marksymbol.templ");
+ return substitute(markSymbol, new String[] { width, height, resourceId, symbolName, color });
+ }
+
+ //Creates text symbol
+ //Parameters:
+ //text - string for the text
+ //fontHeight - the height for the font
+ //foregroundColor - color code for the foreground color
+ public String createTextSymbol(String text, String fontHeight, String foregroundColor) throws IOException
+ {
+ String textSymbol = readTemplate("textsymbol.templ");
+ return substitute(textSymbol, new String[] { fontHeight, fontHeight, text, foregroundColor });
+ }
+
+ //Creates a point rule
+ //Parameters:
+ //pointSym - point symbolization. Use createMarkSymbol to create it
+ //legendlabel - string for the legend label
+ //filter - string for the filter
+ //label - use createTextSymbol to create it
+ public String createPointRule(String legendLabel, String filter, String label, String pointSym) throws IOException
+ {
+ String pointRule = readTemplate("pointrule.templ");
+ return substitute(pointRule, new String[] { legendLabel, filter, label, pointSym });
+ }
+
+ //Creates PointTypeStyle
+ //Parameters:
+ //pointRule - use createPointRule to define rules
+ public String createPointTypeStyle(String pointRule) throws IOException
+ {
+ String pointTypeStyle = readTemplate("pointtypestyle.templ");
+ return substitute(pointTypeStyle, new String[] { pointRule });
+ }
+
+ //Creates ScaleRange
+ //Parameterss
+ //minScale - minimum scale
+ //maxScale - maximum scale
+ //typeStyle - use one createAreaTypeStyle, createLineTypeStyle, or createPointTypeStyle
+ public String createScaleRange(String minScale, String maxScale, String typeStyle) throws IOException
+ {
+ String scaleRange = readTemplate("scalerange.templ");
+ return substitute(scaleRange, new String[] { minScale, maxScale, typeStyle });
+ }
+
+ //Creates a layer definition
+ //resourceId - resource identifier for the new layer
+ //featureClass - the name of the feature class
+ //geometry - the name of the geometry
+ //featureClassRange - use createScaleRange to define it.
+ public String createLayerDefinition(String resourceId, String featureClass, String geometry, String featureClassRange) throws IOException
+ {
+ String layerDef = readTemplate("layerdefinition.templ");
+ return substitute(layerDef, new String[] { resourceId, featureClass, geometry, featureClassRange });
+ }
+}
+%>
Added: branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/task_pane.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/modifying_maps_and_layers/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+ Copyright (C) 2004-2011 by Autodesk, Inc.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of version 2.1 of the GNU Lesser
+ General Public License as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <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">
+ <h1 class="AppHeading">Modifying Maps & Layers</h1>
+ <p>The following links all load in the hidden script frame, leaving this task pane visible.</p>
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <ul>
+ <li><a href="change_layers_via_dom.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" target="scriptFrame">
+ Change Layers via DOM</a>
+ <br>Show buildings built after 1980.
+ <br>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "change_layers_via_dom.jsp") %>" >View source</a>
+ </li>
+
+ <li><a href="create_new_squarefootage_layer_definition.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" target="scriptFrame">
+ Create Square Footage Layer</a>
+ <br>Show a map themed by areas.
+ <br>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "create_new_squarefootage_layer_definition.jsp") %>" >View source</a>
+ </li>
+
+ <li><a href="create_new_line_layer_definition.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" target="scriptFrame">
+ Create Hydro Line Layer</a>
+ <br>Show a map themed by lines.
+ <br>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "create_new_line_layer_definition.jsp") %>" >View source</a>
+ </li>
+
+ <li><a href="create_new_point_layer_definition.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" target="scriptFrame">
+ Create Points of Interest Layer</a>
+ <br>Show a map themed by points.
+ <br>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "create_new_point_layer_definition.jsp") %>" >View source</a>
+ </li>
+ </ul>
+ <p>View source for support files:</p>
+ <ul>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "RecentlyBuilt.LayerDefinition") %>">RecentlyBuilt.LayerDefinition</a></li>
+ <li><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "layer_functions.jsp") %>">layer_functions.jsp</a></li>
+ </ul>
+ <p>Map Debugging:</p>
+ <a target="_blank" href="../common/mapinfo.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>">Map Information</a>
+ </body>
+</html>
Modified: branches/4.0/MgDev/Doc/samples/javasamples/readme.txt
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/readme.txt 2026-11-15 13:56:59 UTC (rev 10290)
+++ branches/4.0/MgDev/Doc/samples/javasamples/readme.txt 2026-11-18 15:26:37 UTC (rev 10291)
@@ -3,14 +3,23 @@
This is the complete set of Java samples referenced in the MapGuide Developer's Guide
-Notes
------
+Installation
+------------
-These samples assume that MapGuide Open Source is installed in the default location in
-C:\Program Files\OSGeo\MapGuide
+These samples are installed with the web tier and are served by the bundled Tomcat:
-If this is not the case edit common/common.jsp and change the paths to match your install location
+ <install>/webserverextensions/www/javasamples
-These samples require a user named "Author" (pass: author) with authoring privileges. This is a default user in a standard MapGuide installation. If you have deleted or modified this user, edit main.php and update with a matching login
+Nothing has to be configured or edited after an installation. common/common.jsp derives every
+directory the samples use from the location the page is deployed to, so the samples follow the
+installation wherever it is.
-These samples require the Sheboygan sample dataset. Load this package first before running the samples.
\ No newline at end of file
+Requirements
+------------
+
+These samples require a user named "Author" (pass: author) with authoring privileges. This is a
+default user in a standard MapGuide installation. If you have deleted or modified this user, edit
+main.jsp and update with a matching login
+
+These samples require the Sheboygan sample dataset. Load this package first before running the
+samples.
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/arearule.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/arearule.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/arearule.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,18 @@
+<AreaRule>
+ <LegendLabel>%s</LegendLabel>
+ <Filter>%s</Filter>
+ <AreaSymbolization2D>
+ <Fill>
+ <FillPattern>Solid</FillPattern>
+ <ForegroundColor>%s</ForegroundColor>
+ <BackgroundColor>FF000000</BackgroundColor>
+ </Fill>
+ <Stroke>
+ <LineStyle>Solid</LineStyle>
+ <Thickness>1</Thickness>
+ <Color>FF000000</Color>
+ <Unit>Points</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ </Stroke>
+ </AreaSymbolization2D>
+</AreaRule>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/areatypestyle.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/areatypestyle.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/areatypestyle.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1 @@
+<AreaTypeStyle>%s</AreaTypeStyle>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/layerdefinition.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/layerdefinition.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/layerdefinition.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LayerDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LayerDefinition-1.3.0.xsd" version="1.3.0">
+ <VectorLayerDefinition>
+ <ResourceId>%s</ResourceId>
+ <FeatureName>%s</FeatureName>
+ <FeatureNameType>FeatureClass</FeatureNameType>
+ <Geometry>%s</Geometry>
+ %s
+ </VectorLayerDefinition>
+</LayerDefinition>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linerule.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linerule.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linerule.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,11 @@
+<LineRule>
+ <LegendLabel>%s</LegendLabel>
+ <Filter>%s</Filter>
+ <LineSymbolization2D>
+ <LineStyle>Solid</LineStyle>
+ <Thickness>1</Thickness>
+ <Color>%s</Color>
+ <Unit>Points</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ </LineSymbolization2D>
+</LineRule>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linetypestyle.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linetypestyle.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/linetypestyle.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1 @@
+<LineTypeStyle>%s</LineTypeStyle>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/marksymbol.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/marksymbol.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/marksymbol.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,15 @@
+<W2D>
+ <Unit>Points</Unit>
+ <SizeContext>DeviceUnits</SizeContext>
+ <SizeX>%s</SizeX>
+ <SizeY>%s</SizeY>
+ <Rotation>0</Rotation>
+ <MaintainAspect>true</MaintainAspect>
+ <W2DSymbol>
+ <ResourceId>%s</ResourceId>
+ <LibraryItemName>%s</LibraryItemName>
+ </W2DSymbol>
+ <FillColor>%s</FillColor>
+ <LineColor>FF000000</LineColor>
+ <TextColor>FF000000</TextColor>
+</W2D>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointrule.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointrule.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointrule.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,6 @@
+<PointRule>
+ <LegendLabel>%s</LegendLabel>
+ <Filter>%s</Filter>
+ <Label>%s</Label>
+ <PointSymbolization2D>%s</PointSymbolization2D>
+</PointRule>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointtypestyle.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointtypestyle.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/pointtypestyle.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,5 @@
+<PointTypeStyle>
+ <DisplayAsText>false</DisplayAsText>
+ <AllowOverpost>false</AllowOverpost>
+ %s
+</PointTypeStyle>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/scalerange.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/scalerange.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/scalerange.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,5 @@
+<VectorScaleRange>
+ <MinScale>%s</MinScale>
+ <MaxScale>%s</MaxScale>
+ %s
+</VectorScaleRange>
Added: branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/textsymbol.templ
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/textsymbol.templ (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/viewerfiles/textsymbol.templ 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,15 @@
+<Unit>Points</Unit>
+<SizeContext>DeviceUnits</SizeContext>
+<SizeX>%s</SizeX>
+<SizeY>%s</SizeY>
+<Rotation>0</Rotation>
+<Text>%s</Text>
+<FontName>Arial</FontName>
+<ForegroundColor>%s</ForegroundColor>
+<BackgroundColor>FF000000</BackgroundColor>
+<BackgroundStyle>Transparent</BackgroundStyle>
+<HorizontalAlignment>Center</HorizontalAlignment>
+<VerticalAlignment>Baseline</VerticalAlignment>
+<Bold>false</Bold>
+<Italic>false</Italic>
+<Underlined>false</Underlined>
Added: branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/listselection.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/listselection.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/listselection.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,130 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+Copyright (C) 2004-2011 by Autodesk, Inc.
+This library is free software; you can redistribute it and/or
+modify it under the terms of version 2.1 of the GNU Lesser
+General Public License as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+
+<%@ page import="java.io.*" %>
+<%@ page import="java.net.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+
+ <head>
+ <title>Viewer Sample Application - List Selected Parcels</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" >
+
+ <h1 class="AppHeading">Selected Parcels</h1>
+
+ <%
+ 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.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // ----------------------------------------------------------
+ // Use the following code for AJAX or DWF Viewers
+ // This requires passing selection data via HTTP POST
+
+ MgSelection selection = null;
+ MgReadOnlyLayerCollection layers = null;
+ String encodedSelection = request.getParameter("SELECTION");
+ if (encodedSelection != null && encodedSelection.length() > 0)
+ {
+ selection = new MgSelection(map, URLDecoder.decode(encodedSelection, "UTF-8"));
+ layers = selection.getLayers();
+ }
+ // ---------------------------------------------------------
+
+ // ---------------------------------------------------------
+ // Use the following code for AJAX Viewers only.
+ // This does not require passing selection data via HTTP POST.
+ //
+ // selection = new MgSelection(map);
+ // selection.open(resourceService, mapName);
+ // layers = selection.getLayers();
+ // ---------------------------------------------------------
+
+ if (layers != null && selection != null)
+ {
+ for (int i = 0; i < layers.getCount(); i++)
+ {
+ // Only check selected features in the Parcels layer.
+
+ MgLayerBase layer = layers.getItem(i);
+
+ if (layer.getName().equals("Parcels"))
+ {
+
+ // Create a filter containing the IDs of the selected features on this layer
+
+ String layerClassName = layer.getFeatureClassName();
+
+ MgFeatureReader featureReader = selection.getSelectedFeatures(layer, layerClassName, false);
+
+ // Process each item in the MgFeatureReader, displaying the owner name
+
+ try {
+ while (featureReader.readNext())
+ {
+ String val = featureReader.getString("NAME") + "<br /> " + featureReader.getString("RPROPAD");
+ out.print(val + "<br />");
+ }
+ } finally { //Finally guarantees code in this block will execute
+ featureReader.close();
+ }
+ }
+ }
+ }
+ else
+ {
+ out.print("No selected layers");
+ out.print("</p>");
+ }
+ }
+ catch (MgException e)
+ {
+ out.print("<p>" + e.getExceptionMessage() + "</p>");
+ out.print("<p>" + e.getDetails() + "</p>");
+ }
+ catch (Exception e)
+ {
+ out.print("<p>" + e.toString() + "</p>");
+ }
+ %>
+
+ <p><a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "listselection.jsp") %>" >View source</a></p>
+ </body>
+
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/queryfeatures.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/queryfeatures.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/queryfeatures.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,118 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+Copyright (C) 2004-2011 by Autodesk, Inc.
+This library is free software; you can redistribute it and/or
+modify it under the terms of version 2.1 of the GNU Lesser
+General Public License as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+
+ <head>
+ <title>Viewer Sample Application - Query Parcels</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">
+
+ <h1 class="AppHeading">Feature Query</h1>
+
+ <%
+
+ 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.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // Get the geometry for the boundaries of District 6
+
+ MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();
+ districtQuery.setFilter("ID = '6'");
+
+ MgLayerBase layer = map.getLayers().getItem("Districts");
+ MgFeatureReader featureReader = layer.selectFeatures(districtQuery);
+ MgByteReader districtGeometryData = null;
+ try {
+ featureReader.readNext();
+ districtGeometryData = featureReader.getGeometry(layer.getFeatureGeometryName());
+ } finally { //Ensures this block is always run
+ featureReader.close();
+ }
+
+ // Convert the AGF binary data to MgGeometry.
+
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgGeometry districtGeometry = agfReaderWriter.read(districtGeometryData);
+
+ // Create a filter to select the desired features.
+ // Combine a basic filter and a spatial filter.
+
+ MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
+ queryOptions.setFilter("RNAME LIKE 'SCHMITT%'");
+
+ queryOptions.setSpatialFilter("SHPGEOM", districtGeometry, MgFeatureSpatialOperations.Inside);
+
+ // Select the features.
+
+ layer = map.getLayers().getItem("Parcels");
+ featureReader = layer.selectFeatures(queryOptions);
+
+ // For each selected feature, display the address.
+
+ out.print("<p>Properties owned by Schmitt ");
+ out.print("in District 6</p><p>");
+
+ try {
+ while (featureReader.readNext())
+ {
+ String val = featureReader.getString("RPROPAD");
+ out.print(val + "<br />");
+ }
+ } finally { //Ensures this block is always run
+ featureReader.close();
+ }
+ out.print("</p>");
+ }
+ catch (MgException e)
+ {
+ out.print(e.getExceptionMessage());
+ out.print(e.getDetails());
+ }
+ catch (Exception e)
+ {
+ out.print(e.toString());
+ }
+ %>
+ </body>
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/selectfeatures.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/selectfeatures.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/selectfeatures.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,126 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+Copyright (C) 2004-2011 by Autodesk, Inc.
+This library is free software; you can redistribute it and/or
+modify it under the terms of version 2.1 of the GNU Lesser
+General Public License as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ page import="org.osgeo.mapguide.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+
+ <head>
+ <title>Viewer Sample Application - Server-side Selection</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()">
+
+ <h1 class="AppHeading">Select features</h1>
+
+ <%
+
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ String selectionXml = "";
+
+ try
+ {
+
+ // Initialize the Web Extensions and connect to the Server using
+ // the Web Extensions session identifier.
+
+ MapGuideJavaApi.mgInitializeWebTier(webconfigFilePath);
+
+ MgUserInformation userInfo = new MgUserInformation(sessionId);
+ MgSiteConnection siteConnection = new MgSiteConnection();
+ siteConnection.open(userInfo);
+
+ MgMap map = new MgMap(siteConnection);
+ map.open(mapName);
+
+ // Get the geometry for the boundaries of District 6
+
+ MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();
+ districtQuery.setFilter("ID = '6'");
+
+ MgLayerBase layer = map.getLayers().getItem("Districts");
+ MgFeatureReader featureReader = layer.selectFeatures(districtQuery);
+ MgByteReader districtGeometryData = null;
+ try {
+ featureReader.readNext();
+ districtGeometryData = featureReader.getGeometry(layer.getFeatureGeometryName());
+ } finally { //Ensures the reader is closed regardless
+ featureReader.close();
+ }
+
+ // Convert the AGF binary data to MgGeometry.
+
+ MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
+ MgGeometry districtGeometry = agfReaderWriter.read(districtGeometryData);
+
+ // Create a filter to select the desired features. Combine
+ // a basic filter and a spatial filter.
+
+ MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
+ queryOptions.setFilter("RNAME LIKE 'SCHMITT%'");
+ queryOptions.setSpatialFilter("SHPGEOM", districtGeometry, MgFeatureSpatialOperations.Inside);
+
+ // Get the features from the feature source,
+ // turn it into a selection, then save the selection as XML.
+
+ layer = map.getLayers().getItem("Parcels");
+ featureReader = layer.selectFeatures(queryOptions);
+
+ MgSelection selection = new MgSelection(map);
+ selection.addFeatures(layer, featureReader, 0);
+ selectionXml = selection.toXml();
+
+ out.print("Selecting parcels owned by Schmitt in District 6");
+ }
+ catch (MgException e)
+ {
+ out.print(e.getExceptionMessage());
+ out.print(e.getDetails());
+ }
+ catch (Exception e)
+ {
+ out.print(e.toString());
+ }
+ %>
+
+ </body>
+
+ <script language="javascript">
+
+ <!-- Emit this function and assocate it with the onLoad event for the -.
+ <!-- page so that it gets executed when this page loads in the -.
+ <!-- browser. The function calls the SetSelectionXML method on the -.
+ <!-- Viewer Frame, which updates the current selection on the viewer -.
+ <!-- and the server. -.
+
+ function OnPageLoad()
+ {
+ selectionXml = '<%= selectionXml %>';
+ parent.parent.SetSelectionXML(selectionXml);
+ }
+
+ </script>
+
+</html>
Added: branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/task_pane.jsp
===================================================================
--- branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/task_pane.jsp (rev 0)
+++ branches/4.0/MgDev/Doc/samples/javasamples/working_with_feature_data/task_pane.jsp 2026-11-18 15:26:37 UTC (rev 10291)
@@ -0,0 +1,84 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%--
+Copyright (C) 2004-2011 by Autodesk, Inc.
+This library is free software; you can redistribute it and/or
+modify it under the terms of version 2.1 of the GNU Lesser
+General Public License as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+--%>
+
+<%@ page import="java.io.*" %>
+<%@ page import="javax.servlet.http.*" %>
+<%@ include file="../common/common.jsp" %>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
+ <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">
+ <script language="javascript">
+ function ZoomToDistrict()
+ {
+ parent.parent.ZoomToView(-87.727698, 43.735028, 8000, true);
+ }
+ function listSelection()
+ {
+ xmlSel = encodeURIComponent(parent.parent.mapFrame.GetSelectionXML());
+ params = new Array("SESSION", parent.parent.mapFrame.GetSessionId(),
+ "MAPNAME", parent.parent.mapFrame.GetMapName(),
+ "SELECTION", xmlSel);
+ pageUrl = "/mapguide/javasamples/working_with_feature_data/listselection.jsp";
+ parent.parent.formFrame.Submit(pageUrl, params, "taskPaneFrame");
+ }
+ </script>
+ <meta http-equiv="content-script-type" content="text/javascript">
+ </head>
+ <body class="AppFrame">
+ <h1 class="AppHeading">Working With Feature Data</h1>
+ <p>
+ <%
+ String sessionId = request.getParameter("SESSION");
+ String mapName = request.getParameter("MAPNAME");
+ %>
+ <ul>
+ <li>
+ <a href="#" onclick="ZoomToDistrict();" >Zoom to District 6</a>
+ <br />Position the map to display parcels in District 6
+ </li>
+ <li>
+ <a href="queryfeatures.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" >Query features</a>
+ <br />List properties in District 6 owned by Schmitt
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "queryfeatures.jsp") %>" >View source</a>
+ </li>
+ <li>
+ <a href="selectfeatures.jsp?SESSION=<%= sessionId %>&MAPNAME=<%= mapName %>" >Set active selection</a>
+ <br />Select properties in District 6 owned by Schmitt
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "selectfeatures.jsp") %>" >View source</a>
+ </li>
+ <li>
+ <a href="#" onclick="listSelection();" >List selected features</a>
+ <br />Lists currently selected features
+ <br/>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "listselection.jsp") %>" >View source</a>
+ </li>
+ </ul>
+ </p>
+ <p>View the source for this task pane, showing JavaScript for repositioning map and initiating selection list.</p>
+ <ul>
+ <li>
+ <a target="_blank" href="../common/viewsource.jsp?FILENAME=<%= samplePath(request, "task_pane.jsp") %>" >task_pane.jsp</a>
+ </li>
+ </ul>
+ </p>
+ </body>
+</html>
More information about the mapguide-commits
mailing list