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

📄 maprequesthandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public byte[] handleRequest(String request) throws IOException,            MapRequestFormatException {        Properties requestProperties = convertRequestToProps(request);        String requestType = requestProperties.getProperty(REQUEST);        if (requestType != null) {            if (requestType.equalsIgnoreCase(MAP)) {                Debug.message("imageserver", "MRH: Map request...");                return handleMapRequest(requestProperties);                //          } else if                // (requestType.equalsIgnoreCase(CAPABILITIES)) {                //              Debug.message("imageserver", "MRH: Capabilities                // request...");                //              handleCapabilitiesRequest(requestProperties, out);            } else {                throw new MapRequestFormatException("Request type not handled: "                        + requestType);            }        } else {            throw new MapRequestFormatException("Request not understood: "                    + request);        }    }    /**     * Given a general request, parse it and handle it. Appends a     * content type to the output stream which may mess things up for     * servlets asking for images.     *      * @param request the request string of key value pairs.     * @param out OutputStream to reply on.     */    public void handleRequest(String request, OutputStream out)            throws IOException, MapRequestFormatException {        Properties requestProperties = convertRequestToProps(request);        String requestType = requestProperties.getProperty(REQUEST);        if (requestType != null) {            if (requestType.equalsIgnoreCase(MAP)) {                Debug.message("imageserver", "MRH: Map request...");                handleMapRequest(requestProperties, out);            } else if (requestType.equalsIgnoreCase(CAPABILITIES)) {                Debug.message("imageserver", "MRH: Capabilities request...");                handleCapabilitiesRequest(requestProperties, out);            } else if (requestType.equalsIgnoreCase(PAN)) {                Debug.message("imageserver", "MRH: Pan request...");                handlePanRequest(requestProperties, out);            } else if (requestType.equalsIgnoreCase(RECENTER)) {                Debug.message("imageserver", "MRH: Recenter request...");                handleRecenterRequest(requestProperties, out);            } else {                throw new MapRequestFormatException("Request type not handled: "                        + requestType);            }        } else {            throw new MapRequestFormatException("Request not understood: "                    + request);        }    }    /**     * Handle a map request, and create and image for it.     *      * @param requestProperties the request in properties format.     * @return byte[] of formatted image.     */    public byte[] handleMapRequest(Properties requestProperties)            throws IOException, MapRequestFormatException {        Proj projection = ImageServerUtils.createOMProjection(requestProperties,                defaultProjection);        setBackground(ImageServerUtils.getBackground(requestProperties));        boolean formatFound = false;        String format = requestProperties.getProperty(FORMAT);        if (format != null) {            formatFound = setFormatter(format.toUpperCase());            formatFound = true;            Debug.message("imageserver", "Format requested " + format);        }        if (Debug.debugging("imageserver")                && (format == null || formatFound == false)) {            Debug.output("MRH: no formatter defined, using default");        }        byte[] image;        // We need to think about using the layer mask, parsing it        // intelligently, and not using it if it's a little freaky.        //      String strLayerMask =        // requestProperties.getProperty(LAYERMASK);        //      // default is to show all the layers server knows about.        //      int layerMask = 0xFFFFFFFF;        //      if (strLayerMask != null) {        //          if (Debug.debugging("imageserver") {        //              Debug.output("MRH.handleMapRequest: LayerMask unsigned int        // is " +        //                           strLayerMask);        //          }        //          layerMask = Integer.parseInt(strLayerMask);        //      }        String strLayers = requestProperties.getProperty(LAYERS);        // Pass any properties to the layers??? Maybe if another        // property is set, to bother with taking up the time to run        // through all of this...        if (strLayers != null) {            Vector layers = PropUtils.parseMarkers(strLayers, ",");            if (Debug.debugging("imageserver")) {                Debug.output("MRH.handleMapRequest: requested layers >> "                        + layers);            }            image = createImage(projection, -1, -1, layers);        } else {            // if LAYERS property is not specified            // Check default layers or if visibility should be used to            // determine default            if (getUseVisibility()) {                if (Debug.debugging("imageserver")) {                    Debug.output("MRH.handleMapRequest: Using visibility to determine layers");                }                image = createImage(projection,                        -1,                        -1,                        calculateVisibleLayerMask());            } else {                Vector layers = PropUtils.parseMarkers(defaultLayers, " ");                if (Debug.debugging("imageserver")) {                    Debug.output("MRH.handleMapRequest: requested layers >> "                            + layers + " out of " + getAllLayerNames());                }                image = createImage(projection, -1, -1, layers);            }        }        return image;    }    /**     * Handle a Map Request. Appends a content type to the output     * stream which may mess things up for servlets.     */    public void handleMapRequest(Properties requestProperties, OutputStream out)            throws IOException, MapRequestFormatException {        byte[] image = handleMapRequest(requestProperties);        if (Debug.debugging("imageserver")) {            Debug.output("MRH: have completed image, size " + image.length);        }        String contentType = getFormatterContentType(getFormatter());        if (contentType == null) {            contentType = HttpConnection.CONTENT_PLAIN;        }        Debug.message("imageserver", "MRH: have type = " + contentType);        HttpConnection.writeHttpResponse(out, contentType, image);    }    /**     * Handle a Pan Request.     */    public void handlePanRequest(Properties requestProperties, OutputStream out)            throws IOException, MapRequestFormatException {        Proj projection = ImageServerUtils.createOMProjection(requestProperties,                defaultProjection);        String contentType = HttpConnection.CONTENT_PLAIN;        String response;        float panAzmth;        try {            panAzmth = Float.parseFloat(requestProperties.getProperty(AZIMUTH));            projection.pan(panAzmth);        } catch (Exception exc) {            Debug.output("MSH: Invalid Azimuth");        }        response = Math.round(projection.getCenter().getLatitude() * 100.0)                / 100.0 + ":"                + Math.round(projection.getCenter().getLongitude() * 100.0)                / 100.0;        HttpConnection.writeHttpResponse(out, contentType, response);    }    /**     * Handle a Recenter Request. Appends a content type to the output     * stream which may mess things up for servlets.     */    public void handleRecenterRequest(Properties requestProperties,                                      OutputStream out) throws IOException,            MapRequestFormatException {        Proj projection = ImageServerUtils.createOMProjection(requestProperties,                defaultProjection);        String contentType = HttpConnection.CONTENT_PLAIN;        ;        String response;        try {            int x = Integer.parseInt(requestProperties.getProperty(X));            int y = Integer.parseInt(requestProperties.getProperty(Y));            projection.setCenter(projection.inverse(x, y));        } catch (Exception exc) {            Debug.output("MSH: Invalid Azimuth");        }        response = Math.round(projection.getCenter().getLatitude() * 100.0)                / 100.0 + ":"                + Math.round(projection.getCenter().getLongitude() * 100.0)                / 100.0;        HttpConnection.writeHttpResponse(out, contentType, response);    }    /**     * Given an ImageFormatter, get the HttpConnection content type     * that matches it.     */    public String getFormatterContentType(ImageFormatter formatter) {        String ret = null;        String label = formatter.getFormatLabel();        String[] knownContentTypes = HttpConnection.getAllContentTypes();        for (int i = 0; i < knownContentTypes.length; i++) {            if (knownContentTypes[i].indexOf(label.toLowerCase()) != -1) {                ret = knownContentTypes[i];                break;            }        }        return ret;    }    /**     * Handle a capabilities request.     */    public void handleCapabilitiesRequest(Properties requestProperties,                                          OutputStream out) throws IOException,            MapRequestFormatException {        if (Debug.debugging("imageserver")) {            Debug.output("MRH.handleCapabilitiesRequest: unimplemented");        }        throw new MapRequestFormatException("Capabilities request currently not handled");    }}

⌨️ 快捷键说明

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