/** * Sets the CRS of the viewport, if one exists, based on the first Layer with a non-null CRS. * This is called when a new Layer is added to the Layer list. Does nothing if the viewport * already has a CRS set or if it has been set as non-editable. */ private void checkViewportCRS() { if (viewport != null && getCoordinateReferenceSystem() == null && viewport.isEditable()) { for (Layer layer : layerList) { ReferencedEnvelope bounds = layer.getBounds(); if (bounds != null) { CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); if (crs != null) { viewport.setCoordinateReferenceSystem(crs); return; } } } } }
@Test public void newViewportIsEditableByDefault() { MapViewport vp = new MapViewport(); assertTrue(vp.isEditable()); }
@Test public void setAndRetrieveEditableStatus() { MapViewport vp = new MapViewport(); vp.setEditable(false); assertFalse(vp.isEditable()); vp.setEditable(true); assertTrue(vp.isEditable()); }
@Test public void copyCtor() { MapViewport vp = new MapViewport(WORLD_1_1, true); vp.setScreenArea(SCREEN_1_1); vp.setEditable(false); MapViewport copy = new MapViewport(vp); assertTrue(copy.isEditable()); assertViewportsEqual(vp, copy); }
@Test public void crsIsNotAutoSetIfViewportHasExplicitCRS() { final CoordinateReferenceSystem crs = DefaultEngineeringCRS.GENERIC_2D; MapViewport viewport = new MapViewport(); viewport.setCoordinateReferenceSystem(crs); mapContent.setViewport(viewport); Layer layerWithCRS = new MockLayer(WORLD); mapContent.addLayer(layerWithCRS); assertTrue(viewport.isEditable()); assertEquals(crs, mapContent.getCoordinateReferenceSystem()); assertFalse( WORLD.getCoordinateReferenceSystem() .equals(mapContent.getCoordinateReferenceSystem())); }
/** * Sets the CRS of the viewport, if one exists, based on the first Layer * with a non-null CRS. This is called when a new Layer is added to the * Layer list. Does nothing if the viewport already has a CRS set or if * it has been set as non-editable. */ private void checkViewportCRS() { if (viewport != null && getCoordinateReferenceSystem() == null && viewport.isEditable()) { for (Layer layer : layerList) { ReferencedEnvelope bounds = layer.getBounds(); if (bounds != null) { CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); if (crs != null) { viewport.setCoordinateReferenceSystem(crs); return; } } } } }