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

📄 zoomtoactionhandler.java

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

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.solutions.jitk.common.metadata.BasicMetadataExporter;


public class ZoomToActionHandler implements IActionHandler {
    private String _name = null;
    private WebContext _context = null;
    private WebGeometry _geometry = null;

    /**
     * Zooms the map to the {@link WebGeometry} of the CS/W
     * search result.
     */
    public void execute() {
        WebMap map = null;

        map = _context.getWebMap();

        if (_geometry instanceof WebPoint) {
            WebExtent extent = null;

            // there is a known bug in the core ADF's WebMap.centerAt()
            // method, the code below is a workaround
            map.centerAt((WebPoint) _geometry, 1.0d);

            extent = map.getCurrentExtent();
            extent.expand(0.5d);

            map.setCurrentExtent(extent);

            _context.refresh();
        } else if (_geometry instanceof WebPolygon) {
            double[] longs;
            double[] lats;
            double minx = 0D;
            double miny = 0D;
            double maxx = 0D;
            double maxy = 0D;
            WebPolygon polygon = (WebPolygon) _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.setMaxX(maxx);
            extent.setMaxY(maxy);
            extent.setMinX(minx);
            extent.setMinY(miny);

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

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#getActionKey()
     */
    public String getActionKey() {
        return _name;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#getName()
     */
    public String getName() {
        return _name;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#setName(java.lang.String)
     */
    public void setName(String name) {
        _name = name;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#shouldDisplay(com.esri.solutions.jitk.common.metadata.BasicMetadataExporter)
     */
    public boolean shouldDisplay(BasicMetadataExporter exporter) {
        return true;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#setWebContext(com.esri.adf.web.data.WebContext)
     */
    public void setWebContext(WebContext context) {
        _context = context;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.web.tasks.search.csw.actions.IActionHandler#setWebGeometry(com.esri.adf.web.data.geometry.WebGeometry)
     */
    public void setWebGeometry(WebGeometry geometry) {
        _geometry = geometry;
    }
}

⌨️ 快捷键说明

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