UNPKG

15.8 kBTypeScriptView Raw
1import { Type } from './centerconstraint';
2import { Coordinate } from './coordinate';
3import { EventsKey } from './events';
4import BaseEvent from './events/Event';
5import { Extent } from './extent';
6import SimpleGeometry from './geom/SimpleGeometry';
7import BaseObject, { ObjectEvent } from './Object';
8import { Pixel } from './pixel';
9import { ProjectionLike } from './proj';
10import Projection from './proj/Projection';
11import { Type as Type_1 } from './resolutionconstraint';
12import { Type as Type_2 } from './rotationconstraint';
13import { Size } from './size';
14import ViewHint from './ViewHint';
15
16/**
17 * An animation configuration
18 */
19export interface Animation {
20 sourceCenter?: Coordinate | undefined;
21 targetCenter?: Coordinate | undefined;
22 sourceResolution?: number | undefined;
23 targetResolution?: number | undefined;
24 sourceRotation?: number | undefined;
25 targetRotation?: number | undefined;
26 anchor?: Coordinate | undefined;
27 start: number;
28 duration: number;
29 complete: boolean;
30 easing: (p0: number) => number;
31 callback: (p0: boolean) => void;
32}
33export interface AnimationOptions {
34 center?: Coordinate | undefined;
35 zoom?: number | undefined;
36 resolution?: number | undefined;
37 rotation?: number | undefined;
38 anchor?: Coordinate | undefined;
39 duration?: number | undefined;
40 easing?: ((p0: number) => number) | undefined;
41}
42export interface Constraints {
43 center: Type;
44 resolution: Type_1;
45 rotation: Type_2;
46}
47export interface FitOptions {
48 size?: Size | undefined;
49 padding?: number[] | undefined;
50 nearest?: boolean | undefined;
51 minResolution?: number | undefined;
52 maxZoom?: number | undefined;
53 duration?: number | undefined;
54 easing?: ((p0: number) => number) | undefined;
55 callback?: ((p0: boolean) => void) | undefined;
56}
57export interface State {
58 center: Coordinate;
59 projection: Projection;
60 resolution: number;
61 rotation: number;
62 zoom: number;
63}
64export interface ViewOptions {
65 center?: Coordinate | undefined;
66 constrainRotation?: boolean | number | undefined;
67 enableRotation?: boolean | undefined;
68 extent?: Extent | undefined;
69 constrainOnlyCenter?: boolean | undefined;
70 smoothExtentConstraint?: boolean | undefined;
71 maxResolution?: number | undefined;
72 minResolution?: number | undefined;
73 maxZoom?: number | undefined;
74 minZoom?: number | undefined;
75 multiWorld?: boolean | undefined;
76 constrainResolution?: boolean | undefined;
77 smoothResolutionConstraint?: boolean | undefined;
78 showFullExtent?: boolean | undefined;
79 projection?: ProjectionLike | undefined;
80 resolution?: number | undefined;
81 resolutions?: number[] | undefined;
82 rotation?: number | undefined;
83 zoom?: number | undefined;
84 zoomFactor?: number | undefined;
85 padding?: number[] | undefined;
86}
87export default class View extends BaseObject {
88 constructor(opt_options?: ViewOptions);
89 /**
90 * Padding (in css pixels).
91 * If the map viewport is partially covered with other content (overlays) along
92 * its edges, this setting allows to shift the center of the viewport away from that
93 * content. The order of the values in the array is top, right, bottom, left.
94 * The default is no padding, which is equivalent to [0, 0, 0, 0].
95 */
96 padding: number[];
97 /**
98 * Adds relative coordinates to the center of the view. Any extent constraint will apply.
99 */
100 adjustCenter(deltaCoordinates: Coordinate): void;
101 /**
102 * Adds relative coordinates to the center of the view. Any extent constraint will apply.
103 */
104 adjustCenterInternal(deltaCoordinates: Coordinate): void;
105 /**
106 * Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
107 * constraint will apply.
108 */
109 adjustResolution(ratio: number, opt_anchor?: Coordinate): void;
110 /**
111 * Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
112 * constraint will apply.
113 */
114 adjustResolutionInternal(ratio: number, opt_anchor?: Coordinate): void;
115 /**
116 * Adds a value to the view rotation, optionally using an anchor. Any rotation
117 * constraint will apply.
118 */
119 adjustRotation(delta: number, opt_anchor?: Coordinate): void;
120 adjustRotationInternal(delta: number, opt_anchor?: Coordinate): void;
121 /**
122 * Adds a value to the view zoom level, optionally using an anchor. Any resolution
123 * constraint will apply.
124 */
125 adjustZoom(delta: number, opt_anchor?: Coordinate): void;
126 /**
127 * Animate the view. The view's center, zoom (or resolution), and rotation
128 * can be animated for smooth transitions between view states. For example,
129 * to animate the view to a new zoom level:
130 * <code>view.animate({zoom: view.getZoom() + 1});</code>By default, the animation lasts one second and uses in-and-out easing. You
131 * can customize this behavior by including duration (in milliseconds) and
132 * easing options (see {@link module:ol/easing}).
133 * To chain together multiple animations, call the method with multiple
134 * animation objects. For example, to first zoom and then pan:
135 * <code>view.animate({zoom: 10}, {center: [0, 0]});</code>If you provide a function as the last argument to the animate method, it
136 * will get called at the end of an animation series. The callback will be
137 * called with true if the animation series completed on its own or false
138 * if it was cancelled.
139 * Animations are cancelled by user interactions (e.g. dragging the map) or by
140 * calling view.setCenter(), view.setResolution(), or view.setRotation()
141 * (or another method that calls one of these).
142 */
143 animate(...var_args: (AnimationOptions | ((p0: boolean) => void))[]): void;
144 animateInternal(...var_args: (AnimationOptions | ((p0: boolean) => void))[]): void;
145 /**
146 * Set up the view with the given options.
147 */
148 applyOptions_(options: ViewOptions): void;
149 /**
150 * Notify the View that an interaction has started.
151 * The view state will be resolved to a stable one if needed
152 * (depending on its constraints).
153 */
154 beginInteraction(): void;
155 calculateCenterRotate(rotation: number, anchor: Coordinate): Coordinate | undefined;
156 /**
157 * Calculates the shift between map and viewport center.
158 */
159 calculateCenterShift(center: Coordinate, resolution: number, rotation: number, size: Size): number[] | undefined;
160 calculateCenterZoom(resolution: number, anchor: Coordinate): Coordinate | undefined;
161 /**
162 * Calculate the extent for the current view state and the passed size.
163 * The size is the pixel dimensions of the box into which the calculated extent
164 * should fit. In most cases you want to get the extent of the entire map,
165 * that is map.getSize().
166 */
167 calculateExtent(opt_size?: Size): Extent;
168 calculateExtentInternal(opt_size?: Size): Extent;
169 /**
170 * Cancel any ongoing animations.
171 */
172 cancelAnimations(): void;
173 /**
174 * Center on coordinate and view position.
175 */
176 centerOn(coordinate: Coordinate, size: Size, position: Pixel): void;
177 centerOnInternal(coordinate: Coordinate, size: Size, position: Pixel): void;
178 /**
179 * Notify the View that an interaction has ended. The view state will be resolved
180 * to a stable one if needed (depending on its constraints).
181 */
182 endInteraction(opt_duration?: number, opt_resolutionDirection?: number, opt_anchor?: Coordinate): void;
183 /**
184 * Notify the View that an interaction has ended. The view state will be resolved
185 * to a stable one if needed (depending on its constraints).
186 */
187 endInteractionInternal(opt_duration?: number, opt_resolutionDirection?: number, opt_anchor?: Coordinate): void;
188 /**
189 * Fit the given geometry or extent based on the given map size and border.
190 * The size is pixel dimensions of the box to fit the extent into.
191 * In most cases you will want to use the map size, that is map.getSize().
192 * Takes care of the map angle.
193 */
194 fit(geometryOrExtent: SimpleGeometry | Extent, opt_options?: FitOptions): void;
195 fitInternal(geometry: SimpleGeometry, opt_options?: FitOptions): void;
196 /**
197 * Determine if the view is being animated.
198 */
199 getAnimating(): boolean;
200 /**
201 * Get the view center.
202 */
203 getCenter(): Coordinate | undefined;
204 /**
205 * Get the view center without transforming to user projection.
206 */
207 getCenterInternal(): Coordinate | undefined;
208 /**
209 * Get a valid position for the view center according to the current constraints.
210 */
211 getConstrainedCenter(targetCenter: Coordinate | undefined, opt_targetResolution?: number): Coordinate | undefined;
212 /**
213 * Get a valid resolution according to the current view constraints.
214 */
215 getConstrainedResolution(targetResolution: number | undefined, opt_direction?: number): number | undefined;
216 /**
217 * Get a valid zoom level according to the current view constraints.
218 */
219 getConstrainedZoom(targetZoom: number | undefined, opt_direction?: number): number | undefined;
220 getConstrainResolution(): boolean;
221 getConstraints(): Constraints;
222 getHints(opt_hints?: number[]): number[];
223 /**
224 * Determine if the user is interacting with the view, such as panning or zooming.
225 */
226 getInteracting(): boolean;
227 /**
228 * Get the maximum resolution of the view.
229 */
230 getMaxResolution(): number;
231 /**
232 * Get the maximum zoom level for the view.
233 */
234 getMaxZoom(): number;
235 /**
236 * Get the minimum resolution of the view.
237 */
238 getMinResolution(): number;
239 /**
240 * Get the minimum zoom level for the view.
241 */
242 getMinZoom(): number;
243 /**
244 * Get the view projection.
245 */
246 getProjection(): Projection;
247 /**
248 * Get the view resolution.
249 */
250 getResolution(): number | undefined;
251 /**
252 * Get the resolution for a provided extent (in map units) and size (in pixels).
253 */
254 getResolutionForExtent(extent: Extent, opt_size?: Size): number;
255 /**
256 * Get the resolution for a provided extent (in map units) and size (in pixels).
257 */
258 getResolutionForExtentInternal(extent: Extent, opt_size?: Size): number;
259 /**
260 * Return a function that returns a value between 0 and 1 for a
261 * resolution. Exponential scaling is assumed.
262 */
263 getResolutionForValueFunction(opt_power?: number): (p0: number) => number;
264 /**
265 * Get the resolution for a zoom level.
266 */
267 getResolutionForZoom(zoom: number): number;
268 /**
269 * Get the resolutions for the view. This returns the array of resolutions
270 * passed to the constructor of the View, or undefined if none were given.
271 */
272 getResolutions(): number[] | undefined;
273 /**
274 * Get the view rotation.
275 */
276 getRotation(): number;
277 getState(): State;
278 /**
279 * Get an updated version of the view options used to construct the view. The
280 * current resolution (or zoom), center, and rotation are applied to any stored
281 * options. The provided options can be used to apply new min/max zoom or
282 * resolution limits.
283 */
284 getUpdatedOptions_(newOptions: ViewOptions): ViewOptions;
285 /**
286 * Return a function that returns a resolution for a value between
287 * 0 and 1. Exponential scaling is assumed.
288 */
289 getValueForResolutionFunction(opt_power?: number): (p0: number) => number;
290 /**
291 * Get the current zoom level. This method may return non-integer zoom levels
292 * if the view does not constrain the resolution, or if an interaction or
293 * animation is underway.
294 */
295 getZoom(): number | undefined;
296 /**
297 * Get the zoom level for a resolution.
298 */
299 getZoomForResolution(resolution: number): number | undefined;
300 isDef(): boolean;
301 /**
302 * If any constraints need to be applied, an animation will be triggered.
303 * This is typically done on interaction end.
304 * Note: calling this with a duration of 0 will apply the constrained values straight away,
305 * without animation.
306 */
307 resolveConstraints(opt_duration?: number, opt_resolutionDirection?: number, opt_anchor?: Coordinate): void;
308 /**
309 * Set the center of the current view. Any extent constraint will apply.
310 */
311 setCenter(center: Coordinate | undefined): void;
312 /**
313 * Set the center using the view projection (not the user projection).
314 */
315 setCenterInternal(center: Coordinate | undefined): void;
316 /**
317 * Set whether the view shoud allow intermediary zoom levels.
318 */
319 setConstrainResolution(enabled: boolean): void;
320 setHint(hint: ViewHint, delta: number): number;
321 /**
322 * Set a new maximum zoom level for the view.
323 */
324 setMaxZoom(zoom: number): void;
325 /**
326 * Set a new minimum zoom level for the view.
327 */
328 setMinZoom(zoom: number): void;
329 /**
330 * Set the resolution for this view. Any resolution constraint will apply.
331 */
332 setResolution(resolution: number | undefined): void;
333 /**
334 * Set the rotation for this view. Any rotation constraint will apply.
335 */
336 setRotation(rotation: number): void;
337 /**
338 * Stores the viewport size on the view. The viewport size is not read every time from the DOM
339 * to avoid performance hit and layout reflow.
340 * This should be done on map size change.
341 * Note: the constraints are not resolved during an animation to avoid stopping it
342 */
343 setViewportSize(opt_size?: Size): void;
344 /**
345 * Zoom to a specific zoom level. Any resolution constrain will apply.
346 */
347 setZoom(zoom: number): void;
348 /**
349 * Update all animations.
350 */
351 updateAnimations_(): void;
352 on(type: string | string[], listener: (p0: any) => any): EventsKey | EventsKey[];
353 once(type: string | string[], listener: (p0: any) => any): EventsKey | EventsKey[];
354 un(type: string | string[], listener: (p0: any) => any): void;
355 on(type: 'change', listener: (evt: BaseEvent) => void): EventsKey;
356 once(type: 'change', listener: (evt: BaseEvent) => void): EventsKey;
357 un(type: 'change', listener: (evt: BaseEvent) => void): void;
358 on(type: 'change:center', listener: (evt: ObjectEvent) => void): EventsKey;
359 once(type: 'change:center', listener: (evt: ObjectEvent) => void): EventsKey;
360 un(type: 'change:center', listener: (evt: ObjectEvent) => void): void;
361 on(type: 'change:resolution', listener: (evt: ObjectEvent) => void): EventsKey;
362 once(type: 'change:resolution', listener: (evt: ObjectEvent) => void): EventsKey;
363 un(type: 'change:resolution', listener: (evt: ObjectEvent) => void): void;
364 on(type: 'change:rotation', listener: (evt: ObjectEvent) => void): EventsKey;
365 once(type: 'change:rotation', listener: (evt: ObjectEvent) => void): EventsKey;
366 un(type: 'change:rotation', listener: (evt: ObjectEvent) => void): void;
367 on(type: 'error', listener: (evt: BaseEvent) => void): EventsKey;
368 once(type: 'error', listener: (evt: BaseEvent) => void): EventsKey;
369 un(type: 'error', listener: (evt: BaseEvent) => void): void;
370 on(type: 'propertychange', listener: (evt: ObjectEvent) => void): EventsKey;
371 once(type: 'propertychange', listener: (evt: ObjectEvent) => void): EventsKey;
372 un(type: 'propertychange', listener: (evt: ObjectEvent) => void): void;
373}
374export function createCenterConstraint(options: ViewOptions): Type;
375export function createResolutionConstraint(options: ViewOptions): any;
376export function createRotationConstraint(options: ViewOptions): Type_2;
377/**
378 * Determine if an animation involves no view change.
379 */
380export function isNoopAnimation(animation: Animation): boolean;