Package com.bbn.openmap.proj

Examples of com.bbn.openmap.proj.Proj


     * @return byte[] representing an SVG of the map in it's current
     *         state.
     */
    public byte[] getImageFromMapBean(com.bbn.openmap.MapBean map) {

        Proj proj = (Proj) map.getProjection();
        java.awt.Graphics graphics = getGraphics(proj.getWidth(),
                proj.getHeight());

        // This should actually be getting the layers, and rendering
        // each one. It turns out that calling paintChildren() will
        // render a buffered image if the MapBean is buffered, and
        // that's not what we really want here.
        //      map.paintChildren(graphics);

        map.addPropertyChangeListener(this);

        // Layers should be set...
        proj.drawBackground((Graphics2D) graphics, map.getBckgrnd());

        if (layers != null) {
            for (int i = layers.length - 1; i >= 0; i--) {
                layers[i].renderDataForProjection(proj, graphics);
            }
View Full Code Here


     * @return byte[] of formatted image.
     */
    public byte[] handleMapRequest(Properties requestProperties)
            throws IOException, MapRequestFormatException {

        Proj projection = ImageServerUtils.createOMProjection(requestProperties,
                defaultProjection);

        // Old way, bad, bad. Can't set the background for the whole image
        // server for one request, it wacks the default.

View Full Code Here

     * 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);
    }
View Full Code Here

     */
    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);
    }
View Full Code Here

     * properties.
     *
     * @param mapBean
     */
    public void updateWithParameters(MapBean mapBean) {
        Proj projection = (Proj) mapBean.getProjection();
        Object suggested = getSuggested(PROJECTION_TYPE);
        if (suggested instanceof Class && suggested != projection.getClass()) {
            LatLonPoint center = projection.getCenter();
            projection = (Proj) ProjectionFactory.makeProjection((Class) suggested,
                    center.getLatitude(),
                    center.getLongitude(),
                    projection.getScale(),
                    projection.getWidth(),
                    projection.getHeight());
        }

        suggested = getSuggested(CENTER);
        if (suggested instanceof LatLonPoint) {
            projection.setCenter((LatLonPoint) suggested);
        }

        suggested = getSuggested(SCALE);
        if (suggested instanceof Number) {
            projection.setScale(((Number) suggested).floatValue());
        }

        mapBean.setProjection(projection);
    }
