Image overlays can be used to quickly render frequently changing images in a map view A map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more or scene view A scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more . For example, you can render real-time sensor data, such as weather, where each static image displayed represents a single frame from the radar satellite image. A user perceives the display of the static images in succession as an animation if the images are displayed at small enough time intervals.

Image overlays and graphics overlays both render above all layers in the map or scene. Image overlays render below any graphics overlays you’ve added to the view. This order ensures that graphics you want to display won’t be obscured by your image overlays. For example, you might want to show graphics representing aircraft on top of image overlays showing the sensor data they are collecting.

Since they are designed for quick display, image overlays do not support the rich processing and rendering capabilities of a raster layer, which still provides the best option for workflows that require static image rendering, analysis, and persistence. See Add raster data for more information about working with raster layers.

Add an image overlay

A map or scene view manages a collection of image overlays. Each ImageOverlay contains a single ImageFrame that defines an image to display. Georeferenced images (those with a world file) are added at the correct geographic location. Otherwise, you must define a geographic extent An extent is a bounding rectangle with points that delineate an area for a map or scene. Learn more for the image frame. If a spatial reference A spatial reference is a set of parameters, typically defined by a WKID, that define the coordinate system and spatial properties for geographic data. Applications use a spatial reference to correctly display the position of geographic data in a map or scene. Learn more is not defined for the extent, it is assumed to be the same as the map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more or scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more . If the spatial reference of the extent is different from that of the map or scene, the image will fail to render.

  1. If your image doesn’t have georeference information, define an extent for the image using an Envelope or quadrilateral Polygon.

    Create envelope
    /// An envelope of the Pacific sector in southwest US for displaying the image frame.
    private let pacificSouthwestEnvelope = Envelope(
    center: Point(latitude: 35.131016955536694, longitude: -120.0724273439448),
    width: 15.09589635986124,
    height: -14.3770441522488
    )

    You can also define a geographic extent using a polygon that has exactly four points (to define each corner of the image). The polygon can be any quadrilateral; it need not be a rectangle.

    Create polygon
    /// (untransformed) Lower-left -> Upper-left -> Upper-right -> Lower-right
    private let pacificSouthwestPolygon = Polygon(
    points: [
    Point(x: -123, y: 27),
    Point(x: -123, y: 40),
    Point(x: -120, y: 40),
    Point(x: -120, y: 27)
    ]
    )

    When you define the polygon, the order in which you specify the vertices has significance and can result in rotating or reflecting the image displayed within the polygon.

    In the following descriptions, all starting positions refer to the original (untransformed) position.

    When specifying vertices in the clockwise direction: Start in the lower-left corner to display the image in its original orientation. Starting at the next clockwise vertex rotates the image 90° clockwise, and so on.

    When specifying vertices in the counterclockwise direction: Start in the lower-right corner to reflect the image around the y-axis. Starting at the next counterclockwise vertex rotates the reflected image 90° counterclockwise, and so on.

  2. Create an image frame and pass an UIImage into the constructor. These formats are supported for UIImage: TIFF, GeoTIFF, ICO, BMP, GIF, JPEG and PNG. Animated GIF is not supported, but can be displayed as a static image. If you need to define the extent explicitly, also pass the envelope or polygon to the constructor.

    Create image frame using UIImage
    let frame = ImageFrame(image: uiImage, extent: pacificSouthwestEnvelope)
    Create image frame using URL
    let frame = ImageFrame(url: urlToImage, extent: pacificSouthwestEnvelope)
  3. Attach the initial image frame to the image overlay. The image overlay has properties to control visibility and opacity of the image. Set the opacity less than 1.0 to make the image semi-transparent so data underneath can be seen.

    Add image frame to an image overlay
    imageOverlay.imageFrame = frame
    imageOverlay.opacity = 0.5
  4. Add the image overlay to the map or scene view’s image overlay collection. To zoom to the extent of the image, you can set the viewpoint using the image frame extent.

    Add image overlay to scene view's image overlay collection
    // Create a scene view to display the scene.
    SceneView(scene: model.scene, imageOverlays: [model.imageOverlay])
    Set viewpoint with the image frame's extent
    // Creates a scene and set an initial viewpoint.
    let scene = Scene(basemapStyle: .arcGISDarkGrayBase)
    let point = Point(x: -116.621, y: 24.7773, z: 856977, spatialReference: .wgs84)
    let camera = Camera(location: point, heading: 353.994, pitch: 48.5495, roll: 0)
    scene.initialViewpoint = Viewpoint(boundingGeometry: imageFrame.extent!, camera: camera)

Radar image for image overlay

Animate an image overlay

You can animate the display of image overlays by changing the frame they contain at a specified interval. You might use a timer, for example, to read the next image in a sequence, use it to create a new ImageFrame, and replace the current frame in the ImageOverlay.

  1. Create a function that sets the image frame. The function is called for each image.

    Function that sets the image frame
    /// Sets the image frame to the next one.
    @objc
    func setImageFrame() {
    if let uiImage = imagesIterator.next() {
    let frame = ImageFrame(image: uiImage, extent: pacificSouthwestEnvelope)
    imageOverlay.imageFrame = frame
    imageOverlay.opacity = 0.5
    }
    }
  2. Define a function that returns a CADisplayLink that will call the setImageFrame() function at set intervals.

    Define function returning a CADisplayLink
    /// Creates a display link timer for the image overlay animation.
    /// - Returns: A new `CADisplayLink` object.
    func makeDisplayLink() -> CADisplayLink {
    // Create new display link.
    let newDisplayLink = CADisplayLink(target: self, selector: #selector(setImageFrame))
    // Set the default frame rate to 60 fps.
    newDisplayLink.preferredFramesPerSecond = 60
    newDisplayLink.isPaused = true
    // Add to main thread common mode run loop, so it is not effected by UI events.
    newDisplayLink.add(to: .main, forMode: .common)
    return newDisplayLink
    }
  3. Create the CADisplayLink and load the first image.

    gif of radar images for image overlay animation

    Create CADisplayLink
    init() {
    // Create display link and load first image.
    displayLink = makeDisplayLink()
    setImageFrame()
    }