Skip to main content

alphaThis is a new frontend component. Help us improve it and give your feedback on Slack.

Frame Plugin

Adds a regular shaped frame to the map, for the user to position an area by moving the map, e.g. to make a report or draw a feature. The user presses Done when the area is in the frame.

Usage

import createFramePlugin from '@defra/interactive-map/plugins/frame'
const framePlugin = createFramePlugin({
aspectRatio: 1.5
})
const interactiveMap = new InteractiveMap('map', {
plugins: [framePlugin]
})
interactiveMap.on('map:ready', () => {
framePlugin.addFrame('report-area')
})
interactiveMap.on('frame:done', (feature) => {
console.log('Framed area:', feature.geometry)
})

For UMD, add plugins/frame/dist/umd/index.js and call defra.framePlugin().

Options

Options are passed to the factory function when creating the plugin. The FrameConfig options (aspectRatio and the widths) are the defaults for every frame, and can be overridden for each frame by addFrame and editFeature.


aspectRatio

Type:
number
Default:
1

The frame's width divided by its height. 2 is twice as wide as it is tall.


mobileWidth

Type:
string
Default:
'300px'

Maximum width of the frame on mobile.


tabletWidth

Type:
string
Default:
'360px'

Maximum width of the frame on tablet.


desktopWidth

Type:
string
Default:
'400px'

Maximum width of the frame on desktop.


manifest

Type:
Partial<PluginManifest>

Overrides for the plugin's buttons, panels and controls, matched by id. See PluginDescriptor manifest. The plugin's buttons are frameDone and frameCancel.


Methods

Methods are called on the plugin instance after the map is ready.


addFrame(featureId, config?)

Show a frame over the centre of the map, for the user to position by moving the map. While it's shown, frame:updated is emitted as the framed area changes. Done emits frame:done with the framed area as a polygon feature with this ID, and Cancel emits frame:cancel.

ArgumentTypeDescription
featureIdstringID to give the framed area's feature
configFrameConfigOptional. The frame's shape and size, overriding the plugin options
framePlugin.addFrame('report-area', { aspectRatio: 210 / 297 })

editFeature(feature, config?)

Show a frame fitted to an existing feature, with the feature's aspect ratio, and fit the map to it. Done emits frame:done with the framed area as a polygon feature with the same ID.

ArgumentTypeDescription
featureGeoJSON.FeatureThe polygon feature to frame. Its ID is feature.id, or else feature.properties.id
configFrameConfigOptional. The frame's size, overriding the plugin options. Its aspectRatio is ignored
framePlugin.editFeature(savedArea)

Events

Subscribe to events using interactiveMap.on().


frame:add

Emitted when addFrame shows a frame.

Payload:
None

frame:edit

Emitted when editFeature shows a frame.

Payload:
None

frame:updated

Emitted while a frame is shown, whenever the framed area changes as the map moves, zooms or resizes.

Payload:
the framed area, as a polygon GeoJSON.Feature

frame:done

Emitted when the user presses Done. The frame is removed.

Payload:
the framed area, as a polygon GeoJSON.Feature with the frame's feature ID

frame:cancel

Emitted when the user presses Cancel. The frame is removed.

Payload:
None