Select to view content in your preferred language

Experience Builder custom widget get graphics

689
2
11-27-2023 05:23 AM
liva
by
New Contributor

Hallo,

I am trying to develop a widget in experience builder. The purpose is, when the user presses a button, the app to retrieve all the user's drawings that exist on the map, in order to get their geometry. This is my code so far, but it seems that it doesn't work correctly. The function getGraphics() works, but the drawings on the map can’t be read.

import { React, AllWidgetProps } from 'jimu-core'

import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'

import { Button } from 'jimu-ui';

const { useState } = React

const Widget = (props: AllWidgetProps<any>) => {

  const [jmv, setJimuMapView] = useState<JimuMapView>()

 

  const activeViewChangeHandler = (jimuMapView: JimuMapView) => {

    if (jimuMapView) {

      setJimuMapView(jimuMapView)

    }

  }

   function getGraphics(){

    const graphicDrawings = jmv.view.graphics.toArray()

    if(graphicDrawings.length > 0) {

      console.log("graphics on map")

    }

    else{

      console.log('no graphics on map')

    }

  }

  return (

    <div className="widget-starter jimu-widget">

      {

        props.useMapWidgetIds &&

        props.useMapWidgetIds.length === 1 && (

          <JimuMapViewComponent

            useMapWidgetId={props.useMapWidgetIds?.[0]}

            onActiveViewChange={activeViewChangeHandler}

          />

        )

      }

      <Button type="primary" onClick={getGraphics}>

      </Button>

 

    </div>

  )

}

export default Widget

 

Appreciate if you can help me…Thank you!

0 Kudos
2 Replies
BluntBSE
New Contributor II

I have the same question. Jimu Map Views appear to have a "view" wrapper, but this "view" doesn't appear to have the "graphics" property, referenced in the esri tutorial on Graphics.

0 Kudos
liva
by
New Contributor

Thank you for your response. I solved the problem by creating a new graphics layer for my custom widget.

0 Kudos