⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gazetteersearchresult.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.common.gazetteer;

import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.query.WebQuery;

import java.util.HashMap;
import java.util.Map;


/**
 * This class is meant to represent a Gazetteer record returned from a
 * Gazetteer get records request.
 */
@SuppressWarnings("serial")
public class GazetteerSearchResult {
    /**
     * Reference to the Java ADF {@link WebContext} object.
     */
    private WebContext m_context = null;

    /**
     * {@link WebGeometry} geographic location of the Gazetteer record.
     */
    private WebGeometry m_geometry = null;

    /**
     * Name of the Gazeteer record.
     */
    private String m_name = null;

    /**
     * Detailed information of the Gazetteer record.
     *
     * <p>
     * Key:                Column name.
     * Value:        Column value.
     * </p>
     */
    private Map<String, String> m_details = null;

    /**
     * Constructor that initializes the instance with the given
     * <code>context</code> and <code>geom</code>.
     *
     * @param context Reference to the Java ADF {@link WebContext}.
     * @param geom {@link WebGeometry} geographic location.
     * @throws NullPointerException Thrown if the <code>context</code> or <code>geom</code>
     *                         arguments are <code>null</code>.
     */
    public GazetteerSearchResult(WebContext context, WebGeometry geom) {
        if (context == null) {
            throw new NullPointerException();
        }

        if (geom == null) {
            throw new NullPointerException();
        }

        m_context = context;
        m_geometry = geom;
        m_details = new HashMap<String, String>();
    }

    /**
     * Constructor that initializes the instance with the given
     * <code>geom</code>.  To set the reference to the Java ADF
     * {@link WebContext} object use {@link #setWebContext(WebContext)}.
     *
     * @param geom {@link WebGeometry} geographic location.
     * @throws NullPointerException Thrown if the <code>geom</code> argument
     *                         is <code>null</code>.
     */
    public GazetteerSearchResult(WebGeometry geom) {
        if (geom == null) {
            throw new NullPointerException();
        }

        m_geometry = geom;
        m_details = new HashMap<String, String>();
    }

    /**
     * Gets the name of the Gazetteer record.
     *
     * @return {@link String} name of the Gazetteer record.
     */
    public String getName() {
        return m_name;
    }

    /**
     * Sets the name of the Gazetteer record.
     *
     * @param name {@link String} name of the Gazetteer record.
     */
    public void setName(String name) {
        m_name = name;
    }

    /**
     * Gets the detail {@link Map} of the Gazetteer record.
     *
     * <p>
     * Key:                Column name.
     * Value:        Column value.
     * </p>
     *
     * @return Detail {@link Map} for the Gazetteer record.
     */
    public Map<String, String> getDetails() {
        return m_details;
    }

    /**
     * Sets the detail {@link Map} of the Gazetteer record.
     *
     * <p>
     * Key:                Column name.
     * Value:        Column value.
     * </p>
     *
     * @param details Detail {@link Map} for the Gazetteer record.
     */
    public void setDetails(Map<String, String> details) {
        m_details = details;
    }

    /**
     * Sets the reference to the Java ADF {@link WebContext}.
     *
     * @param context Reference to the Java ADF {@link WebContext}.
     * @throws NullPointerException Thrown if the <code>context</code> argument
     *                         is <code>null</code>.
     */
    public void setWebContext(WebContext context) {
        if (context == null) {
            throw new NullPointerException();
        }

        m_context = context;
    }

    /**
     * Action method to zoom to the geographic location of the
     * Gazetteer record stored in {@link #m_geometry}.
     *
     * <p>
     * Possible implementations
     * of the {@link WebGeometry} supported are {@link WebPoint} and
     * {@link WebPolygon}.
     * </p>
     */
    public void zoomTo() {
        WebMap map = null;

        map = m_context.getWebMap();

        if (m_geometry instanceof WebPoint) {
            map.centerAt((WebPoint) m_geometry, 0.1d);
            m_context.refresh();
        } else if (m_geometry instanceof WebPolygon) {
            double[] longs;
            double[] lats;
            double minx = 0D;
            double miny = 0D;
            double maxx = 0D;
            double maxy = 0D;
            WebPolygon polygon = (WebPolygon) m_geometry;
            WebExtent extent = null;

            longs = polygon.getRing(0).getXs();
            lats = polygon.getRing(0).getYs();

            minx = longs[0];
            maxx = longs[0];
            miny = lats[0];
            maxy = lats[0];

            for (int i = 0; i < longs.length; i++) {
                minx = (longs[i] < minx) ? longs[i] : minx;
                maxx = (longs[i] > maxx) ? longs[i] : maxx;
                miny = (lats[i] < miny) ? lats[i] : miny;
                maxy = (lats[i] > maxy) ? lats[i] : maxy;
            }

            extent = new WebExtent();

            extent.setSpatialReference(m_geometry.getSpatialReference());

            extent.setMaxX(maxx);
            extent.setMaxY(maxy);
            extent.setMinX(minx);
            extent.setMinY(miny);

            map.setCurrentExtent(extent);
            m_context.refresh();
        }
    }

    /**
     * Action method to highlight the geographic location of the Gazetteer
     * record stored in {@link #m_geometry}.
     */
    public void highlight() {
        WebQuery webQuery = null;

        webQuery = m_context.getWebQuery();

        if (!webQuery.containsDisplayGeometry(m_geometry)) {
            webQuery.addDisplayGeometry(m_geometry);
        }
    }

    /**
     * Action method to clear the highlighted geographic location of the
     * Gazetteer record stored in {@link #m_geometry}.
     */
    public void clearGraphic() {
        m_context.getWebQuery().clearGraphic(m_geometry);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -