2

I am creating a simple method for drawing Points on map, and have problem with full extent. I create a new point layer and add it to mapContent, and the problem is that it set bounds somewhere around 0, is it possible to set that bounds to be same as for another layer opened. If I first open another layer I get this in console

Jun 22, 2016 6:26:54 PM org.geotools.map.FeatureLayer getBounds
WARNING: Bounds crs not defined; assuming bounds from schema are correct for CollectionFeatureSource:org.geotools.feature.DefaultFeatureCollection@48b99eac
Jun 22, 2016 6:26:55 PM org.geotools.map.FeatureLayer getBounds
WARNING: Bounds crs not defined; assuming bounds from schema are correct for CollectionFeatureSource:org.geotools.feature.DefaultFeatureCollection@48b99eac

and I get that every time I create a new point, just more for every new point

Here is code I use for this

    JButton create = new JButton("create");
    create.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            mapPane.setCursorTool(
                    new CursorTool() {
                        @Override
                        public void onMouseClicked(MapMouseEvent ev) {
                            createPointLayer();
                            createFeatures(ev);
                            for(Layer layer : map.layers()){
                                if(pointLayer == layer){
                                    i++;
                                    if(i>1){
                                        int index = map.layers().indexOf(layer);
                                        map.layers().remove(index);
                                    }
                                }
                            }
                        }
                    });
        }

    });
    toolBar.add(create);
    }
void createFeatures(MapMouseEvent ev) {
    double[] xy = ev.getWorldPos().getCoordinate();
    Point point = geometryFactory.createPoint(new Coordinate(xy[0], xy[1]));
    pointCollection.add(SimpleFeatureBuilder.build(pointType, new Object[]{point}, null));

    //create map layer event
    MapLayerEvent mple = new MapLayerEvent(pointLayer, MapLayerEvent.DATA_CHANGED);
    //create maplayer list event
    MapLayerListEvent mplle = new MapLayerListEvent(map, pointLayer, map.layers().indexOf(pointLayer), mple);

    mapPane.layerChanged(mplle);
    System.out.println(MessageFormat.format("Created Point: {0}", point));
}
/**
 *
 */
private void createPointLayer() {
    if (pointType == null) {
        pointFeatureTypeBuilder.setName("Point");
        pointFeatureTypeBuilder.setCRS(mapPane.getMapContent().getCoordinateReferenceSystem());
        pointFeatureTypeBuilder.add("the_geom", Point.class);
        pointType = pointFeatureTypeBuilder.buildFeatureType();
        pointCollection = new DefaultFeatureCollection(null, pointType);
    }

    pointLayer = new FeatureLayer(pointCollection, pointStyle);
    map.addLayer(pointLayer);
}

Do you have any suggestion, or to leave it like that and just exclude that layer when setting extent?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.