@mappedin/events
v6.9.1-beta.0
Published
An extension for [Mappedin JS](https://www.npmjs.com/package/@mappedin/mappedin-js) that supports CMS events.
Readme
@mappedin/events
An extension for Mappedin JS that supports CMS events.
Usage
Installation
With NPM:
npm install @mappedin/eventsWith Yarn:
yarn add @mappedin/eventsGetting Started
import { show3dMap, Marker } from '@mappedin/mappedin-js';
import { EventsManager } from '@mappedin/events';
const mapData = await getMapData(...);
// Create an EventManager to load and read event data
const em = new EventsManager(mapData);
// Use Promise.all() to reduce sequential load time
const [mapView] = await Promise.all([show3dMap(...), em.load()]);
// Read all events
for (const event of em.events) {
// Add event markers to all spaces that have events
const target = event.location?.spaces[0];
mapView.Markers.add(target, `<div>${event.name}</div>`);
}Options
/**
* Options for the {@link EventsManager}.
*/
export type EventsManagerOptions = Partial<{
/**
* The fields to fetch for each event.
*
* @default fields id, name, type, startDate, endDate, externalId, description, location, image, video
*/
fields: string[];
/**
* Whether to include past or expired events.
*
* @default false
*/
includeExpired: boolean;
}>;Methods
class EventsManager {
/**
* Whether load() has been called and successfully completed.
*/
get ready(): boolean;
/**
* All current and future events that have been loaded. Will be empty if load() has not been called.
*/
get events(): EventMetaData[];
/**
* Load all the events for the map.
*/
async load(): void;
/**
* Get an event by ID.
*/
getById(id: string): EventMetaData | undefined;
/**
* Get an array of events attached to an EnterpriseLocation.
*/
getByLocationId(locationId: string): EventMetaData[];
/**
* Clean up the EventsManager instance.
*/
destroy(): void;
}