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

📄 wmscontentaction.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                } catch (FactoryException e) {
                                    // TODO Add Action Errors
                                    return mapping.findForward("config.wms.content");
                                }

                                ReferencedEnvelope newEnvelope = new ReferencedEnvelope(dstCRS);
                                newEnvelope.init(selectedEnvelope.getLowerCorner().getOrdinate(0),
                                    selectedEnvelope.getUpperCorner().getOrdinate(0),
                                    selectedEnvelope.getLowerCorner().getOrdinate(1),
                                    selectedEnvelope.getUpperCorner().getOrdinate(1));

                                newEnvelope.expandToInclude(cvEnvelope);

                                selectedEnvelope = new GeneralEnvelope(new double[] {
                                            newEnvelope.getMinX(), newEnvelope.getMinY()
                                        },
                                        new double[] { newEnvelope.getMaxX(), newEnvelope.getMaxY() });
                                selectedEnvelope.setCoordinateReferenceSystem(dstCRS);
                            }
                        }
                    }
                }

                if (selectedEnvelope != null) {
                    envelope.setCoordinateReferenceSystem(selectedEnvelope
                        .getCoordinateReferenceSystem());
                    envelope.setEnvelope(selectedEnvelope);
                    envelopeMap.put(baseMapTitle, envelope);
                    contentForm.setBaseMapEnvelope(selectedLayerIndex, envelope);
                }
            }
        }

        if (selectedLayerIndex < 0) {
            return mapping.findForward("config.wms.content");
        }

        /*config.setBaseMapLayers(layerMap);
        config.setBaseMapStyles(styleMap);
        config.setBaseMapEnvelopes(envelopeMap);*/
        return mapping.findForward("config.wms.content");
    }

    private ActionForward executeRemoveLayerGroup(ActionMapping mapping, String action,
        WMSContentForm contentForm, WMSConfig config, HttpServletRequest request,
        HttpServletResponse response) {
        HashMap layerMap = new HashMap();
        HashMap styleMap = new HashMap();
        HashMap envelopeMap = new HashMap();

        int removedLayerIndex = contentForm.getSelectedLayer();

        if (removedLayerIndex < 0) {
            return mapping.findForward("config.wms.content");
        }

        contentForm.getBaseMapTitles().remove(removedLayerIndex);
        contentForm.getBaseMapLayers().remove(removedLayerIndex);
        contentForm.getBaseMapStyles().remove(removedLayerIndex);
        contentForm.getBaseMapEnvelopes().remove(removedLayerIndex);
        contentForm.getMinCPs().remove(new Integer(removedLayerIndex));
        contentForm.getMaxCPs().remove(new Integer(removedLayerIndex));

        int bmi = 0;
        for (Iterator it = contentForm.getBaseMapTitles().iterator(); it.hasNext();) {
			String baseMapTitle = (String) it.next();

			String baseMapLayers = (String) contentForm.getBaseMapLayers().get(bmi);
			String baseMapStyles = (String) contentForm.getBaseMapStyles().get(bmi);
			GeneralEnvelope envelope = (GeneralEnvelope) contentForm.getBaseMapEnvelopes().get(bmi);

			/*
			 * System.out.println("******************* contentAction: title=" +
			 * baseMapTitle + ", layers=" + baseMapLayers + ", styles=" +
			 * baseMapStyles);
			 */
			layerMap.put(baseMapTitle, baseMapLayers);
			styleMap.put(baseMapTitle, baseMapStyles);
			envelopeMap.put(baseMapTitle, envelope);

			bmi++;
		}

        config.setBaseMapLayers(layerMap);
        config.setBaseMapStyles(styleMap);
        config.setBaseMapEnvelopes(envelopeMap);

        return mapping.findForward("config.wms.content");
    }

    private ActionForward executeAddNewLayerGroup(ActionMapping mapping, String action,
        WMSContentForm contentForm, WMSConfig config, HttpServletRequest request,
        HttpServletResponse response) throws ServletException {
        HashMap layerMap = new HashMap();
        HashMap styleMap = new HashMap();
        HashMap envelopeMap = new HashMap();

        int bmi;
        Iterator it;

        for (bmi = 0, it = contentForm.getBaseMapTitles().iterator(); it.hasNext(); bmi++) {
            String baseMapTitle = (String) it.next();
            String baseMapLayers = (String) contentForm.getBaseMapLayers().get(bmi);
            String baseMapStyles = (String) contentForm.getBaseMapStyles().get(bmi);

            GeneralEnvelope envelope = (GeneralEnvelope) contentForm.getBaseMapEnvelopes().get(bmi);

            /*
                         * System.out.println("******************* contentAction: title=" +
                         * baseMapTitle + ", layers=" + baseMapLayers + ", styles=" +
                         * baseMapStyles);
                         */
            layerMap.put(baseMapTitle, baseMapLayers);
            styleMap.put(baseMapTitle, baseMapStyles);
            envelopeMap.put(baseMapTitle, envelope);
        }

        String name = "<new_layer_group>";
        int num = 2;

        while ((config.getBaseMapLayers() != null) && (config.getBaseMapLayers().get(name) != null)) {
            name = "<new_layer_group" + num + ">";
            num++;
        }

        GeneralEnvelope defaultEnvelope = new GeneralEnvelope(new double[] { -180.0, -90.0 },
                new double[] { 180.0, 90.0 });

        try {
            defaultEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326"));
        } catch (NoSuchAuthorityCodeException e) {
            throw new ServletException(e);
        } catch (FactoryException e) {
            throw new ServletException(e);
        }

        layerMap.put(name, "");
        styleMap.put(name, "");
        envelopeMap.put(name, defaultEnvelope);

        contentForm.getBaseMapTitles().add(name);
        contentForm.getBaseMapLayers().add("");
        contentForm.getBaseMapStyles().add("");
        contentForm.getBaseMapEnvelopes().add(defaultEnvelope);

        config.setBaseMapLayers(layerMap);
        config.setBaseMapStyles(styleMap);
        config.setBaseMapEnvelopes(envelopeMap);

        return mapping.findForward("config.wms.content");
    }

    private ActionForward executeSubmit(ActionMapping mapping, String action,
            WMSContentForm contentForm, WMSConfig config, HttpServletRequest request,
            HttpServletResponse response) {
            HashMap layerMap = new HashMap();
            HashMap styleMap = new HashMap();
            HashMap envelopeMap = new HashMap();

            int bmi;
            Iterator it;

            for (bmi = 0, it = contentForm.getBaseMapTitles().iterator(); it.hasNext(); bmi++) {
                String baseMapTitle = (String) it.next();
                String baseMapLayers = (String) contentForm.getBaseMapLayers().get(bmi);
                String baseMapStyles = (String) contentForm.getBaseMapStyles().get(bmi);
                GeneralEnvelope envelope = (GeneralEnvelope) contentForm.getBaseMapEnvelopes().get(bmi);

                /*System.out.println("******************* contentAction: title=" + baseMapTitle + ", layers="
                + baseMapLayers + ", styles=" + baseMapStyles);*/
                Data catalog = (Data) getServlet().getServletContext()
                                          .getAttribute(Data.WEB_CONTAINER_KEY);

                GeneralEnvelope selectedEnvelope = null;
                String[] layerNames = baseMapLayers.split(",");
                String[] styles = baseMapStyles.split("\\s*,\\s*");

                for (int i = 0; i < layerNames.length; i++) {
                    String layerName = layerNames[i].trim();

                    Integer layerType = (Integer) catalog.getLayerType(layerName);

                    if (layerType == null) {
                        ActionErrors errors = new ActionErrors();
                        errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("errors.invalid", new ActionMessage("Layer " + layerName)));
                        saveErrors(request, errors);

                        return mapping.findForward("config.wms.content");
                    }
                }

                for (int i = 0; i < styles.length; i++) {
                    String styleName = styles[i].trim();

                    Style style = catalog.getStyle(styleName);

                    if ((style == null) && !"".equals(styleName)) {
                        ActionErrors errors = new ActionErrors();
                        errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("error.styleId.notFound", new ActionMessage(styleName)));
                        saveErrors(request, errors);

                        return mapping.findForward("config.wms.content");
                    }
                }

                layerMap.put(baseMapTitle, baseMapLayers);
                styleMap.put(baseMapTitle, baseMapStyles);
                envelopeMap.put(baseMapTitle, envelope);
            }

            config.setBaseMapLayers(layerMap);
            config.setBaseMapStyles(styleMap);
            config.setBaseMapEnvelopes(envelopeMap);

            getApplicationState().notifyConfigChanged();

            return mapping.findForward("config");
        }
}

⌨️ 快捷键说明

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