English

Bug: Empty map is returned when the zoomToFeatures attribute of the displayFeatures method is set to true

Description

When using ArcIMS Java Connector, calling the displayFeatures method on a map when the zoomToFeatures attribute is set to true returns an empty map. This happens only with the point layer, and when the resultant recordset contains only one feature.

Cause

When displayFeatures is called with the zoomToFeatures attribute set to true, Java Connector first sets a filter internally and sends a GET_FEATURES request. From the ArcXML response, it gets the global envelope of the resulting recordset. It then sends a GET_IMAGE request with the map extent equal to the global envelope obtained from the previous request. If the recordset contains a single point feature, the global envelope of the recordset will be an envelope with minx=maxx and miny=maxy, which is not a real envelope but a point. As a result, an empty image is returned.

Workaround

Use a filter object to get the global envelope of the recordset. Apply a tolerance value to the boundary of the global envelope and create a new envelope. Set this new envelope to the Map object to zoom to the selected features.

Below is a scriplet and a tag JSP sample page, which can be configured and run the same way as 'jspSamples'.
 

Note:
'jspSamples' can be installed from the ArcIMS CD. Check the readme file in the ArcIMS Home/Samples/Java folder for configuring and running the samples.
  • Scriplet Sample:
<%@page contentType="text/html"%>

<%@ page import="com.esri.aims.mtier.model.map.layer.FeatureLayer" %>
<%@ page import="com.esri.aims.mtier.model.envelope.Envelope" %>
<%@ page import="com.esri.aims.mtier.model.map.layer.renderer.symbol.SimpleMarkerSymbol" %>
<%@ page import="com.esri.aims.mtier.model.map.layer.renderer.symbol.SimpleLineSymbol" %>
<%@ page import="com.esri.aims.mtier.model.acetate.Line" %>
<%@ page import="com.esri.aims.mtier.model.acetate.Point" %>
<%@ page import="com.esri.aims.mtier.model.acetate.Polygon" %>
<%@ page import="com.esri.aims.mtier.model.acetate.Ring" %>
<%@ page import="com.esri.aims.mtier.model.acetate.Points" %>
<%@ page import="com.esri.aims.mtier.model.util.CoordsToPoints" %>
<%@ page import="com.esri.aims.mtier.model.map.layer.query.Filter" %>
<%@ page import="com.esri.aims.mtier.model.map.layer.query.Recordset" %>
<jsp:useBean id="connection" class="com.esri.aims.mtier.io.ConnectionProxy" scope="page" />
<jsp:useBean id="map" class="com.esri.aims.mtier.model.map.Map" scope="page" />

<html><head><title>Testing Displayfeatures Method with Spatial Object</title></head>
<BODY bgcolor="#ffffff"><p align="center">

<%
if (connection.getHost() == null){
connection.setHost("localhost");
connection.setPort(5300);
connection.setService("SantaClara");
map.initMap(connection, 0, true, true, true, true);
map.setWidth(500);
map.setHeight(350);
}

SimpleMarkerSymbol simplePoint = new SimpleMarkerSymbol();
simplePoint.setColor("255,255,0");
simplePoint.setWidth(14);

Filter filter=new Filter();
filter.setWhereExpression("NAME='San Jose'");
filter.setGlobalEnvelope(true);

FeatureLayer fLayer = (FeatureLayer)map.getLayers().item(5);
fLayer.setFilterObject(filter);
map.refresh();
Recordset rec = fLayer.getRecordset();
Envelope env = rec.getEnvelope(0);
double minx = env.getMinX();
double miny = env.getMinY();
double maxx = env.getMaxX();
double maxy = env.getMaxY();
double tol=0.02;
Envelope env1 = new Envelope();
env1.setMaxX(maxx+tol);
env1.setMaxY(maxy+tol);
env1.setMinX(minx-tol);
env1.setMinY(miny-tol);
map.setEnvelope(env1);

rec.clearRecordset();
fLayer.setFilterObject(null);

map.displayFeatures(fLayer, "NAME='San Jose'", false, simplePoint);
map.refresh();
String mapURL = map.getMapOutput().getURL();
%>

<img src="<%=mapURL%>">
</body>
</html>
  •  Tag Sample:
<%@taglib prefix="aims" uri="arcims_taglib.tld" %>
<%@page import="java.util.Vector" %>

<html><head><title>Testing Displayfeatures Method with Spatial Object</title></head>
<BODY bgcolor="#ffffff"><p align="center">
<aims:getSettings id="myHost" value="host" propFileName="jspsamples.properties" />
<aims:getSettings id="myPort" value="port" propFileName="jspsamples.properties" />
<aims:getSettings id="myService" value="service" propFileName="jspsamples.properties" />

<aims:tcpConnection id="myConnection" host="<%=(myHost)%>" port="<%=(myPort)%>" debug="false"/>
<aims:mapService id="myMapService" connectionId="<%=(myConnection)%>" name="<%=(myService)%>" 
        loadEnvelope="true" loadExtensions="true" loadRecordset="true" loadRenderer="true"/>

<%
    String fieldValue = null;
    String recCount = "0";
    Vector fieldsCollection = new Vector();
    int i=0;
    int j=0;
    String x1 = null;
    String y1 = null;
    String x2=null;
    String y2=null;    
%>


<aims:map id="myMap" serviceId="<%=(myMapService)%>" createMap="false">
    <aims:separators ts="," cs=" " />
    <aims:layer layerId="5" visible="true">
        <aims:filter globalEnvelope="true" whereExpression="NAME='San Jose'">
        </aims:filter>
        <aims:recordset>
            <table border="1"><tr>
            <aims:iterateTableDesc fieldName="fName" fieldPrecision="fPrecision" fieldType="fType" fieldLength="fLength" >
                <td bgcolor="#ffe6a6"><%=(fName)%></td>
            </aims:iterateTableDesc></tr><tr>
            <aims:iterateRecordset recordsetCount="rsCount" recordLength="recLength" fieldValue="fValue">                                    
<%              recCount = rsCount; 
                fieldsCollection.add(fValue);
		if (i % (Integer.parseInt(recLength))  == 0) {
%>
		</tr><tr><td><%=(fValue)%></td>
<%
		}else{
%>
		<td><%=(fValue)%></td> 
<%
		}
		i++;
%>
            </aims:iterateRecordset>

        <aims:iterateEnvelope maxx="maxx" maxy="maxy" minx="minx" miny="miny" >
       <%
        if (j==0) {
        x1=String.valueOf(Double.parseDouble(maxx)+0.02);
        y1=String.valueOf(Double.parseDouble(maxy)+0.02);
        x2=String.valueOf(Double.parseDouble(minx)-0.02);
        y2=String.valueOf(Double.parseDouble(miny)-0.02);

        }
        j++;     
       %>      
 
        </aims:iterateEnvelope>

        </aims:recordset>
</table>
    </aims:layer>
</aims:map>

<aims:map id="myMap2" serviceId="<%=(myMapService)%>" width="500" height="300" createMap="true">
  <aims:envelope minx="<%=(x2)%>" miny="<%=(y2)%>" maxx="<%=(x1)%>" maxy="<%=(y1)%>" />   
    <aims:layer layerId="5">
        <aims:displayFeatures expression="NAME='San Jose'" zoomToFeatures="false" >
            <aims:simpleMarkerSymbol width="25" type="star" color="0,0,255" outline="0,0,0" shadow="0,0,0" />          
        </aims:displayFeatures>
    </aims:layer>
</aims:map>
<center><img src="<%=myMap2%>"/></center>
</body>
</html>