|
| 1 | +/** |
| 2 | + * @typedef {Object} Options |
| 3 | + * @property {string} styleUrl The URL of the Mapbox style object to use for this layer. For a |
| 4 | + * style created with Mapbox Studio and hosted on Mapbox, this will look like |
| 5 | + * 'mapbox://styles/you/your-style'. |
| 6 | + * @property {string} [accessToken] The access token for your Mapbox style. This has to be provided |
| 7 | + * for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query |
| 8 | + * parameter of the style url. |
| 9 | + * @property {string} [source] If your style uses more than one source, you need to use either the |
| 10 | + * `source` property or the `layers` property to limit rendering to a single vector source. The |
| 11 | + * `source` property corresponds to the id of a vector source in your Mapbox style. |
| 12 | + * @property {Array<string>} [layers] Limit rendering to the list of included layers. All layers |
| 13 | + * must share the same vector source. If your style uses more than one source, you need to use |
| 14 | + * either the `source` property or the `layers` property to limit rendering to a single vector |
| 15 | + * source. |
| 16 | + * @property {boolean} [declutter=true] Declutter images and text. Decluttering is applied to all |
| 17 | + * image and text styles of all Vector and VectorTile layers that have set this to `true`. The priority |
| 18 | + * is defined by the z-index of the layer, the `zIndex` of the style and the render order of features. |
| 19 | + * Higher z-index means higher priority. Within the same z-index, a feature rendered before another has |
| 20 | + * higher priority. |
| 21 | + * |
| 22 | + * As an optimization decluttered features from layers with the same `className` are rendered above |
| 23 | + * the fill and stroke styles of all of those layers regardless of z-index. To opt out of this |
| 24 | + * behavior and place declutterd features with their own layer configure the layer with a `className` |
| 25 | + * other than `ol-layer`. |
| 26 | + * @property {import("ol/layer/Base.js").BackgroundColor|false} [background] Background color for the layer. |
| 27 | + * If not specified, the background from the Mapbox style object will be used. Set to `false` to prevent |
| 28 | + * the Mapbox style's background from being used. |
| 29 | + * @property {string} [className='ol-layer'] A CSS class name to set to the layer element. |
| 30 | + * @property {number} [opacity=1] Opacity (0, 1). |
| 31 | + * @property {boolean} [visible=true] Visibility. |
| 32 | + * @property {import("ol/extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be |
| 33 | + * rendered outside of this extent. |
| 34 | + * @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers |
| 35 | + * will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed |
| 36 | + * for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()` |
| 37 | + * method was used. |
| 38 | + * @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be |
| 39 | + * visible. |
| 40 | + * @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will |
| 41 | + * be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `maxResolution` will |
| 42 | + * match the style source's `minzoom`. |
| 43 | + * @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will |
| 44 | + * be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `minZoom` will match |
| 45 | + * the style source's `minzoom`. |
| 46 | + * @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will |
| 47 | + * be visible. |
| 48 | + * @property {import("ol/render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting |
| 49 | + * features before rendering. By default features are drawn in the order that they are created. Use |
| 50 | + * `null` to avoid the sort, but get an undefined draw order. |
| 51 | + * @property {number} [renderBuffer=100] The buffer in pixels around the tile extent used by the |
| 52 | + * renderer when getting features from the vector tile for the rendering or hit-detection. |
| 53 | + * Recommended value: Vector tiles are usually generated with a buffer, so this value should match |
| 54 | + * the largest possible buffer of the used tiles. It should be at least the size of the largest |
| 55 | + * point symbol or line width. |
| 56 | + * @property {import("ol/layer/VectorTile.js").VectorTileRenderType} [renderMode='hybrid'] Render mode for vector tiles: |
| 57 | + * * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom |
| 58 | + * animations. Point symbols and texts are accurately rendered as vectors and can stay upright on |
| 59 | + * rotated views. |
| 60 | + * * `'vector'`: Everything is rendered as vectors. Use this mode for improved performance on vector |
| 61 | + * tile layers with only a few rendered features (e.g. for highlighting a subset of features of |
| 62 | + * another layer with the same source). |
| 63 | + * @property {import("ol/Map.js").default} [map] Sets the layer as overlay on a map. The map will not manage |
| 64 | + * this layer in its layers collection, and the layer will be rendered on top. This is useful for |
| 65 | + * temporary layers. The standard way to add a layer to a map and have it managed by the map is to |
| 66 | + * use `map.addLayer()`. |
| 67 | + * @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will be |
| 68 | + * recreated during animations. This means that no vectors will be shown clipped, but the setting |
| 69 | + * will have a performance impact for large amounts of vector data. When set to `false`, batches |
| 70 | + * will be recreated when no animation is active. |
| 71 | + * @property {boolean} [updateWhileInteracting=false] When set to `true`, feature batches will be |
| 72 | + * recreated during interactions. See also `updateWhileAnimating`. |
| 73 | + * @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0` |
| 74 | + * means no preloading. |
| 75 | + * @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error. |
| 76 | + * @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`. |
| 77 | + */ |
| 78 | +/** |
| 79 | + * @classdesc |
| 80 | + * ```js |
| 81 | + * import {MapboxVectorLayer} from 'ol-mapbox-style'; |
| 82 | + * ``` |
| 83 | + * A vector tile layer based on a Mapbox style that uses a single vector source. Configure |
| 84 | + * the layer with the `styleUrl` and `accessToken` shown in Mapbox Studio's share panel. |
| 85 | + * If the style uses more than one source, use the `source` property to choose a single |
| 86 | + * vector source. If you want to render a subset of the layers in the style, use the `layers` |
| 87 | + * property (all layers must share the same vector source). See the constructor options for |
| 88 | + * more detail. |
| 89 | + * |
| 90 | + * const map = new Map({ |
| 91 | + * view: new View({ |
| 92 | + * center: [0, 0], |
| 93 | + * zoom: 1, |
| 94 | + * }), |
| 95 | + * layers: [ |
| 96 | + * new MapboxVectorLayer({ |
| 97 | + * styleUrl: 'mapbox://styles/mapbox/bright-v9', |
| 98 | + * accessToken: 'your-mapbox-access-token-here', |
| 99 | + * }), |
| 100 | + * ], |
| 101 | + * target: 'map', |
| 102 | + * }); |
| 103 | + * |
| 104 | + * On configuration or loading error, the layer will trigger an `'error'` event. Listeners |
| 105 | + * will receive an object with an `error` property that can be used to diagnose the problem. |
| 106 | + * |
| 107 | + * **Note for users of the full build**: The `MapboxVectorLayer` requires the |
| 108 | + * [ol-mapbox-style](https://github.com/openlayers/ol-mapbox-style) library to be loaded as well. |
| 109 | + * |
| 110 | + * @param {Options} options Options. |
| 111 | + * @extends {VectorTileLayer} |
| 112 | + * @fires module:ol/events/Event~BaseEvent#event:error |
| 113 | + * @api |
| 114 | + */ |
| 115 | +export default class MapboxVectorLayer extends VectorTileLayer { |
| 116 | + /** |
| 117 | + * @param {Options} options Layer options. At a minimum, `styleUrl` and `accessToken` |
| 118 | + * must be provided. |
| 119 | + */ |
| 120 | + constructor(options: Options); |
| 121 | + accessToken: string | undefined; |
| 122 | +} |
| 123 | +export type Map = import("ol/Map.js").default; |
| 124 | +export type Options = { |
| 125 | + /** |
| 126 | + * The URL of the Mapbox style object to use for this layer. For a |
| 127 | + * style created with Mapbox Studio and hosted on Mapbox, this will look like |
| 128 | + * 'mapbox://styles/you/your-style'. |
| 129 | + */ |
| 130 | + styleUrl: string; |
| 131 | + /** |
| 132 | + * The access token for your Mapbox style. This has to be provided |
| 133 | + * for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query |
| 134 | + * parameter of the style url. |
| 135 | + */ |
| 136 | + accessToken?: string | undefined; |
| 137 | + /** |
| 138 | + * If your style uses more than one source, you need to use either the |
| 139 | + * `source` property or the `layers` property to limit rendering to a single vector source. The |
| 140 | + * `source` property corresponds to the id of a vector source in your Mapbox style. |
| 141 | + */ |
| 142 | + source?: string | undefined; |
| 143 | + /** |
| 144 | + * Limit rendering to the list of included layers. All layers |
| 145 | + * must share the same vector source. If your style uses more than one source, you need to use |
| 146 | + * either the `source` property or the `layers` property to limit rendering to a single vector |
| 147 | + * source. |
| 148 | + */ |
| 149 | + layers?: string[] | undefined; |
| 150 | + /** |
| 151 | + * Declutter images and text. Decluttering is applied to all |
| 152 | + * image and text styles of all Vector and VectorTile layers that have set this to `true`. The priority |
| 153 | + * is defined by the z-index of the layer, the `zIndex` of the style and the render order of features. |
| 154 | + * Higher z-index means higher priority. Within the same z-index, a feature rendered before another has |
| 155 | + * higher priority. |
| 156 | + * |
| 157 | + * As an optimization decluttered features from layers with the same `className` are rendered above |
| 158 | + * the fill and stroke styles of all of those layers regardless of z-index. To opt out of this |
| 159 | + * behavior and place declutterd features with their own layer configure the layer with a `className` |
| 160 | + * other than `ol-layer`. |
| 161 | + */ |
| 162 | + declutter?: boolean | undefined; |
| 163 | + /** |
| 164 | + * Background color for the layer. |
| 165 | + * If not specified, the background from the Mapbox style object will be used. Set to `false` to prevent |
| 166 | + * the Mapbox style's background from being used. |
| 167 | + */ |
| 168 | + background?: false | import("ol/layer/Base.js").BackgroundColor | undefined; |
| 169 | + /** |
| 170 | + * A CSS class name to set to the layer element. |
| 171 | + */ |
| 172 | + className?: string | undefined; |
| 173 | + /** |
| 174 | + * Opacity (0, 1). |
| 175 | + */ |
| 176 | + opacity?: number | undefined; |
| 177 | + /** |
| 178 | + * Visibility. |
| 179 | + */ |
| 180 | + visible?: boolean | undefined; |
| 181 | + /** |
| 182 | + * The bounding extent for layer rendering. The layer will not be |
| 183 | + * rendered outside of this extent. |
| 184 | + */ |
| 185 | + extent?: import("ol/extent.js").Extent | undefined; |
| 186 | + /** |
| 187 | + * The z-index for layer rendering. At rendering time, the layers |
| 188 | + * will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed |
| 189 | + * for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()` |
| 190 | + * method was used. |
| 191 | + */ |
| 192 | + zIndex?: number | undefined; |
| 193 | + /** |
| 194 | + * The minimum resolution (inclusive) at which this layer will be |
| 195 | + * visible. |
| 196 | + */ |
| 197 | + minResolution?: number | undefined; |
| 198 | + /** |
| 199 | + * The maximum resolution (exclusive) below which this layer will |
| 200 | + * be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `maxResolution` will |
| 201 | + * match the style source's `minzoom`. |
| 202 | + */ |
| 203 | + maxResolution?: number | undefined; |
| 204 | + /** |
| 205 | + * The minimum view zoom level (exclusive) above which this layer will |
| 206 | + * be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `minZoom` will match |
| 207 | + * the style source's `minzoom`. |
| 208 | + */ |
| 209 | + minZoom?: number | undefined; |
| 210 | + /** |
| 211 | + * The maximum view zoom level (inclusive) at which this layer will |
| 212 | + * be visible. |
| 213 | + */ |
| 214 | + maxZoom?: number | undefined; |
| 215 | + /** |
| 216 | + * Render order. Function to be used when sorting |
| 217 | + * features before rendering. By default features are drawn in the order that they are created. Use |
| 218 | + * `null` to avoid the sort, but get an undefined draw order. |
| 219 | + */ |
| 220 | + renderOrder?: import("ol/render.js").OrderFunction | undefined; |
| 221 | + /** |
| 222 | + * The buffer in pixels around the tile extent used by the |
| 223 | + * renderer when getting features from the vector tile for the rendering or hit-detection. |
| 224 | + * Recommended value: Vector tiles are usually generated with a buffer, so this value should match |
| 225 | + * the largest possible buffer of the used tiles. It should be at least the size of the largest |
| 226 | + * point symbol or line width. |
| 227 | + */ |
| 228 | + renderBuffer?: number | undefined; |
| 229 | + /** |
| 230 | + * Render mode for vector tiles: |
| 231 | + * * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom |
| 232 | + * animations. Point symbols and texts are accurately rendered as vectors and can stay upright on |
| 233 | + * rotated views. |
| 234 | + * * `'vector'`: Everything is rendered as vectors. Use this mode for improved performance on vector |
| 235 | + * tile layers with only a few rendered features (e.g. for highlighting a subset of features of |
| 236 | + * another layer with the same source). |
| 237 | + */ |
| 238 | + renderMode?: import("ol/layer/VectorTile.js").VectorTileRenderType | undefined; |
| 239 | + /** |
| 240 | + * Sets the layer as overlay on a map. The map will not manage |
| 241 | + * this layer in its layers collection, and the layer will be rendered on top. This is useful for |
| 242 | + * temporary layers. The standard way to add a layer to a map and have it managed by the map is to |
| 243 | + * use `map.addLayer()`. |
| 244 | + */ |
| 245 | + map?: import("ol/Map.js").default | undefined; |
| 246 | + /** |
| 247 | + * When set to `true`, feature batches will be |
| 248 | + * recreated during animations. This means that no vectors will be shown clipped, but the setting |
| 249 | + * will have a performance impact for large amounts of vector data. When set to `false`, batches |
| 250 | + * will be recreated when no animation is active. |
| 251 | + */ |
| 252 | + updateWhileAnimating?: boolean | undefined; |
| 253 | + /** |
| 254 | + * When set to `true`, feature batches will be |
| 255 | + * recreated during interactions. See also `updateWhileAnimating`. |
| 256 | + */ |
| 257 | + updateWhileInteracting?: boolean | undefined; |
| 258 | + /** |
| 259 | + * Preload. Load low-resolution tiles up to `preload` levels. `0` |
| 260 | + * means no preloading. |
| 261 | + */ |
| 262 | + preload?: number | undefined; |
| 263 | + /** |
| 264 | + * Use interim tiles on error. |
| 265 | + */ |
| 266 | + useInterimTilesOnError?: boolean | undefined; |
| 267 | + /** |
| 268 | + * Arbitrary observable properties. Can be accessed with `#get()` and `#set()`. |
| 269 | + */ |
| 270 | + properties?: { |
| 271 | + [x: string]: any; |
| 272 | + } | undefined; |
| 273 | +}; |
| 274 | +import VectorTileLayer from 'ol/layer/VectorTile.js'; |
0 commit comments