Package org.geoserver.wms

Examples of org.geoserver.wms.WMSMapContent


        final List<Rule> rules = getActiveRules(style, params.getScaleDenominator());
        if (rules.size() == 0) {
            return null;
        }
        GetMapRequest getMap = params.getGetMapRequest();
        WMSMapContent mc = new WMSMapContent(getMap);
        try {
            // prepare the fake web map content
            mc.setTransparent(true);
            mc.setBuffer(params.getBuffer());
            mc.getViewport().setBounds(new ReferencedEnvelope(getMap.getBbox(), getMap.getCrs()));
            mc.setMapWidth(getMap.getWidth());
            mc.setMapHeight(getMap.getHeight());
            FeatureLayer layer = getLayer(params, style);
            mc.addLayer(layer);
            // setup the env variables just like in the original GetMap
            RenderingVariables.setupEnvironmentVariables(mc);
           
            // setup the transformation from screen to world space
            AffineTransform worldToScreen = RendererUtilities.worldToScreenTransform(
                    params.getRequestedBounds(), new Rectangle(params.getWidth(), params.getHeight()));
            AffineTransform screenToWorld = worldToScreen.createInverse();
           
            // apply uom rescale on the rules
            rescaleRules(rules, params);
           
            // setup the area we are actually going to paint
            int radius = getSearchRadius(params, rules, layer, getMap, screenToWorld);
            if(radius < buffer) {
                radius = buffer;
            }
            Envelope targetRasterSpace = new Envelope(params.getX() - radius, params.getX() + radius,
                    params.getY() - radius, params.getY() + radius);
            Envelope targetModelSpace = JTS.transform(targetRasterSpace, new AffineTransform2D(screenToWorld));
           
            // prepare the image we are going to check rendering against
            int paintAreaSize = radius * 2 + 1;
            final BufferedImage image = ImageTypeSpecifier.createFromBufferedImageType(
                    BufferedImage.TYPE_INT_ARGB).createBufferedImage(paintAreaSize,
                    paintAreaSize);
            image.setAccelerationPriority(0);
   
            // and now the listener that will check for painted pixels
            int mid = radius;
            int hitAreaSize = buffer * 2 + 1;
            Rectangle hitArea = new Rectangle(mid - buffer, mid - buffer, hitAreaSize, hitAreaSize);
            final FeatureInfoRenderListener featureInfoListener = new FeatureInfoRenderListener(
                    image, hitArea, maxFeatures, params.getPropertyNames());

            // update the map context
            mc.getViewport().setBounds(new ReferencedEnvelope(targetModelSpace, getMap.getCrs()));
            mc.setMapWidth(paintAreaSize);
            mc.setMapHeight(paintAreaSize);
           
            // and now run the rendering _almost_ like a GetMap
            RenderedImageMapOutputFormat rim = new RenderedImageMapOutputFormat(wms) {
   
                private Graphics2D graphics;

                @Override
                protected RenderedImage prepareImage(int width, int height, IndexColorModel palette,
                        boolean transparent) {
                    return image;
                }

                @Override
                protected Graphics2D getGraphics(boolean transparent, Color bgColor,
                        RenderedImage preparedImage, Map<Key, Object> hintsMap) {
                    graphics = super.getGraphics(transparent, bgColor, preparedImage,
                            hintsMap);
                    return graphics;
                }
   
                @Override
                protected void onBeforeRender(StreamingRenderer renderer) {
                    // force the renderer into serial painting mode, as we need to check what
                    // was painted to decide which features to include in the results
                    Map hints = renderer.getRendererHints();
                    hints.put(StreamingRenderer.OPTIMIZE_FTS_RENDERING_KEY, Boolean.FALSE);
                    // disable antialiasing to speed up rendering
                    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
   
                    // TODO: should we disable the screenmap as well?
                    featureInfoListener.setGraphics(graphics);
                    featureInfoListener.setRenderer(renderer);
                    renderer.addRenderListener(featureInfoListener);
                }
            };
            rim.produceMap(mc);
           
            List<SimpleFeature> features = featureInfoListener.getFeatures();
            return aggregateByFeatureType(features);
        } finally {
            mc.dispose();
        }
    }
