Add geometry rendering improvements

This commit is contained in:
Kelani Tolulope
2022-12-14 16:54:03 +01:00
parent 82981edb2b
commit f29b9a1dfe
21 changed files with 1039 additions and 2 deletions
@@ -0,0 +1,35 @@
import { Record } from '../../record'
import { Namespace } from '../../namespace'
import { Module } from '../../module'
import { Compose as ComposeAPI } from '../../../../api-clients'
interface FeedOptions {
color: string;
prefilter: string;
}
interface Feed {
titleField: string;
options: FeedOptions;
}
interface Range {
end: Date;
start: Date;
}
export async function RecordFeed ($ComposeAPI: ComposeAPI, module: Module, namespace: Namespace, feed: Feed): Promise<any[]> {
// Params for record fetching
const params = {
namespaceID: namespace.namespaceID,
moduleID: module.moduleID,
query: feed.options.prefilter,
}
const events: Array<any> = []
return $ComposeAPI.recordList(params).then(({ set }) => {
return (set as Array<{ recordID: string }>)
// cast & freeze
.map(r => Object.freeze(new Record(module, r)))
})
}
@@ -0,0 +1,56 @@
import { Apply, NoID } from '../../../../cast'
import { IsOf } from '../../../../guards'
interface FeedOptions {
color: string;
prefilter: string;
moduleID: string;
resource: string;
titleField: string;
geometryField: string;
displayMarker: boolean;
displayPolygon: boolean;
}
export type FeedInput = Partial<Feed> | Feed
const defOptions = {
moduleID: NoID,
color: '#2f85cb',
prefilter: '',
resource: 'compose:record',
titleField: '',
geometryField: '',
displayMarker: false,
displayPolygon: true,
}
/**
* Feed class represents an event feed for the given calendar
*/
export default class Feed {
public resource = 'compose:record'
public titleField = ''
public color = '#2f85cb'
public geometryField = ''
public displayMarker = false
public displayPolygon = true
public options: FeedOptions = { ...defOptions }
constructor (i?: FeedInput) {
this.apply(i)
}
apply (i?: FeedInput): void {
if (!i) return
if (IsOf<Feed>(i, 'resource')) {
Apply(this, i, String, 'resource', 'color', 'titleField', 'geometryField')
Apply(this, i, Boolean, 'displayMarker', 'displayPolygon')
if (i.options) {
this.options = { ...this.options, ...i.options }
}
}
}
}
@@ -0,0 +1 @@
export { PageBlockGeometry } from './page-block'
@@ -0,0 +1,63 @@
import { PageBlock, Registry } from '../base'
import { Apply } from '../../../../cast'
import Feed, { FeedInput } from './feed'
import { RecordFeed } from './feed-record'
const kind = 'Geometry'
type Bounds = number[][]
interface Options {
defaultView: string;
center: Array<number>;
feeds: Array<Feed>;
zoomStarting: number;
zoomMin: number;
zoomMax: number;
bounds: Bounds | null;
lockBounds: boolean;
}
const defaults: Readonly<Options> = Object.freeze({
defaultView: '',
center: [35, -30],
feeds: [],
zoomStarting: 2,
zoomMin: 1,
zoomMax: 18,
bounds: null,
lockBounds: false,
})
export class PageBlockGeometry extends PageBlock {
readonly kind = kind
options: Options = { ...defaults }
static feedResources = Object.freeze({
record: 'compose:record',
})
constructor (i?: PageBlock | Partial<PageBlock>) {
super(i)
this.applyOptions(i?.options as Partial<Options>)
}
applyOptions (o?: Partial<Options>): void {
if (!o) return
this.options.feeds = (o.feeds || []).map(f => new Feed(f))
this.options.center = (o.center || [])
this.options.bounds = (o.bounds || null)
Apply(this.options, o, Number, 'zoomStarting', 'zoomMin', 'zoomMax')
Apply(this.options, o, Boolean, 'lockBounds')
}
static makeFeed (f?: FeedInput): Feed {
return new Feed(f)
}
static RecordFeed = RecordFeed
}
Registry.set(kind, PageBlockGeometry)
@@ -0,0 +1,3 @@
export const feedResources = {
record: 'compose:record',
}
@@ -15,6 +15,8 @@ export { PageBlockComment } from './comment'
export { PageBlockReport } from './report'
export { PageBlockProgress } from './progress'
export { PageBlockNylas } from './nylas'
export { PageBlockGeometry } from './geometry'
export function PageBlockMaker<T extends PageBlock> (i: { kind: string }): T {
const PageBlockTemp = Registry.get(i.kind)