Hello all, I have a JMapFrame with a MapContent containing a raster JPG, a shapefile and 2 feature layers containing points and lines. The frame has a checkbox that change the visibility of the shapefile layer. When the shapefile layer is not visible, I would like the map to be resized in order for the other layers to appear bigger (the shapefile extent, Nz map, is a lot bigger than the other layers).
What I have in return is that, when the biggest layer is not visible the others are visualized very small, while when it is visible, the raster is at his biggest dimension and NZ map is cut out of the screen. Below a piece of the code I am using to achieve the goal. I can post the whole frame code and the files (jpg and shp) if necessary. Any help is more than appreciated. Thank you Andrea frame.enableToolBar(true); frame.enableStatusBar(true); JToolBar toolBar = frame.getToolBar(); JCheckBox jcb = new JCheckBox("Shape Visible", true); toolBar.addSeparator(); toolBar.add(jcb); jcb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { shpLayer.setVisible(jcb.isSelected()); recalculateBounds(); } }); private void recalculateBounds() { MapContent content = frame.getMapContent(); MapViewport viewport = content.getViewport(); actualBounds = viewport.getBounds(); maxBounds = null; ReferencedEnvelope maxBounds = null; CoordinateReferenceSystem mapCRS = viewport.getCoordinateReferenceSystem(); for (Layer layer : content.layers()) { if(layer.isVisible()) { ReferencedEnvelope dataBounds = layer.getBounds(); CoordinateReferenceSystem dataCrs = dataBounds.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(dataCrs, mapCRS)){ try { dataBounds = dataBounds.transform(mapCRS, true); catch (TransformException e) { e.printStackTrace(); catch (FactoryException e) { e.printStackTrace(); } if (maxBounds == null) { maxBounds = dataBounds; }else { maxBounds.expandToInclude(dataBounds); } } } viewport.setBounds( maxBounds); }
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users