Select to view content in your preferred language

How to add symbol image to arcScene using local .png or .img file?

758
3
Jump to solution
01-31-2021 09:57 AM
VanyaIvanov
Regular Contributor

How to add symbol image to arcScene using local .png or .img file?

I used this code but it doesnt work:

GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
sceneView.getGraphicsOverlays().add(graphicsOverlay);

// An image file on the hard drive.
File file = new File("C:\\Users\\user\\Documents\\IMG1.jpg");

String localUri = file.toURI().toString();

PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(localUri);
markerSymbol.setHeight(100);
markerSymbol.setWidth(100);

markerSymbol.loadAsync();
com.esri.arcgisruntime.geometry.Point symbolPoint = new com.esri.arcgisruntime.geometry.Point(20, 20, SpatialReferences.getWgs84());
Graphic symbolGraphic = new Graphic(symbolPoint, markerSymbol);
markerSymbol.addDoneLoadingListener(() -> graphicsOverlay.getGraphics().add(symbolGraphic));

 

0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

If you are working with a file on the local OS, you don't need a full URI format, you can just use the file on its own.  

I just tried this out with the following code:

    GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
    mapView.getGraphicsOverlays().add(graphicsOverlay);

    // An image file on the hard drive.
    PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol("./FireStation.png");
    markerSymbol.setHeight(100);
    markerSymbol.setWidth(100);

    markerSymbol.loadAsync();
    markerSymbol.addDoneLoadingListener(() -> {
      System.out.println("loaded status " + markerSymbol.getLoadStatus());

      if (markerSymbol.getLoadStatus() == LoadStatus.LOADED) {
        // use the symbol
        Point point = new Point(0,0);

        Graphic graphic = new Graphic(point,markerSymbol);
        graphicsOverlay.getGraphics().add(graphic);

      } else {
        // error state as it didn't load
        System.out.println("Failed to load: " + markerSymbol.getLoadError().getCause());
      }
    });

Does this work for you?

View solution in original post

3 Replies
MarkBaird
Esri Regular Contributor

If you are working with a file on the local OS, you don't need a full URI format, you can just use the file on its own.  

I just tried this out with the following code:

    GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
    mapView.getGraphicsOverlays().add(graphicsOverlay);

    // An image file on the hard drive.
    PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol("./FireStation.png");
    markerSymbol.setHeight(100);
    markerSymbol.setWidth(100);

    markerSymbol.loadAsync();
    markerSymbol.addDoneLoadingListener(() -> {
      System.out.println("loaded status " + markerSymbol.getLoadStatus());

      if (markerSymbol.getLoadStatus() == LoadStatus.LOADED) {
        // use the symbol
        Point point = new Point(0,0);

        Graphic graphic = new Graphic(point,markerSymbol);
        graphicsOverlay.getGraphics().add(graphic);

      } else {
        // error state as it didn't load
        System.out.println("Failed to load: " + markerSymbol.getLoadError().getCause());
      }
    });

Does this work for you?

VanyaIvanov
Regular Contributor

Thank you! It works.

0 Kudos
MarkBaird
Esri Regular Contributor

An alternative solution would be to construct the symbol directly from a JavaFX image.  If you are already using the image elsewhere in your app for example, you could do this:

    Image image = new Image("file:FireStation.png", 100, 100, false, false);
    PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(image);