Skip to content

Commit 1adda41

Browse files
committed
【feature】支持match expression
1 parent d7807a7 commit 1adda41

File tree

8 files changed

+151
-189
lines changed

8 files changed

+151
-189
lines changed

Diff for: .editorconfig

-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,3 @@ insert_final_newline = true
1111
[*.md]
1212
indent_size = 2
1313
trim_trailing_whitespace = false
14-
15-
[Makefile]
16-
indent_style = tab
17-
indent_size = 4

Diff for: .eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"extends": "openlayers",
33
"globals": {
4-
Promise: false
4+
"Promise": false
55
},
66
"parserOptions": {
77
"ecmaVersion": 6,
8-
"sourceType": module
8+
"sourceType": "module"
99
}
1010
}

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
dist
33
coverage
4-
package-lock.json

Diff for: .npmrc

+8-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
package-lock=false
1+
.circleci/
2+
.git/
3+
examples/
4+
test/
5+
.editorconfig
6+
.eslintrc
7+
webpack.*.js
8+
tsconfig.*.json

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ the specified `source`, which needs to be a `"type": "vector"` or
175175
- `spriteImageUrl` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Sprite image url for the sprite
176176
specified in the Mapbox Style object's `sprite` property. Only required if a
177177
`sprite` property is specified in the Mapbox Style object. (optional, default `undefined`)
178+
- `spriteImage`
178179
- `fonts` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** Array of available fonts, using the
179180
same font names as the Mapbox Style object. If not provided, the style
180181
function will always use the first font from the font array. (optional, default `undefined`)

Diff for: index.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Copyright 2016-present Boundless Spatial, Inc.
44
License: https://raw.githubusercontent.com/boundlessgeo/ol-mapbox-gl-style/master/LICENSE
55
*/
66

7-
import glfun from '@mapbox/mapbox-gl-style-spec/function';
7+
import {Color} from '@mapbox/mapbox-gl-style-spec';
88
import mb2css from 'mapbox-to-css-font';
9-
import applyStyleFunction from './stylefunction';
9+
import applyStyleFunction, {getValue} from './stylefunction';
1010
import googleFonts from 'webfont-matcher/lib/fonts/google';
1111
import {fromLonLat} from 'ol/proj';
1212
import {createXYZ} from 'ol/tilegrid';
@@ -175,32 +175,29 @@ export function applyStyle(layer, glStyle, source, path, resolutions) {
175175
}
176176

177177
function setBackground(map, layer) {
178+
const background = {
179+
type: layer.type
180+
};
178181
function updateStyle() {
179182
var element = map.getTargetElement();
180183
if (!element) {
181184
return;
182185
}
183186
var layout = layer.layout || {};
184187
var paint = layer.paint || {};
188+
background['paint'] = paint;
189+
background.id = 'olms-bg-' + paint['background-opacity'] + paint['background-color'];
185190
var zoom = map.getView().getZoom();
186-
if ('background-color' in paint) {
187-
var bg = glfun(paint['background-color'], {function: 'interpolated', type: 'color'})(zoom);
188-
if (Array.isArray(bg)) {
189-
bg = 'rgba(' +
190-
Math.round(bg[0] * 255) + ',' +
191-
Math.round(bg[1] * 255) + ',' +
192-
Math.round(bg[2] * 255) + ',' +
193-
(bg[3] ? bg[3] : 1) + ')';
194-
}
195-
element.style.backgroundColor = bg;
191+
if (paint['background-color'] !== undefined) {
192+
const bg = getValue(background, 'paint', 'background-color', zoom, {});
193+
element.style.background = Color.parse(bg).toString();
196194
}
197-
if ('background-opacity' in paint) {
198-
element.style.backgroundOpacity =
199-
glfun(paint['background-opacity'], {function: 'interpolated', type: 'number'})(zoom);
195+
if (paint['background-opacity'] !== undefined) {
196+
element.style.opacity = getValue(background, 'paint', 'background-opacity', zoom, {});
200197
}
201198
if (layout.visibility == 'none') {
202199
element.style.backgroundColor = '';
203-
element.style.backgroundOpacity = '';
200+
element.style.opacity = '';
204201
}
205202
}
206203
if (map.getTargetElement()) {

Diff for: package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ol-mapbox-style",
3-
"version": "3.0.0-beta.7",
3+
"version": "2.11.2-1",
44
"description": "Create OpenLayers maps from Mapbox Style objects",
55
"main": "index.js",
66
"repository": {
@@ -71,8 +71,8 @@
7171
"cover": "jest --coverage"
7272
},
7373
"dependencies": {
74-
"@mapbox/mapbox-gl-style-spec": "^9.0.1",
75-
"mapbox-to-css-font": "^2.1.0",
74+
"@mapbox/mapbox-gl-style-spec": "^13.14.0",
75+
"mapbox-to-css-font": "^2.4.0",
7676
"webfont-matcher": "^1.1.0"
7777
},
7878
"peerDependencies": {
@@ -84,7 +84,6 @@
8484
"babel-jest": "^23.0.0-alpha.0",
8585
"babel-loader": "^7.1.4",
8686
"babel-preset-env": "^1.6.1",
87-
"canvas": "^1.6.8",
8887
"copy-webpack-plugin": "^4.5.1",
8988
"css-loader": "^0.28.11",
9089
"deep-freeze": "0.0.1",
@@ -104,9 +103,9 @@
104103
"should": "^11.2.1",
105104
"should-approximately-deep": "^1.1.0",
106105
"style-loader": "^0.20.3",
107-
"webpack": "^4.1.1",
108-
"webpack-cli": "^2.0.12",
109-
"webpack-dev-server": "^3.1.1"
106+
"webpack": "^4.41.3",
107+
"webpack-cli": "^3.3.10",
108+
"webpack-dev-server": "^3.9.0"
110109
},
111110
"jest": {
112111
"setupFiles": [

0 commit comments

Comments
 (0)