/** * Get the current coordinate system. * * @return the coordinate system of this box. */ public CoordinateReferenceSystem getCoordinateReferenceSystem() { return super.getCoordinateReferenceSystem(); }
/** * Renders features based on the map layers and their styles as specified in the map context * using <code>setContext</code>. * * <p>This version of the method assumes that paint area, envelope and worldToScreen transform * are already computed. Use this method to avoid recomputation. <b>Note however that no check * is performed that they are really in sync!<b/> * * @param graphics The graphics object to draw to. * @param paintArea The size of the output area in output units (eg: pixels). * @param mapArea the map's visible area (viewport) in map coordinates. * @param worldToScreen A transform which converts World coordinates to Screen coordinates. * @deprecated Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) * or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, * AffineTransform worldToScreen) instead. */ public void paint( Graphics2D graphics, Rectangle paintArea, Envelope mapArea, AffineTransform worldToScreen) { paint( graphics, paintArea, new ReferencedEnvelope(mapArea, mapContent.getCoordinateReferenceSystem()), worldToScreen); }
/** * Helper for constructors to calculate mouse position in world coordinates. * * @param pane source map pane * @param event source mouse event * @return position in world coordinates */ private DirectPosition2D calculateWorldPos(MapPane pane, MouseEvent event) { AffineTransform tr = pane.getScreenToWorldTransform(); DirectPosition2D pos = new DirectPosition2D(event.getX(), event.getY()); tr.transform(pos, pos); pos.setCoordinateReferenceSystem(pane.getMapContent().getCoordinateReferenceSystem()); return pos; } }
/** * Gets an envelope of specified width (in pixels) which is centred on the mouse position. * * @param widthPixels envelope width in pixels * @return the envelope * @throws IllegalArgumentException if {@code widthPixels} is less than zero */ public ReferencedEnvelope getEnvelopeByPixels(double widthPixels) { if (widthPixels < 0) { throw new IllegalArgumentException("invalid value for widthPixels: " + widthPixels); } Rectangle2D screenRect = new Rectangle2D.Double( getX() - (widthPixels / 2), getY() - (widthPixels / 2), widthPixels, widthPixels); MapPane pane = getSource(); Rectangle2D worldRect = pane.getScreenToWorldTransform().createTransformedShape(screenRect).getBounds2D(); return new ReferencedEnvelope( worldRect, pane.getMapContent().getCoordinateReferenceSystem()); }
-1, 1, -1, 1, mapContent.getCoordinateReferenceSystem()); ymin, ymax, mapContent.getCoordinateReferenceSystem());
/** Displays the CRS definition in a dialog. */ private void showCRS() { if (mapPane != null && mapPane.getMapContent() != null) { CoordinateReferenceSystem crs = mapPane.getMapContent().getCoordinateReferenceSystem(); JTextReporter.showDialog( "Coordinate reference system", crs.toWKT(), JTextReporter.FLAG_MODAL); } } }
MapContent mapContent = mapPane.getMapContent(); if (mapContent != null) { crs = 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; } } } } }
CoordinateReferenceSystem contentCRS = content.getCoordinateReferenceSystem(); CoordinateReferenceSystem layerCRS = layer.getFeatureSource().getSchema().getCoordinateReferenceSystem();
@Test public void crsIsAutoSetFromFirstLayerWithNonNullCRS() { CoordinateReferenceSystem startCRS = mapContent.getCoordinateReferenceSystem(); ReferencedEnvelope envNoCRS = new ReferencedEnvelope(WORLD, null); Layer layerNoCRS = new MockLayer(envNoCRS); mapContent.addLayer(layerNoCRS); assertEquals(startCRS, mapContent.getCoordinateReferenceSystem()); Layer layerWithCRS = new MockLayer(WORLD); mapContent.addLayer(layerWithCRS); assertEquals( WORLD.getCoordinateReferenceSystem(), mapContent.getCoordinateReferenceSystem()); }
/** * Creates a context from the provided map content. * * <p>This method is used to prevent duplication in classes supporting deprecated * getMapContext() methods. * * @param content MapContent to be represented */ public MapContext(MapContent content) { this(content.getCoordinateReferenceSystem()); for (Layer layer : content.layers()) { addLayer(layer); } this.setAreaOfInterest(content.getViewport().getBounds()); } /**
/** * Helper method for {@linkplain #setDisplayArea} which is also called by other methods that * want to set the display area without provoking repainting of the display * * @param envelope requested display area */ protected void doSetDisplayArea(Envelope envelope) { if (mapContent != null) { CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (crs == null) { // assume that it is the current CRS crs = mapContent.getCoordinateReferenceSystem(); } ReferencedEnvelope refEnv = new ReferencedEnvelope( envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), crs); mapContent.getViewport().setBounds(refEnv); } else { pendingDisplayArea = new ReferencedEnvelope(envelope); } // Publish the resulting display area with the event publishEvent( new MapPaneEvent(this, MapPaneEvent.Type.DISPLAY_AREA_CHANGED, getDisplayArea())); }
/** * Get the current coordinate system. * * @return the coordinate system of this box. */ public CoordinateReferenceSystem getCoordinateReferenceSystem(){ return super.getCoordinateReferenceSystem(); }
0.5 * DEFAULT_DISTANCE_FRACTION * (mapBounds.getWidth() + mapBounds.getHeight()); CoordinateReferenceSystem contentCRS = getMapContent().getCoordinateReferenceSystem(); ReferencedEnvelope env = new ReferencedEnvelope(
@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. */ private void setCRS() { if (mapPane != null && mapPane.getMapContent() != null) { String initial = null; CoordinateReferenceSystem crs = mapPane.getMapContent().getCoordinateReferenceSystem(); if (crs != null) { try { initial = CRS.lookupIdentifier(Citations.EPSG, crs, false); } catch (Exception ex) { // do nothing } } CoordinateReferenceSystem newCRS = JCRSChooser.showDialog(null, initial, "EPSG"); if (newCRS != null && (crs == null || !CRS.equalsIgnoreMetadata(crs, newCRS))) { try { mapPane.getMapContent().getViewport().setCoordinateReferenceSystem(newCRS); } catch (Exception ex) { JExceptionReporter.showDialog(ex, "Failed to set the requested CRS"); } } } }
@Test public void crsIsNotAutoSetIfViewportIsNotEditable() { MapViewport viewport = new MapViewport(); viewport.setEditable(false); mapContent.setViewport(viewport); Layer layerWithCRS = new MockLayer(WORLD); mapContent.addLayer(layerWithCRS); assertNull(mapContent.getCoordinateReferenceSystem()); }
@Test public void crsIsAutoSetWhenGetViewportCalledBeforeAddingLayers() { MapViewport viewport = mapContent.getViewport(); assertNull(viewport.getCoordinateReferenceSystem()); ReferencedEnvelope envNoCRS = new ReferencedEnvelope(WORLD, null); Layer layerNoCRS = new MockLayer(envNoCRS); mapContent.addLayer(layerNoCRS); assertNull(mapContent.getCoordinateReferenceSystem()); Layer layerWithCRS = new MockLayer(WORLD); mapContent.addLayer(layerWithCRS); assertEquals(WORLD.getCoordinateReferenceSystem(), viewport.getCoordinateReferenceSystem()); }
query.setCoordinateSystemReproject(getMapContent().getCoordinateReferenceSystem()); FeatureSource featureSource = getLayer().getFeatureSource(); Collection<PropertyDescriptor> descriptors = featureSource.getSchema().getDescriptors();
"map viewport WGS84", CRS.equalsIgnoreMetadata( DefaultGeographicCRS.WGS84, content.getCoordinateReferenceSystem()));