Package org.geotools.map

Examples of org.geotools.map.MapContext


        if ( crs == null )
        {
            crs = DefaultGeographicCRS.WGS84;
        }

        final MapContext context = new DefaultMapContext( crs );
        context.addLayer( featureSource, style );
        context.getLayerBounds();

        return context;
    }
View Full Code Here


     * @return an map context with generated test data.
     */
    public MapContext createExampleMap()
    {
        // TODO: Read up on Coordinate Reference System, and pass one to the constructor below:
        final MapContext exampleMap = new DefaultMapContext();

        // Some random height coverage data
        // TODO

        // Some random roads
        // TODO

        // Some random lakes and rivers
        // TODO

        // Some random cities containing building polygons
        // TODO

        // Some random coverage color (population density?)
        // TODO

        try
        {
            //AttributeType geom = AttributeTypeFactory.newAttributeType("the_geom", Point.class);
            AttributeType geom = AttributeTypeFactory.newAttributeType( "the_geom", LineString.class );
            AttributeType roadWidth = AttributeTypeFactory.newAttributeType( "width", Float.class );
            FeatureType ftRoad = FeatureTypes.newFeatureType( new AttributeType[]{ geom, roadWidth }, "road" );

            WKTReader wktReader = new WKTReader();
            //Point geometry = (Point) wktReader.read("POINT (" + lat + " " + lon + ")");
            LineString geometry = (LineString) wktReader.read( "LINESTRING (0 0, 10 10, 10 20, 20 30, 10 40, 15 50)" );
            Float width = new Float( 10 );
            Feature theRoad = ftRoad.create( new Object[]{ geometry, width }, "myRoad" );

            System.out.println( theRoad );

            final FeatureCollection featureCollection = new DefaultFeatureCollection( "roads", ftRoad );

            featureCollection.add( theRoad );

            exampleMap.addLayer( new DefaultMapLayer( featureCollection, new BasicLineStyle() ) );

            System.out.println( "exampleMap = " + exampleMap );
        }
        catch ( SchemaException e )
        {
View Full Code Here

        final Show2DMapSpike mapViewer = new Show2DMapSpike();

        //MapContext context = loadMapContextFromCommandLine( args, mapViewer );

        final ExampleDataGenerator exampleDataGenerator = new ExampleDataGenerator();
        final MapContext context = exampleDataGenerator.createExampleMap();

        mapViewer.setMapContext( context );
    }
View Full Code Here

    }

    private static MapContext loadMapContextFromCommandLine( final String[] args, final Show2DMapSpike mapViewer )
            throws Exception
    {
        MapContext context = null;
        if ( args.length == 0 || !args[ 0 ].toLowerCase().endsWith( ".shp" ) )
        {
            System.out.println( "java org.geotools.gui.swing.MapViewer shapefile.shp" );
            System.out.println( "Notes:" );
            System.out.println( " Any provided shapefile.prj file or shapefile.sld will be used" );
View Full Code Here

        CoordinateReferenceSystem crs = fs.getSchema().getDefaultGeometry().getCoordinateSystem();
        if ( crs == null )
        {
            crs = DefaultGeographicCRS.WGS84;
        }
        MapContext context = new DefaultMapContext( crs );
        context.addLayer( fs, style[ 0 ] );

        context.getLayerBounds();
        return context;

    }
View Full Code Here

        CoordinateReferenceSystem crs = fs.getSchema().getDefaultGeometry().getCoordinateSystem();
        if ( crs == null )
        {
            crs = DefaultGeographicCRS.WGS84;
        }
        MapContext context = new DefaultMapContext( crs );
        context.addLayer( fs, style[ 0 ] );

        context.getLayerBounds();
        return context;
    }
