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

📄 selectbyfeaturebuffertask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }

    /**
     * Get target layer list
     */
    public Map<String, String> getTargetLayerList() {
        return this.targetLayerList;
    }

    /**
     * Get unit list
     */
    public Map<Integer, String> getUnitList() {
        this.unitList = GeomUtil.getUnitList();

        return this.unitList;
    }

    /**
     * Get update list
     */
    public void updateList(TaskEvent event) {
        _logger.info("Updating layer list");
        requestTaskRender();

        this.layerList = new LayerList(this.getContext());
    }

    /**
     * Get update target list
     */
    public void updateTargetList(TaskEvent event) {
        _logger.info("Updating layer target list");
        requestTaskRender();

        this.targetLayerList = new LayerList(this.getContext());
    }

    private WebGeometry bufferFeature(GISResource gisResource,
        WebGeometry geoOrigin, double dDistance) throws Exception {
        WebGeometry geoBuffer = null;

        //Calculating buffer
        IServerContextFactory ipSvrCtxFact = this.getServerContextFactor();
        IBufferCalculator bufferCalculator = BufferCalculatorFactory.createInstance(gisResource,
                ipSvrCtxFact);
        int iUnits = getUnit().intValue();

        geoBuffer = bufferCalculator.calculateBuffer(geoOrigin, dDistance,
                iUnits);

        return geoBuffer;
    }

    /**
     * Returns the layer name determined from the {@link GISResource} associated to the layer
     * and the ID of the layer.
     * @param resource {@link GISResource} the layer belongs to
     * @param lyrId ID of the layer
     * @return Layer name, or null if the name could not be determined
     */
    protected String getLayerNameFromId(GISResource resource, String lyrId) {
        String layerName = null;

        if (resource instanceof AIMSMapResource) {
            AIMSMapResource aimsMapResource = (AIMSMapResource) resource;
            AIMSMapFunctionality aimsMapFunc = (AIMSMapFunctionality) (aimsMapResource).getFunctionality(
                    "map");
            Layer aimsLayer = aimsMapFunc.getLayer(lyrId);
            layerName = aimsLayer.getName();
        }

        if (resource instanceof AGSMapResource) {
            AGSMapResource agsMapResource = (AGSMapResource) resource;
            AGSMapFunctionality agsMapFunc = (AGSMapFunctionality) (agsMapResource).getFunctionality(
                    "map");
            MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(Integer.parseInt(
                        lyrId));
            layerName = mapLayer.getName();
        }

        if (resource instanceof WFSMapResource) {
            WFSMapResource wfsMapResource = (WFSMapResource) resource;
            WFSWebLayerInfo wfsLayerInfo = wfsMapResource.getLayerInfoByIndex(Integer.parseInt(
                        lyrId));

            if (wfsLayerInfo != null) {
                layerName = wfsLayerInfo.getName();
            }
        }

        return layerName;
    }

    /**
     * Select point from the map to query feature(s) for buffering.
     */
    @SuppressWarnings("deprecation")
    private List<QueryResult> performQuery(WebContext webContext) {
        List<QueryResult> searchResults = null;

        try {
            WebQuery webQuery = webContext.getWebQuery();

            String layer = this.getLayer();
            String[] layerInfo = layer.split("!");

            double dist = 0;

            if ((getDistance() != null) && (getDistance().length() > 0)) {
                dist = Double.parseDouble(getDistance());
            }

            this.bufferGeom = null;

            LinkedHashMap<String, GISResource> resources = (LinkedHashMap<String, GISResource>) this._context.getResources();
            String id = layerInfo[0];
            Object resource = resources.get(id);
            GISResource gisResource = (GISResource) resource;
            String layerName = null;
            String lyrId = layerInfo[1];

            layerName = getLayerNameFromId(gisResource, lyrId);

            if (layerName == null) {
                renderResourceMessage(LAYER_NOT_FOUND);
                _logger.error("Layer name not found");

                return null;
            }

            WebSimplePolygonSymbol pSymbol = new WebSimplePolygonSymbol();
            pSymbol.setFillColor(FILL_COLOR);
            pSymbol.setFillTransparency(TRANSPARENCY_FACTOR);
            pSymbol.setBoundaryColor(FILL_COLOR);

            int tolerance = 0;

            if (queryGeometry instanceof WebPoint ||
                    queryGeometry instanceof WebPolyline) {
                tolerance = 5;
            }

            IdentifyCriteria iqc = new IdentifyCriteria(queryGeometry, tolerance);
            searchResults = webQuery.query(iqc,
                    WebLayerInfoUtil.getWebLayerInfoList(
                        webQuery.getQueryLayers(), (GISResource) resource, lyrId));

            // if the highlighter is set to clear the previous results,
            // clear the web graphics also
            if ((_highlighter == null) ||
                    _highlighter.getClearPreviousResults()) {
                _context.getWebGraphics().clearGraphics();
            }

            boolean isLocalAGS = false;

            if (searchResults.size() > 0) {
                QueryResult result = (QueryResult) searchResults.get(0);
                searchResults = new ArrayList<QueryResult>();
                searchResults.add(result);
                result.highlight();
                this.currentHighlighted = result;

                WebGeometry webGeom = result.getHighlightGeometry();
                WebSymbol webSym = null;

                if (webGeom instanceof WebPoint) {
                    WebSimpleMarkerSymbol ptSymbol = new WebSimpleMarkerSymbol();
                    ptSymbol.setColor(FILL_COLOR);
                    ptSymbol.setMarkerType(0);
                    ptSymbol.setWidth(5);
                    webSym = ptSymbol;
                }

                if (webGeom instanceof WebPolyline) {
                    WebSimpleLineSymbol lSymbol = new WebSimpleLineSymbol();
                    lSymbol.setColor(FILL_COLOR);
                    lSymbol.setWidth(3);
                    webSym = lSymbol;
                }

                if (webGeom instanceof WebPolygon) {
                    webSym = pSymbol;
                }

                GraphicElement graphicElem = new GraphicElement();
                graphicElem.setGeometry(webGeom);
                graphicElem.setSymbol(webSym);
                webContext.getWebGraphics().addGraphics(graphicElem);

                if (dist != 0) {
                    if (resource instanceof AGSMapResource) {
                        AGSMapResource agsMapResource = (AGSMapResource) resource;

                        if (agsMapResource instanceof AGSLocalMapResource) {
                            isLocalAGS = true;
                            this.bufferGeom = bufferFeature(gisResource,
                                    webGeom, dist);
                        }
                    }

                    if (resource instanceof AIMSMapResource || !isLocalAGS) {
                        this.bufferGeom = bufferFeature(gisResource, webGeom,
                                dist);
                    }
                } else {
                    this.bufferGeom = webGeom;
                }
            }

            webQuery.destroy();

            if (this.bufferGeom == null) {
                renderMessage(TextResources.getResourceString(NO_RECORD_MESSAGE));

                return null;
            }

            webQuery = (WebQuery) webContext.getWebQuery();

            GraphicElement graphicElem = new GraphicElement();
            graphicElem.setGeometry(this.bufferGeom);
            graphicElem.setSymbol(pSymbol);
            webContext.getWebGraphics().addGraphics(graphicElem);

            this.highlightResults(searchResults);
        } catch (Exception e) {
            renderExceptionMessage(e);
            _logger.error("Unable to do query", e);
        }

        return searchResults;
    }

    /**
     * Show intersecting features
     */
    public void showIntersectingFeatures(TaskEvent event) {
        try {
            _logger.info("Querying features that intersect with buffer");
            super.requestTaskRender();

            performQuery(event.getWebContext());

            if (this.bufferGeom == null) {
                return;
            }

            WebResults webResults = this._context.getWebResults();
            WebQuery webQuery = this._context.getWebQuery();
            LinkedHashMap<String, GISResource> resources = (LinkedHashMap<String, GISResource>) this._context.getResources();
            String session_id = ADFDownloadServlet.generateId();
            String targetLayer = this.getTargetLayer();
            String[] targetLayerInfo = targetLayer.split("!");
            String targetId = targetLayerInfo[0];
            Object targetResource = resources.get(targetId);
            Object resource = resources.get(targetId);
            String targetLyrId = targetLayerInfo[1];

            List<QueryResult> searchResults = null;

            if (targetResource instanceof AIMSMapResource) {
                // ADF Bug, it can't do the Identify with the WebPolygon. Below uses AIMS API to perform the query
                AIMSMapResource aimsMapResource = (AIMSMapResource) targetResource;
                AIMSMapFunctionality aimsMapFunc = (AIMSMapFunctionality) (aimsMapResource).getFunctionality(
                        "map");

                //				Layer aimsLayer = aimsMapFunc.getLayer(targetLyrId);
                AimsBufferUtil bufUtil = new AimsBufferUtil();
                String aimsWhereClause = bufUtil.doBuffer(session_id,
                        aimsMapResource, aimsMapFunc, targetLyrId,
                        this.bufferGeom);
                bufUtil = null;

                PredefinedQueryCriteria pqc = new PredefinedQueryCriteria();
                pqc.setWhereClause(aimsWhereClause);
                searchResults = webQuery.query(pqc,
                        WebLayerInfoUtil.getWebLayerInfoList(
                            webQuery.getQueryLayers(), (GISResource) resource,
                            targetLyrId));
            } else {
                IdentifyCriteria iqc = new IdentifyCriteria(this.bufferGeom);
                iqc.setMaxRecordCount(MAX_RECORDS);
                searchResults = webQuery.query(iqc,
                        WebLayerInfoUtil.getWebLayerInfoList(
                            webQuery.getQueryLayers(), (GISResource) resource,
                            targetLyrId));
            }

            if ((searchResults == null) || (searchResults.size() == 0)) {
                this.renderMessage(TextResources.getResourceString(
                        NO_RECORD_MESSAGE));

                return;
            }

            this.highlightResults(searchResults);
            webResults.addResultsWithActionMap("Point Buffer Task",
                searchResults, "getName", "getDetails", _actions, "clearGraphic");
        } catch (Exception e) {
            renderExceptionMessage(e);
            _logger.error("Unable to show intersecting features", e);
        }
    }

    /**
     * Select point from the map to query feature(s) for buffering.
     */
    public void selectPoint(MapEvent event) {
        try {
            _logger.info("Selecting map buffer point");
            requestTaskRender();

            WebContext webContext = event.getWebContext();
            WebMap webMap = event.getWebContext().getWebMap();
            WebGeometry webGeo = event.getWebGeometry();
            WebPoint webPoint = (WebPoint) webGeo.toMapGeometry(webMap);
            queryGeometry = (WebGeometry) webPoint;

            List<QueryResult> searchResults = performQuery(event.getWebContext());

            WebResults webResults = webContext.getWebResults();
            webResults.addResultsWithActionMap("Feature Buffer Task",
                searchResults, "getName", "getDetails", _actions, "clearGraphic");
        } catch (Exception e) {
            renderExceptionMessage(e);
            _logger.error("Unable to select point", e);
        }
    }

    /**
     * Select polygon
     */
    public void selectPolygon(MapEvent event) {
        try {
            _logger.info("Selecting polygon on map");
            super.requestTaskRender();

            WebContext webContext = event.getWebContext();
            WebMap webMap = event.getWebContext().getWebMap();
            WebGeometry webGeo = event.getWebGeometry();
            WebExtent ext = (WebExtent) webGeo.toMapGeometry(webMap);

            com.esri.solutions.jitk.web.data.geometry.WebExtent mvsWebExtent = new com.esri.solutions.jitk.web.data.geometry.WebExtent(ext);

            WebPolygon wp = mvsWebExtent.toWebPolygon();

            queryGeometry = (WebGeometry) wp;

            List<QueryResult> searchResults = performQuery(webContext);

            WebResults webResults = webContext.getWebResults();
            webResults.addResultsWithActionMap("Feature Buffer Task",
                searchResults, "getName", "getDetails", _actions, "clearGraphic");
        } catch (Exception e) {
            renderExceptionMessage(e);
            _logger.error("Unable to select polygon", e);
        }
    }

    /**
     * Clear buffer
     */
    public void clearBuffer(TaskEvent event) {
        try {
            _logger.info("Clearing buffer graphics");
            requestTaskRender();

            this.queryGeometry = null;
            this._context.getWebGraphics().clearGraphics();
            this._context.getWebQuery().clearGraphics();
            this.bufferGeom = null;
            this.currentHighlighted = null;
            this._context.refresh();
        } catch (Exception e) {
            renderExceptionMessage(e);
            _logger.error("Unable to clear buffer", e);
        }
    }

    /**
     * Update selected layer list
     */
    @SuppressWarnings("unused")
    public void doSelectLayer(TaskEvent event) {
        _logger.info("Updating selected layer list");
        super.requestTaskRender();

        String layer = this.getLayer();
    }

    /**
     * Get highlighted feature
     */
    public QueryResult getCurrentHighlighted() {
        return currentHighlighted;
    }

    /**
     * Set highlighted feature
     */
    public void setCurrentHighlighted(QueryResult currentHighlighted) {
        this.currentHighlighted = currentHighlighted;
    }
}

⌨️ 快捷键说明

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