terra-draw-monorepo
    Preparing search index...

    Class TerraDraw

    Index

    Constructors

    Accessors

    • get enabled(): boolean

      A property used to determine whether the instance is active or not. You can use the start method to set this to true, and stop method to set this to false. This is a read only property.

      Returns boolean

      true or false depending on if the instance is stopped or started

    Methods

    • A method for adding features to the store. This method will validate the features returning an array of validation results. Features must match one of the modes enabled in the instance.

      Parameters

      Returns StoreValidation[]

      an array of validation results

    • Removes all data from the current store and ensures any rendered data is cleared from the map.

      Returns void

    • Provides the ability to programmatically deselect a feature using the instances provided select mode. If not select mode is provided in the instance, an error will be thrown. If the instance is not currently in the select mode, it will switch to it.

      Parameters

      • id: FeatureId

        the id of the feature to deselect

      Returns void

    • Returns the next feature id from the store - defaults to UUID4 unless you have set a custom idStrategy. This method can be useful if you are needing creating features outside of the Terra Draw instance but want to add them in to the store.

      Returns FeatureId

      a id, either number of string based on whatever the configured idStrategy is

    • Gets the features at a given longitude and latitude. Will return point and linestrings that are a given pixel distance away from the lng/lat and any polygons which contain it.

      Parameters

      • lngLat: { lat: number; lng: number }
      • Optionaloptions: GetFeatureOptions

      Returns GeoJSONStoreFeatures[]

    • Takes a given pointer event and will return point and linestrings that are a given pixel distance away from the longitude/latitude, and any polygons which contain it.

      Parameters

      • event: PointerEvent | MouseEvent
      • Optionaloptions: GetFeatureOptions

      Returns GeoJSONStoreFeatures[]

    • Get the state of the mode i.e. if we are currently unregistered, registered, drawing etc. This can be used to make decisions based on what the current mode is doing.

      Returns TerraDrawModeState

      the current mode state as a string

    • Returns true or false depending on if the Terra Draw instance has a feature with a given id

      Parameters

      Returns boolean

      a boolean determining if the instance has a feature with the given id

    • Provides the ability to programmatically select a feature using the instances provided select mode. If not select mode is provided in the instance, an error will be thrown. If the instance is not currently in the select mode, it will switch to it.

      Parameters

      • id: FeatureId

        the id of the feature to select

      Returns void

    • A method for setting the current mode by name. Under the hood this will stop the previous mode and start the new one.

      Parameters

      • mode: string

        The mode name you wish to start

      Returns void

    • Type Parameters

      • Styling extends Record<string, number | `#${string}`>

      Parameters

      • mode: string

        The mode you wish to set a style for

      • styles: Styling

        The styles you wish to set for the mode - this is the same as the initialisation style schema

      Returns void

      This method is scheduled for removal in the next major version. Instead use the 'updateModeOptions' method passing the styles property in the options object, and this will dynamically update the styles for the mode.

      Allows the setting of a style for a given mode

    • A method starting Terra Draw. It put the instance into a started state, and in registers the passed adapter giving it all the callbacks required to operate.

      Returns void

    • A method for stopping Terra Draw. Will clear the store, deregister the adapter and remove any rendered layers in the process.

      Returns void

    • A method for transforming a feature's geometry. This can be used to rotate or scale a feature's geometry. This matches the functionality of the scale and rotate behaviors in the select mode.

      Parameters

      • id: FeatureId

        the id of the feature to transform

      • transformation:
            | {
                options: { angle: number };
                origin: Position;
                projection?: "web-mercator";
                type: "rotate";
            }
            | {
                options: { xScale: number; yScale: number };
                origin: Position;
                projection?: "web-mercator";
                type: "scale";
            }

        the transformation to apply to the feature's geometry

      Returns void

    • Updates a features geometry. This an be used to programmatically change the coordinates of a feature. This can be useful for if you want to modify a geometry via a button or some similar user interaction.

      Parameters

      Returns void

    • Updates a features properties. This can be used to programmatically change the properties of a feature. The update is a shallow merge so only the properties you provide will be updated. Certain internal properties are reserved and cannot be updated.

      Parameters

      • id: FeatureId

        the id of the feature to update the property for

      • properties: Record<string, JSON | undefined>

        an object of key value pairs that will be shallowly merged in to the features properties

      Returns void

    • Allow updating of the current options passed to the mode dynamically after the mode has been started. You can also use this method to update styles as these are passed from the options object.

      Type Parameters

      • Mode extends new (...args: any[]) => any

      Parameters

      • mode: InstanceType<Mode>["mode"]

        the mode name you wish to update (the mode name is the public 'mode' property of the mode class)

      • options: Omit<NonNullable<ConstructorParameters<Mode>[0]>, "modeName">

        the options object - this allows partial updating of the modes options (i.e. you do not need to pass the whole options object)

      Returns void