arcgis ios 贴图

arcgis for ios 100.x 现在有一张png图片,知道这个图片在地图上的坐标。现在需要把这个图片放到地图上,并且可以随地图放大缩小。这个该怎么搞?

你可以使用ArcGIS Runtime SDK for iOS中的AGSGraphic类来实现在地图上添加图片的功能。


首先,使用AGSPoint构造函数创建AGSPoint来表示图片所在的坐标。然后,使用AGSMutableMarkerSymbol构造函数创建AGSMutableMarkerSymbol,并使用UIImage的CGImage属性设置图片。


接着,使用AGSGraphic构造函数创建AGSGraphic,并将AGSPoint和AGSMutableMarkerSymbol作为参数传递给构造函数。最后,使用AGSGraphicsOverlay的addGraphic:方法将AGSGraphic添加到地图上。
代码如下:
但是在地图缩放时,图片也会相应地缩放哦

let point = AGSPoint(x: x, y: y, spatialReference: mapView.spatialReference)
let image = UIImage(named: "myImage")
let symbol = AGSMutableMarkerSymbol(image: image!.cgImage!)
let graphic = AGSGraphic(geometry: point, symbol: symbol, attributes: nil)
graphicsOverlay.addGraphic(graphic)


你可以使用 ArcGIS Runtime 100.x for iOS 中的 AGSGraphicsOverlay 类来在地图中放置你的 PNG 图片。

首先,你需要将你的图片转换为 AGSPictureMarkerSymbol 类型。然后,你可以创建一个 AGSGraphic 对象,并使用你的 AGSPictureMarkerSymbol 和你知道的坐标来初始化它。最后,你可以将这个 AGSGraphic 添加到 AGSGraphicsOverlay 对象中,并将 AGSGraphicsOverlay 添加到地图视图中。

代码示例如下:

// 将图片转换为 AGSPictureMarkerSymbol
let image = UIImage(named: "myImage")!
let symbol = AGSPictureMarkerSymbol(image: image)

// 创建 AGSGraphic 对象并设置位置
let graphic = AGSGraphic(geometry: AGSPoint(x: xCoordinate, y: yCoordinate, spatialReference: mapView.spatialReference), symbol: symbol)

// 创建 AGSGraphicsOverlay 对象并添加 AGSGraphic
let graphicsOverlay = AGSGraphicsOverlay()
graphicsOverlay.graphics.add(graphic)

// 将 AGSGraphicsOverlay 添加到地图视图中
mapView.graphicsOverlays.add(graphicsOverlay)

这样,你就可以在地图视图中看到你的图片了。随着地图的缩放,图片会自动调整大小。

可以使用AGSMapView的ViewpointChanged事件来更新AGSImageGraphic的图像,以便在地图缩放时更新图像的大小。

这是一个示例代码,假设已经有一个名为mapView的AGSMapView实例,并且已经知道了图像的URL:

// Create an AGSGraphicsOverlay to hold the image
let graphicsOverlay = AGSGraphicsOverlay()

// Add the graphics overlay to the map view
mapView.graphicsOverlays.add(graphicsOverlay)

// Load the image from a URL
let imageURL = URL(string: "https://www.example.com/image.png")!
let image = AGSImage(url: imageURL)

// Create an AGSImageGraphic and add it to the graphics overlay
let imageGraphic = AGSImageGraphic(image: image, point: AGSPoint(x: 0, y: 0, spatialReference: mapView.spatialReference))
graphicsOverlay.graphics.add(imageGraphic)

// Update the image size when the map view's viewpoint changes
mapView.viewpointChangedHandler = { [weak self] event in
    guard let self = self else { return }
    let viewpoint = event.viewpoint
    let size = self.mapView.toScreen(AGSEnvelope(xMin: 0, yMin: 0, xMax: 100, yMax: 100, spatialReference: self.mapView.spatialReference)).extent
    imageGraphic.image = image.resizedImage(to: size)
}

仅供参考,望采纳,谢谢。

