/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
///
import { Marker, MarkerOptions } from './marker';
import type { Attributes } from './marker-attributes';
/**
* Markers in a collection can have additional (virtual) attributes that are
* defined here.
*/
export type CollectionMarkerAttributes = Attributes & {
/**
* The key function used to create string ids for the records in the
* collection. Specifying this function is highly recommended when the data
* needs to be updated.
*/
key: (data: TUserData) => string;
};
export type MarkerCollectionOptions = {
map?: google.maps.Map | null;
} & Partial>;
/**
* The MarkerCollection provides bindings between an array of arbitrary records
* and the corresponding markers.
*
* - Attributes: attributes are shared with all markers, for the
* position-attribute this has to be a dynamic attribute, all other attributes
* could be either static or dynamic attributes.
* - Data-updates: data in the collection can be updated after creation. This will
* assume that complete sets of records are passed on every update. If
* incremental updates are needed, those have to be applied to the data before
* updating the marker collection. When transitions are implemented (also for
* performance reasons), it will become important to recognize identical
* records, so those can be updated instead of re-created with every update.
*
* @example
* const myData = [{position: [10, 53.5]}, {position: [-110, 23]}];
*
* const markers = new MarkerCollection(myData, {
* position: ({data}) => data.position
* });
*
* markers.map = map;
*/
export declare class MarkerCollection {
/** The map instance the markers are added to. */
private map_;
/** The markers, stored by their keys */
private markers_;
/** The shared marker-attributes. */
private markerAttributes_;
/**
* When a key-function is missing, unique keys are automatically generated. In
* case the same objects are passed into setData() again, the generated keys
* can be looked up in this map.
*/
private generatedKeyCache_;
/**
* The key function used to create string ids for the records in the
* collection. Specifying this function is highly recommended when the data
* needs to be updated.
*/
key?: (data: TUserData) => string;
/**
* Creates a new MarkerCollection without specifying the data yet. This could
* be useful since fetching the data typically happens at a different time
* Providing data when creating the marker-collection is optional.
*
* @param options
*/
constructor(options: MarkerCollectionOptions);
/**
* Creates a new MarkerCollection with existing data.
*
* @param data
* @param options
*/
constructor(data: TUserData[], options: MarkerCollectionOptions);
/** Returns the Google Map instance this collection was added to. */
get map(): google.maps.Map | null;
/**
* Adds this collection to the specified map instance. This will add all
* markers to the map.
*/
set map(map: google.maps.Map | null);
/**
* Sets or updates the data for this collection. When updating data, the
* implementation will use the key-function provided with the Options to
* detrmine which records were added, removed or changed and update the
* underlying marker instances accordingly.
*
* @param data
*/
setData(data: TUserData[]): void;
/**
* Sets the attributes for all markers.
*
* @param attributes
*/
setAttributes(attributes: Partial>): void;
/**
* Generates a key for the passed user-data record. This implementation calls
* the key-function if specified or generates a random key and stores it.
*
* @param record
*/
protected generateKey(record: TUserData): string;
/**
* Creates a new Marker with the specified options and data.
*
* @param options
* @param data
*/
protected createMarker(options: MarkerOptions, data: TUserData): Marker;
}