package nl.tudelft.simulation.dsol.animation.gis.osm; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.rmi.RemoteException; import javax.naming.NamingException; import org.djutils.draw.bounds.Bounds2d; import org.djutils.draw.bounds.Bounds3d; import org.djutils.draw.point.OrientedPoint3d; import org.djutils.draw.point.Point2d; import org.djutils.logger.CategoryLogger; import nl.tudelft.simulation.dsol.animation.D2.RenderableScale; import nl.tudelft.simulation.dsol.animation.gis.GisMapInterface; import nl.tudelft.simulation.dsol.animation.gis.GisRenderable2D; import nl.tudelft.simulation.dsol.animation.gis.transform.CoordinateTransform; import nl.tudelft.simulation.naming.context.Contextualized; import nl.tudelft.simulation.naming.context.util.ContextUtil; /** * This renderable draws OSM maps. *
* Copyright (c) 2020-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information DSOL Manual. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * DSOL License. *
* @author Alexander Verbraeck */ public class OsmRenderable2D implements GisRenderable2D { /** */ private static final long serialVersionUID = 20200108L; /** the map to display. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected GisMapInterface map = null; /** the image cached image. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected BufferedImage cachedImage = null; /** the cached extent. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected Bounds2d cachedExtent = new Bounds2d(0, 0, 0, 0); /** the cached screenSize. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected Dimension cachedScreenSize = new Dimension(); /** the location of the map. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected OrientedPoint3d location = null; /** the bounds of the map. */ @SuppressWarnings("checkstyle:visibilitymodifier") protected Bounds3d bounds = null; /** * constructs a new GisRenderable2D. * @param contextProvider Contextualized; the object that can provide the context to store the animation objects * @param map MapInterface; the map to use. */ public OsmRenderable2D(final Contextualized contextProvider, final GisMapInterface map) { this(contextProvider, map, new CoordinateTransform.NoTransform()); } /** * constructs a new GisRenderable2D. * @param contextProvider Contextualized; the object that can provide the context to store the animation objects * @param map MapInterface; the map to use. * @param coordinateTransform CoordinateTransform; the transformation of (x, y) coordinates to (x', y') coordinates. */ public OsmRenderable2D(final Contextualized contextProvider, final GisMapInterface map, final CoordinateTransform coordinateTransform) { this(contextProvider, map, coordinateTransform, -Double.MAX_VALUE); } /** * constructs a new GisRenderable2D based on an existing Map. * @param contextProvider Contextualized; the object that can provide the context to store the animation objects * @param map MapInterface; the map to use. * @param coordinateTransform CoordinateTransform; the transformation of (x, y) coordinates to (x', y') coordinates. * @param z double; the z-value to use */ public OsmRenderable2D(final Contextualized contextProvider, final GisMapInterface map, final CoordinateTransform coordinateTransform, final double z) { try { this.map = map; this.location = new OrientedPoint3d(this.cachedExtent.midPoint().getX(), this.cachedExtent.midPoint().getY(), z); this.bounds = new Bounds3d(this.cachedExtent.getDeltaX(), this.cachedExtent.getDeltaY(), 0.0); this.bind2Context(contextProvider); } catch (Exception exception) { CategoryLogger.always().warn(exception, "