i2group / notebook-sdk

Create plug-ins that expand and enhance the functionality of the i2 Notebook web client by using the i2 Notebook SDK. The SDK is comprised of documentation, tools, and sample code.
https://i2group.github.io/notebook-sdk/
MIT License
4 stars 1 forks source link

Add geospatial item to chart #8

Closed stvdo closed 12 months ago

stvdo commented 1 year ago

Good morning,

I have now added most properties to an entity and put them on the chart. However, I cannot figure out how to do this for the geospatial entities. Please can you help with this.

The Source is already a Geospatial object, so I expect that this can be easily added as a target property.

My function in ToolView.tsx

const targetProperties: { [key: string]: data.PropertyValue } = {};
        for (const propertyType of entityType.propertyTypes) {

          const sourceProperty = event.properties.find((c: { typeId: any; }) => c.typeId === propertyType.analyzeId);
          if ( sourceProperty ) {
            console.log('Source', sourceProperty);
            console.log('Property', propertyType);
            if ( sourceProperty.value && (propertyType.logicalType === 'singleLineString' || propertyType.logicalType === 'suggestedFromList')){
              console.log('match');
              targetProperties[propertyType.id] = sourceProperty.value;
            } else {
              if ( propertyType.logicalType === 'geospatial'){
                debugger;
                //data.createGeoPoint();
                targetProperties[propertyType.id] = sourceProperty.value;
              }
            }
          }
        }

The error image

Anthony-Johnson-i2 commented 1 year ago

Hi @sdorresteijn88

Have you had a look at the app.IValueFactory that has helper functions for creating a data.IGeoPoint object from either a pair of latitude and longitude values or from a data.IGeoPointData object.

image

Cheers

stvdo commented 1 year ago

Hi @Anthony-Johnson-i2 ,

I have seen this in the connectors indeed. But I didn't get it to work in the plugin.

import {
  chart,
  data,
  records,
  schema,
  toolview,
} from '@i2analyze/notebook-sdk';
.....
targetProperties[propertyType.id] = data.createGeoPoint(sourceProperty.value.coordinates[1], sourceProperty.value.coordinates[0]);

This gives an error and I don't know what to import.

image

image

Tim-Mawson-i2 commented 1 year ago

@sdorresteijn88 Using the value factory is the correct approach - however, note that data is just a typing namespace, there's no code (or at least very little) shipped with the @i2analyze/notebook-sdk, it's mostly just Typescript types. Instead, the value factory can be found on the mutations object that is passed to you in the runXMutations call, e.g.

api.runTrackedMutation((application, mutations) => {
  const geoPoint = mutations.valueFactory.createGeoPoint(lat, long);
  ...
});
Anthony-Johnson-i2 commented 1 year ago

Hi @sdorresteijn88 (Steven)

With Tim's last reply to you, did you manage to get this figured out?

If so, are you happy for this issue to be closed?

Cheers

stvdo commented 12 months ago

Morning @Tim-Mawson-i2 and @Anthony-Johnson-i2,

Thank you very much for your reply. That's the solution indeed, thanks a lot!