@yandex/ymaps3-types
Version:
Types for ymaps3 maps library
70 lines (69 loc) • 2.93 kB
TypeScript
import type { LineStringGeometry, Margin, MultiLineStringGeometry, MultiPolygonGeometry, PointGeometry, PolygonGeometry, LngLat } from "../../common/types";
export interface DraggableProps<Callback> {
/** Feature can be draggable */
draggable?: boolean;
/** Will map center follows marker on drag if marker near the edge of the map */
mapFollowsOnDrag?: boolean | {
activeZoneMargin?: Margin;
};
/** Fires on drag start */
onDragStart?: Callback;
/**
* May be a function that will be called when the user drags and drops an element to a new location on the map.
* The arguments to the function will include the new coordinates.
* A component that uses this component should immediately save the new coordinates in its state and then use
* the new coordinates as props for the marker.
* */
onDragEnd?: Callback;
/** Fires on drag move */
onDragMove?: Callback;
}
export interface BlockingProps {
/**
* This parameter block all map events for the element.
* The map will no longer be able to respond to any {@link DomEvents} on this element, including clicks, double-clicks and others.
*/
blockEvents?: boolean;
/**
* This parameter block all map behaviors for the element.
* The element itself can be zoomed and scrolled by mouse and gestures.
* The map will no longer be able to respond to any {@link BehaviorType} on this element (except `dblClick`).
* Double clicks and other map events will be blocked by the {@link BlockingProps.blockEvents} parameter.
*/
blockBehaviors?: boolean;
}
export interface MapEvent {
/** [x, y] */
readonly screenCoordinates: [
number,
number
];
readonly coordinates: LngLat;
readonly details: Pick<MouseEvent | PointerEvent | TouchEvent, 'type' | 'shiftKey' | 'altKey' | 'metaKey'>;
stopPropagation(): void;
}
export interface FeatureClickEvents {
/** Double click handler */
onDoubleClick?: (event: MouseEvent, mapEvent: MapEvent) => void;
/** Click handler */
onClick?: (event: MouseEvent, mapEvent: MapEvent) => void;
/** Fast click handler */
onFastClick?: (event: MouseEvent, mapEvent: MapEvent) => void;
}
export type Geometry = PolygonGeometry | MultiPolygonGeometry | LineStringGeometry | MultiLineStringGeometry | PointGeometry;
/**
* Feature drag event handler.
* ```typescript
* function onDragEvent(type, coordinates) => {
* console.log('Event:', type, coordinates);
* };
* const feature = new YMapFeature({
* geometry: {...},
* draggable: true,
* onDragStart: onDragEvent.bind(null, 'dragStart'),
* onDragMove: onDragEvent.bind(null, 'dragMove'),
* onDragEnd: onDragEvent.bind(null, 'dragEnd'),
* });
* ```
*/
export type YMapFeatureEventHandler = (coordinates: Geometry['coordinates']) => void | false;