在 ArcGIS for iOS 中可以使用 AGSGraphicsOverlay 来在地图上放置图片。 AGSGraphicsOverlay 是一个可视化图形的容器,可以将任意数量的 AGSGraphic 添加到地图中。 AGSGraphic 类表示在地图上显示的图形,可以通过向其添加任意数量的几何和属性信息来定义图形。

下面是如何将图片放置在地图上的步骤:

创建 AGSGraphicsOverlay 对象,然后将其添加到地图视图中。

创建 AGSGraphic 对象,并设置其几何属性。

创建 AGSImage 对象并设置其图片数据。

使用 AGSMarkerSymbol 创建标记符号,并将其设置为 AGSGraphic 的符号。

将 AGSGraphic 添加到 AGSGraphicsOverlay 中。

// Create the graphics overlay
AGSGraphicsOverlay *graphicsOverlay = [[AGSGraphicsOverlay alloc] init];

// Add the graphics overlay to the map view
[self.mapView addGraphicsOverlay:graphicsOverlay];

// Create the graphic
AGSGraphic *graphic = [[AGSGraphic alloc] init];

// Set the geometry for the graphic
graphic.geometry = [AGSPoint pointWithX:x y:y spatialReference:self.mapView.spatialReference];

// Create the image
NSData *imageData = UIImagePNGRepresentation(image);
AGSImage *agImage = [[AGSImage alloc] initWithImageData:imageData];

// Create the marker symbol
AGSMarkerSymbol *markerSymbol = [AGSMarkerSymbol markerSymbolWithColor:[UIColor greenColor]];
markerSymbol.image = agImage;

// Set the symbol for the graphic
graphic.symbol = markerSymbol;

// Add the graphic to the graphics overlay
[graphicsOverlay addGraphic:graphic];

我来帮你尝试解决下,若是没用,我就不贴代码了啊。等我

首先创建 AGSGraphicsOverlay 对象。然后使用 AGSPictureMarkerSymbol 对象创建一个图片符号,并设置为 PNG 图片的 URL。再使用 AGSPoint 对象创建图片的坐标,并且为这个图片标记创建一个 AGSGraphic 对象。其次将创建的 AGSGraphic 对象添加到 AGSGraphicsOverlay 对象中。最后将 AGSGraphicsOverlay 对象添加到地图视图中。

使用 ArcGIS for iOS 100.x 版本,可以使用 AGSGraphicsOverlay 来添加图片到地图上,并且可以根据图片的坐标来定位图片。

下面是一个示例代码:

let overlay = AGSGraphicsOverlay()

let pictureMarker = AGSPictureMarkerSymbol(image: UIImage(named: "myImage.png"))
let point = AGSPoint(x: xCoordinate, y: yCoordinate, spatialReference: mapView.spatialReference)
let graphic = AGSGraphic(geometry: point, symbol: pictureMarker, attributes: nil)
overlay.graphics.add(graphic)

mapView.graphicsOverlays.add(overlay)

这里, xCoordinate 和 yCoordinate 是图片在地图上的坐标,需要提前知道。myImage.png 是图片的文件名。这段代码创建了一个 AGSGraphicsOverlay,并在其中添加了一个图片,并使用了一个 AGSPictureMarkerSymbol来表示图片。最后把图层添加到地图中,这样就可以在地图上看到这张图片。

随着地图的放大和缩小,图片图片也会自动随之放大或缩小,因为它是跟随地图显示的。但是这个图片放大缩小的比例是不能控制的。如果需要控制图片的放大缩小比例,可以尝试在代码中对AGSGraphic 中的 symbol 进行修改,在设置比例属性来进行控制。

注意:具体的实现还需根据具体业务逻辑来实现.

我不知道是不是我写的有歧义。我的要求是图片必须可以跟随地图放大缩小而放大缩小,说白了就是地图放大的时候 那个图片也跟着放大,地图缩小的时候 图片也要跟着缩小。我当前是用AGSKMLGroundOverlay来解决了这个问题。感谢上面的回答。虽然最终没有解决问题。