View Full Code Here

                || point2 == null)
            return;

        MapBean map = (MapBean) obj;
        Projection projection = map.getProjection();
        Proj p = (Proj) projection;

        synchronized (this) {
            point2 = getRatioPoint((MapBean) e.getSource(),
                    point1,
                    e.getPoint());
            int dx = Math.abs(point2.x - point1.x);
            int dy = Math.abs(point2.y - point1.y);

            // Don't bother redrawing if the rectangle is too small
            if ((dx < 5) || (dy < 5)) {
                // clean up the rectangle, since point2 has the old
                // value.
                paintRectangle(map, point1, point2);

                // If rectangle is too small in both x and y then
                // recenter the map
                if ((dx < 5) && (dy < 5)) {
                    LatLonPoint llp = projection.inverse(e.getPoint());

                    boolean shift = e.isShiftDown();
                    boolean control = e.isControlDown();

                    if (control) {
                        if (shift) {
                            p.setScale(p.getScale() * 2.0f);
                        } else {
                            p.setScale(p.getScale() / 2.0f);
                        }
                    }

                    // reset the points here so the point doesn't get
                    // rendered on the repaint.
                    point1 = null;
                    point2 = null;

                    p.setCenter(llp);
                    map.setProjection(p);
                }
                return;
            }

            // Figure out the new scale
            float newScale = com.bbn.openmap.proj.ProjMath.getScale(point1,
                    point2,
                    projection);

            // Figure out the center of the rectangle
            int centerx = Math.min(point1.x, point2.x) + dx / 2;
            int centery = Math.min(point1.y, point2.y) + dy / 2;
            com.bbn.openmap.LatLonPoint center = projection.inverse(centerx,
                    centery);

            // Fire events on main map to change view to match rect1
            // Debug.output("point1: " +point1);
            // Debug.output("point2: " +point2);
            // Debug.output("Centerx: " +centerx +
            // " Centery: " + centery);
            // Debug.output("New Scale: " + newScale);
            // Debug.output("New Center: " +center);

            // Set the parameters of the projection and then set
            // the projection of the map. This way we save having
            // the MapBean fire two ProjectionEvents.
            p.setScale(newScale);
            p.setCenter(center);

            // reset the points here so the point doesn't get rendered
            // on the repaint.
            point1 = null;
            point2 = null;
View Full Code Here

                                      boolean scaleImage) {
        if (map == null) {
            return new byte[0];
        }

        Proj proj = (Proj) map.getProjection();

        boolean needToScale = (width != proj.getWidth() || height != proj.getHeight());

        if (Debug.debugging("formatter")) {
            Debug.output("AIF: called with w:" + width + ", h:" + height
                    + ", need to scale (" + needToScale + ")"
                    + " and scaleImage (" + scaleImage + ")");
        }

        if (width == -1)
            width = proj.getWidth();
        if (height == -1)
            height = proj.getHeight();

        Graphics graphics = getGraphics(width, height);

        if (!needToScale) {
            if (Debug.debugging("formatter")) {
                Debug.output("AIF: don't need to scale, painting normally.");
            }
            // This way just paints what the MapBean is displaying.
            map.paintAll(graphics);
        } else {
            // One problem with this approach is that it will
            // use the ProjectionPainter interface on the layers. So,
            // you may not get the same image that is on the map. All
            // layers on the map will get painted in the image - so if
            // a layer hasn't painted itself on the map window, you
            // will see it in the image.

            // This lets us know what the layers are
            map.addPropertyChangeListener(this);

            // Layers should be set...
            com.bbn.openmap.LatLonPoint cp = new com.bbn.openmap.LatLonPoint(map.getCenter());

            double scaleMod = 1f;// scale factor for image scale
            // If we need to scale the image,
            // figure out the scale factor.
            if (scaleImage) {
                if (Debug.debugging("formatter")) {
                    Debug.output("AIF: scaling image to w:" + width + ", h:"
                            + height);
                }
                double area1 = (double) proj.getHeight()
                        * (double) proj.getWidth();
                double area2 = (double) height * (double) width;
                scaleMod = Math.sqrt(area1 / area2);
            }

            Proj tp = (Proj) com.bbn.openmap.proj.ProjectionFactory.makeProjection(map.getProjection()
                    .getClass(),
                    cp.getLatitude(),
                    cp.getLongitude(),
                    map.getScale() * (float) scaleMod,
                    width,
                    height);

            tp.drawBackground((Graphics2D) graphics, map.getBckgrnd());

            if (layers != null) {
                for (int i = layers.length - 1; i >= 0; i--) {
                    Projection oldProj = layers[i].getProjection();
                    layers[i].renderDataForProjection(tp, graphics);
View Full Code Here

        checkBackground(requestProperties, parameters);
        Paint bgPaint = parameters.background;

        checkProjectionType(requestProperties, parameters);
        checkBoundingBox(requestProperties, parameters);
        Proj projection = createProjection(requestProperties, parameters);
       
        checkLayersAndStyles(requestProperties, parameters);

        Debug.message("ms", "handleGetMapRequest: createImage layers:" + parameters.topLayerNames.toString());
        return createImage(projection, parameters.width, parameters.height, parameters.topLayerNames, bgPaint);
View Full Code Here

       
        checkLayersAndStyles(requestProperties, parameters);
        checkQueryLayers(requestProperties, parameters);
        checkInfoFormat(requestProperties, parameters);

        Proj projection = createProjection(requestProperties, parameters);
       
        // TODO: get a user defined FeatureInfoResponse
        FeatureInfoResponse featureInfoResponse = null;
        if (featureInfoResponse == null) {
            // TODO: log that user defined was not found
View Full Code Here

        Properties projProps = new Properties();
        projProps.put(ProjectionFactory.CENTER, new LatLonPoint(0f, 0f));
        projProps.setProperty(ProjectionFactory.WIDTH, Integer.toString(parameters.width));
        projProps.setProperty(ProjectionFactory.HEIGHT, Integer.toString(parameters.height));
       
        Proj projection = parameters.crs.createProjection(projProps);
        parameters.crs.prepareProjection(projection);
        projection.setScale(projection.getMinScale());

        LatLonPoint llp1 = parameters.bboxLatLonMinXY;
        LatLonPoint llp2 = parameters.bboxLatLonMaxXY;
        System.out.println("bbox toLatLon: 1: " + llp1 + ", 2: " + llp2 + ", center: " + parameters.bboxLatLonCenter);
       
        // guess a center value
        // TODO: calculate this from bbox values instead of after latlon converting?
        //float centerLat = ((llp2.getLatitude() - llp1.getLatitude()) / 2) + llp1.getLatitude();
        //float centerLon = ((llp2.getLongitude() - llp1.getLongitude()) / 2) + llp1.getLongitude();
        //projection.setCenter(centerLat, centerLon);
        projection.setCenter(parameters.bboxLatLonCenter);
       
        // Debug.output("L1: " + llp1.toString()+", L2: " + llp2.toString();
        // TODO: need to set projection.center before using the projection

        int intnewwidth = parameters.width;
        int intnewheight = parameters.height;
       
        float newscale = projection.getScale(llp1, llp2, new Point(0, 0), new Point(intnewwidth,
                intnewheight));
        projection.setScale(newscale);

        // OGC 01-068r3 (wms 1.1.1) 7.2.3.8. "In the case where the aspect ratio
        // of the BBOX and the ratio width/height are different, the WMS shall
        // stretch the returned map so that the resulting
        // pixels could themselves be rendered in the aspect ratio of the BBOX"
        Point xyp1 = projection.forward(llp1);
        Point xyp2 = projection.forward(llp2);
        int w = xyp2.x - xyp1.x;
        int h = xyp1.y - xyp2.y;
        if (Math.abs(w - parameters.width) > 2 || Math.abs(h - parameters.height) > 2) {
            Debug.output("use aspect ratio fix");
            projection.setWidth(w);
            projection.setHeight(h);
            projection.setCenter(parameters.bboxLatLonCenter);
            float underlyingScale = projection.getScale(llp1, llp2, new Point(0, 0),
                    new Point(w, h));
            projection.setScale(underlyingScale);
            AspectRatioProjection p = new AspectRatioProjection(projection, parameters.width,
                    parameters.height);
            projection = p;
        }
       
View Full Code Here

TOP

Related Classes of com.bbn.openmap.proj.Proj

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.