ol-mapbox-style
Advanced tools
Comparing version 2.8.4 to 2.9.0
35
index.js
@@ -177,5 +177,8 @@ /* | ||
function updateStyle() { | ||
var element = map.getTargetElement(); | ||
if (!element) { | ||
return; | ||
} | ||
var layout = layer.layout || {}; | ||
var paint = layer.paint || {}; | ||
var element = map.getTargetElement(); | ||
var zoom = map.getView().getZoom(); | ||
@@ -229,8 +232,9 @@ if ('background-color' in paint) { | ||
var hasView = true; | ||
function processStyle(glStyle, map, baseUrl, host, path, accessToken) { | ||
var view = map.getView(); | ||
if ('center' in glStyle && !view.getCenter()) { | ||
if ('center' in glStyle && !hasView) { | ||
view.setCenter(proj.fromLonLat(glStyle.center)); | ||
} | ||
if ('zoom' in glStyle && view.getZoom() == undefined) { | ||
if ('zoom' in glStyle && !hasView) { | ||
view.setZoom(glStyle.zoom); | ||
@@ -409,3 +413,20 @@ } | ||
/** | ||
* Loads and applies a Mapbox Style object to an OpenLayers Map. | ||
* Loads and applies a Mapbox Style object to an OpenLayers Map. This includes | ||
* the map background, the layers, the center and the zoom. | ||
* | ||
* The center and zoom will only be set if present in the Mapbox Style document, | ||
* and if not already set on the OpenLayers map. | ||
* | ||
* Layers will be added to the OpenLayers map, without affecting any layers that | ||
* might already be set on the map. | ||
* | ||
* Layers added by `apply()` will have two additional properties: | ||
* | ||
* * `mapbox-source`: The `id` of the Mapbox Style document's source that the | ||
* OpenLayers layer was created from. Usually `apply()` creates one | ||
* OpenLayers layer per Mapbox Style source, unless the layer stack has | ||
* layers from different sources in between. | ||
* * `mapbox-layers`: The `id`s of the Mapbox Style document's layers that are | ||
* included in the OpenLayers layer. | ||
* | ||
* @param {ol.Map|HTMLElement|string} map Either an existing OpenLayers Map | ||
@@ -418,2 +439,7 @@ * instance, or a HTML element, or the id of a HTML element that will be the | ||
* `https://api.mapbox.com/styles/v1/mapbox/bright-v9?access_token=[your_access_token_here]`. | ||
* When passed as JSON style object, all OpenLayers layers created by `apply()` | ||
* will be immediately available, but they may not have a source yet (i.e. when | ||
* they are defined by a TileJSON url in the Mapbox Style document). When passed | ||
* as style url, layers will be added to the map when the Mapbox Style docukment | ||
* is loaded and parsed. | ||
* @return {ol.Map} The OpenLayers Map instance that will be populated with the | ||
@@ -428,2 +454,3 @@ * contents described in the Mapbox Style object. | ||
if (!(map instanceof Map)) { | ||
hasView = false; | ||
map = new Map({ | ||
@@ -430,0 +457,0 @@ target: map |
{ | ||
"name": "ol-mapbox-style", | ||
"version": "2.8.4", | ||
"version": "2.9.0", | ||
"description": "Create OpenLayers maps from Mapbox Style objects", | ||
@@ -53,4 +53,4 @@ "main": "index.js", | ||
"mapbox-to-css-font": "^2.1.0", | ||
"mapbox-to-ol-style": "^3.2.5", | ||
"ol": "^4.5.0", | ||
"mapbox-to-ol-style": "^3.3.0", | ||
"ol": "^4.6.2", | ||
"webfont-matcher": "^1.1.0" | ||
@@ -57,0 +57,0 @@ }, |
@@ -61,4 +61,20 @@ # ol-mapbox-style | ||
Loads and applies a Mapbox Style object to an OpenLayers Map. | ||
Loads and applies a Mapbox Style object to an OpenLayers Map. This includes | ||
the map background, the layers, the center and the zoom. | ||
The center and zoom will only be set if present in the Mapbox Style document, | ||
and if not already set on the OpenLayers map. | ||
Layers will be added to the OpenLayers map, without affecting any layers that | ||
might already be set on the map. | ||
Layers added by `apply()` will have two additional properties: | ||
- `mapbox-source`: The `id` of the Mapbox Style document's source that the | ||
OpenLayers layer was created from. Usually `apply()` creates one | ||
OpenLayers layer per Mapbox Style source, unless the layer stack has | ||
layers from different sources in between. | ||
- `mapbox-layers`: The `id`s of the Mapbox Style document's layers that are | ||
included in the OpenLayers layer. | ||
**Parameters** | ||
@@ -73,2 +89,7 @@ | ||
`https://api.mapbox.com/styles/v1/mapbox/bright-v9?access_token=[your_access_token_here]`. | ||
When passed as JSON style object, all OpenLayers layers created by `apply()` | ||
will be immediately available, but they may not have a source yet (i.e. when | ||
they are defined by a TileJSON url in the Mapbox Style document). When passed | ||
as style url, layers will be added to the map when the Mapbox Style docukment | ||
is loaded and parsed. | ||
@@ -75,0 +96,0 @@ Returns **ol.Map** The OpenLayers Map instance that will be populated with the |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3085234
68816
102
Updatedmapbox-to-ol-style@^3.3.0
Updatedol@^4.6.2