English

Problem: Map.displayFeatures() returns an empty image on point layers

Description

In Java Connector, com.esri.aims.mtier.model.map.Map class has a convenient method displayFeatures() to highlight and zoom to specific features on the map, based on the query set in the feature layer. However, if the selection contains only one feature and the feature layer is of Point type, the returned map is empty.

Note:
This problem does not occur if more than one point feature is selected or the feature layer is of line or polygon type.

Cause

When the zoomToFeatures argument is set to true in map.displayFeatures method, Java Connector uses the envelope of the selected features to set the extent of the map. In the case of only one point feature being selected, the envelope represents a point instead of a real envelope and thus an empty image is generated.

Solution or Workaround

Build a small envelope around the point and zoom to this envelope.

  1. Determine if the feature layer is a point layer:

    Code:
    if (fLayer.getFeatureClass().equalsIgnoreCase("POINT"))

  2. Determine if there is only one feature in the recordset:

    Code:
    if (fLayer.getRecordset().getCount() == 1 )

  3. If both of the above conditions are true, build a Point object based on the following point feature:

    Code:
    com.esri.aims.mtier.model.acetate.Point pnt =new com.esri.aims.mtier.model.acetate.Point();
    pnt.setX(fLayer.getRecordset().getEnvelope(0).getMaxX());
    pnt.setY(fLayer.getRecordset().getEnvelope(0).getMaxY());

  4. Build a small envelope around the point and zoom to this envelope:

    Code:
    com.esri.aims.mtier.model.envelope.Envelope envelope = new com.esri.aims.mtier.model.envelope.Envelope();
    double size=8.0; //change this number to make the envelope bigger or smaller
    envelope.setMinX(pnt.getX() - size);
    envelope.setMinY(pnt.getY() - size);
    envelope.setMaxX(pnt.getX() + size);
    envelope.setMaxY(pnt.getY() + size);
    map.doZoomToExtent(envelope);
    map.refresh();

  5. The following is a complete sample that can be run with 'SantaClara' service:
    DisplayFeatures.zip

Related Information