View Full Code Here

    public void createMapFor(final CoordinateReferenceSystem crs,
            final com.vividsolutions.jts.geom.Envelope areaOfInterest, final Graphics2D graphics)
            throws IOException {

        Geometry geographicBoundingBox = getGeographicBoundingBox(crs);
        MapContext mapContext = getMapContext(crs, geographicBoundingBox, areaOfInterest);

        graphics.setColor(new Color(153, 179, 204));
        graphics.fillRect(0, 0, mapWidth, mapHeight);

        Rectangle paintArea = new Rectangle(mapWidth, mapHeight);

        mapContext.setAreaOfInterest(areaOfInterest, crs);

        GTRenderer renderer = new StreamingRenderer();
        renderer.setContext(mapContext);
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
View Full Code Here

                    continue;
                }
            }

            final MapLayer layer = layers[i];
            MapContext map = this.mapContext;
            map.clearLayerList();
            map.addLayer(layer);

            final int width = this.mapContext.getMapWidth();
            final int height = this.mapContext.getMapHeight();

            LOGGER.fine(new StringBuffer("setting up ").append(width).append("x").append(height)
                                                       .append(" image").toString());

            // simone: ARGB should be much better
            BufferedImage curImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);

            // simboss: this should help out with coverages
            final Graphics2D graphic = GraphicsJAI.createGraphicsJAI(curImage.createGraphics(), null);

            LOGGER.fine("setting to transparent");

            int type = AlphaComposite.SRC;
            graphic.setComposite(AlphaComposite.getInstance(type));

            Color c = new Color(this.mapContext.getBgColor().getRed(),
                    this.mapContext.getBgColor().getGreen(),
                    this.mapContext.getBgColor().getBlue(), 0);

            //LOGGER.info("****** bg color: "+c.getRed()+","+c.getGreen()+","+c.getBlue()+","+c.getAlpha()+", trans: "+c.getTransparency());
            graphic.setBackground(this.mapContext.getBgColor());
            graphic.setColor(c);
            graphic.fillRect(0, 0, width, height);

            type = AlphaComposite.SRC_OVER;
            graphic.setComposite(AlphaComposite.getInstance(type));

            Rectangle paintArea = new Rectangle(width, height);

            final StreamingRenderer renderer = new StreamingRenderer();
            renderer.setContext(map);

            RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            renderer.setJava2DHints(hints);

            // we already do everything that the optimized data loading does...
            // if we set it to true then it does it all twice...
            Map rendererParams = new HashMap();
            rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
            rendererParams.put("renderingBuffer", new Integer(mapContext.getBuffer()));
            renderer.setRendererHints(rendererParams);

            Envelope dataArea = map.getAreaOfInterest();
            AffineTransform at = RendererUtilities.worldToScreenTransform(dataArea, paintArea);
            renderer.paint(graphic, paintArea, dataArea, at);
            graphic.dispose();

            // /////////////////////////////////////////////////////////////////
View Full Code Here

    public void createMapFor(final CoordinateReferenceSystem crs,
            final com.vividsolutions.jts.geom.Envelope areaOfInterest, final Graphics2D graphics)
            throws IOException {

        Geometry geographicBoundingBox = getGeographicBoundingBox(crs);
        MapContext mapContent = getMapContext(crs, geographicBoundingBox, areaOfInterest);

        graphics.setColor(new Color(153, 179, 204));
        graphics.fillRect(0, 0, mapWidth, mapHeight);

        Rectangle paintArea = new Rectangle(mapWidth, mapHeight);

        mapContent.setAreaOfInterest(areaOfInterest, crs);

        GTRenderer renderer = new StreamingRenderer();
        renderer.setContext(mapContent);
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        renderer.setJava2DHints(hints);

        Map renderingHints = new HashMap();
        renderingHints.put("optimizedDataLoadingEnabled", Boolean.TRUE);
        renderingHints.put(StreamingRenderer.ADVANCED_PROJECTION_HANDLING_KEY, Boolean.TRUE);
        renderingHints.put(StreamingRenderer.CONTINUOUS_MAP_WRAPPING, Boolean.TRUE);
        renderer.setRendererHints(renderingHints);
        renderer.paint(graphics, paintArea, areaOfInterest);
       
        mapContent.dispose();
    }
View Full Code Here

      renderer.setContext(map);
    }

    public void writeTo(OutputStream out) throws ServiceException, IOException {
      try {
        MapContext map = renderer.getContext();
        double width = -1;
        double height = -1;
       
        if (map instanceof WMSMapContext) {
          WMSMapContext wmsMap = (WMSMapContext)map;
          width = wmsMap.getMapWidth();
          height = wmsMap.getMapHeight();
        }
        else {
          //guess a width and height based on the envelope
          Envelope area = map.getAreaOfInterest();
          if (area.getHeight() > 0 && area.getWidth() > 0) {
            if (area.getHeight() >= area.getWidth()) {
                height = 600;
                width = height*(area.getWidth()/area.getHeight());
              }
View Full Code Here

TOP

Related Classes of org.geotools.map.MapContext

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.