View Full Code Here


            super(handler, null, null);
        }

        public void encode(Object o) throws IllegalArgumentException {

            final WMSMapContent mapContent = (WMSMapContent) o;
            final GetMapRequest request = mapContent.getRequest();
            final List<Layer> layers = mapContent.layers();

            final KMLLookAt lookAtOpts = new KMLLookAt(request.getFormatOptions());
            // start("kml");
            start("kml",
                    KMLUtils.attributes(new String[] { "xmlns", "http://www.opengis.net/kml/2.2",
                            "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance",
                            "xsi:schemaLocation",
                            "http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd" }));

            // calculate scale denominator
            scaleDenominator = 1;
            try {
                scaleDenominator = RendererUtilities.calculateOGCScale(mapContent.getRenderingArea(),
                        mapContent.getMapWidth(), null);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Error calculating scale denominator", e);
            }
            LOGGER.log(Level.FINE, "scale denominator = " + scaleDenominator);

            // if we have more than one layer ( or a legend was requested ),
            // use the name "GeoServer" to group them
            boolean group;
            Boolean legend = (Boolean) request.getFormatOptions().get("legend");
            if (legend != null) {
                group = (layers.size() > 1) || legend.booleanValue();
            } else {
                group = (layers.size() > 1);
            }
           
            if (group) {
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < layers.size(); i++) {
                    sb.append(layers.get(i).getTitle() + ",");
                }
                sb.setLength(sb.length() - 1);

                start("Document");
                String kmltitle = (String) mapContent.getRequest().getFormatOptions().get("kmltitle");
                element("name", (kmltitle != null ? kmltitle : sb.toString()));
            }

            // for every layer specified in the request
            for (int i = 0; i < layers.size(); i++) {
                // layer and info
                Layer layer = layers.get(i);

                // was a super overlay requested?
                Boolean superoverlay = (Boolean) mapContent.getRequest().getFormatOptions()
                        .get("superoverlay");
                superoverlay = (superoverlay == null ? Boolean.FALSE : superoverlay);
                if (superoverlay) {
                    // encode as super overlay
                    encodeSuperOverlayLayer(mapContent, layer);
View Full Code Here

        public KMLNetworkLinkTranslator(ContentHandler contentHandler) {
            super(contentHandler, null, null);
        }

        public void encode(Object o) throws IllegalArgumentException {
            final WMSMapContent context = (WMSMapContent) o;
            final GetMapRequest request = context.getRequest();
            // restore target mime type for the network links
            if (NetworkLinkMapOutputFormat.KML_MIME_TYPE.equals(request.getFormat())) {
                request.setFormat(KMLMapOutputFormat.MIME_TYPE);
            } else {
                request.setFormat(KMZMapOutputFormat.MIME_TYPE);
View Full Code Here

        testData.setUpDefaultRasterLayers();
    }

    @Test
    public void testTileEntries() throws Exception {
        WMSMapContent mapContent = createMapContent(WORLD, LAKES);
        mapContent.getRequest().setBbox(
            new Envelope(-0.17578125, -0.087890625, 0.17578125, 0.087890625));
        mapContent.getRequest().getFormatOptions().put("min_zoom", "10");
        mapContent.getRequest().getFormatOptions().put("max_zoom", "11");
       
        WebMap map = format.produceMap(mapContent);
        GeoPackage geopkg = createGeoPackage(map);

        assertTrue(geopkg.features().isEmpty());
View Full Code Here

        return request;
    };
   
    WMSMapContent createMapContent(QName... layers) throws IOException {
        GetMapRequest mapRequest = createGetMapRequest(layers);
        WMSMapContent map = new WMSMapContent(mapRequest);
        for (QName l : layers) {
            map.addLayer(createMapLayer(l));
        }
        return map;
    }
View Full Code Here

        testData.setUpDefaultRasterLayers();
    }

    @Test
    public void testTileEntries() throws Exception {
        WMSMapContent mapContent = createMapContent(WORLD, LAKES);
        mapContent.getRequest().setBbox(
            new Envelope(-0.17578125, -0.087890625, 0.17578125, 0.087890625));
        mapContent.getRequest().getFormatOptions().put("min_zoom", "10");
        mapContent.getRequest().getFormatOptions().put("max_zoom", "11");
       
        WebMap map = format.produceMap(mapContent);
        MBTilesFile mbtiles = createMbTilesFiles(map);
       
        MBTilesMetadata metadata = mbtiles.loadMetaData();
View Full Code Here

    }
   
    @Test
    public void testTileEntriesWithAddTiles() throws Exception {
        // Create a getMap request
        WMSMapContent mapContent = createMapContent(WORLD, LAKES);
        mapContent.getRequest().setBbox(
            new Envelope(-0.17578125, -0.087890625, 0.17578125, 0.087890625));
        mapContent.getRequest().getFormatOptions().put("min_zoom", "10");
        mapContent.getRequest().getFormatOptions().put("max_zoom", "11");
        // Create a temporary file for the mbtiles
        File f = File.createTempFile("temp2", ".mbtiles", new File("target"));
        MBTilesFile mbtiles = new MBTilesFile(f);
        mbtiles.init();
        // Add tiles to the file(Internally uses the MBtilesFileWrapper)
        format.addTiles(mbtiles, mapContent.getRequest(), null);
        // Ensure everything is correct
        MBTilesMetadata metadata = mbtiles.loadMetaData();
       
        assertEquals("World_Lakes", metadata.getName());
        assertEquals("0", metadata.getVersion());
View Full Code Here

        return request;
    };
   
    WMSMapContent createMapContent(QName... layers) throws IOException {
        GetMapRequest mapRequest = createGetMapRequest(layers);
        WMSMapContent map = new WMSMapContent(mapRequest);
        for (QName l : layers) {
            map.addLayer(createMapLayer(l));
        }
        return map;
    }
View Full Code Here

            title = getTitle(lgi);
            description = getDescription(lgi);
            keywords = getKeyWords(lgi);
        }

        WMSMapContent context = new WMSMapContent(getMapRequest);
        context.setTitle(title);
        context.setAbstract(description);
        context.setKeywords(keywords);
        context.setMapWidth(getMapRequest.getWidth());
        context.setMapHeight(getMapRequest.getHeight());
        context.getViewport().setBounds((ReferencedEnvelope) getMapRequest.getBbox());

        MapContentWebMap webMap;
        try {
            webMap = (MapContentWebMap) new GetMap(wms).run(getMapRequest, context);
        } catch (Exception e) {
View Full Code Here

        String authorName = gsInfo.getSettings().getContact().getContactPerson();
        Author author = doc.createAndSetAtomAuthor();
        author.addToNameOrUriOrEmail(authorName);
        doc.createAndSetAtomLink(gsInfo.getSettings().getOnlineResource());
       
        WMSMapContent mapContent = encodingContext.getMapContent();
        doc.setDescription(buildDescription(mapContent));

        // see if we have to include sample data
        List<Layer> layers = mapContent.layers();
        boolean includeSampleData = false;
        for (int i = 0; i < layers.size(); i++) {
            // layer and info
            MapLayerInfo layerInfo = mapContent.getRequest().getLayers().get(i);
            final int type = layerInfo.getType();
            if (MapLayerInfo.TYPE_VECTOR == type || MapLayerInfo.TYPE_REMOTE_VECTOR == type) {
                includeSampleData = true;
            }
        }
View Full Code Here

TOP

Related Classes of org.geoserver.wms.WMSMapContent

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.