Setting the ID for a Model component

Hello,

When adding a Model to a Map using the mapView.Models.add() function, we get back the newly added Model object. This has the ID property so we can easily maintain a mapping to the object represent by the Model - for example the registration number of a vehicle.

{

“97cf15c1-ad62-412b-ab1a-78ab33dd9419”: “ABC 123H“,

} etc…..

When using the JSX synxtax like this however, we lose this ability as there isn’t a way to set the ID:-

Is there a way to achieve this, or add some kind of tag to the Model so we can maintain such a mapping? This would help to refer back to the original object in event handlers where we only see the ID of the model in the events models array:-

 models: Array(1)

 0: Em2

  groupId: "fd005ea7-e214-42ad-adb7-5bb64e77b3bc"

  id: "97cf15c1-ad62-412b-ab1a-78ab33dd9419"

  __type: "model"

Thanks

Steve

You can use the ref to get the Mappedin JS Model that was just added like this.

const modelRef = useRef<Mappedin.Model | null>(null);
return (
	<Model ref={modelRef} ... />
1 Like