|
1 | 1 | import Style from 'Core/Style'; |
| 2 | +import { FEATURE_TYPES } from 'Core/Feature'; |
2 | 3 | import assert from 'assert'; |
3 | 4 | import Fetcher from 'Provider/Fetcher'; |
4 | 5 | import { TextureLoader } from 'three'; |
@@ -278,4 +279,85 @@ describe('Style', function () { |
278 | 279 | }); |
279 | 280 | }); |
280 | 281 | }); |
| 282 | + |
| 283 | + describe('setFromProperties', () => { |
| 284 | + it('FEATURE_TYPES.POINT', () => { |
| 285 | + const properties = { |
| 286 | + radius: 2, |
| 287 | + 'label-color': '#eba55f', |
| 288 | + 'icon-color': '#eba55f', |
| 289 | + }; |
| 290 | + const style = Style.setFromProperties(properties, FEATURE_TYPES.POINT); |
| 291 | + assert.equal(style.point.radius, 2); |
| 292 | + assert.equal(style.text.color, '#eba55f'); |
| 293 | + assert.equal(style.icon.color, '#eba55f'); |
| 294 | + }); |
| 295 | + it('FEATURE_TYPES.POLYGON', () => { |
| 296 | + const properties = { |
| 297 | + fill: '#eba55f', |
| 298 | + stroke: '#eba55f', |
| 299 | + }; |
| 300 | + const style = Style.setFromProperties(properties, FEATURE_TYPES.POLYGON); |
| 301 | + assert.equal(style.stroke.color, '#eba55f'); |
| 302 | + assert.equal(style.fill.color, '#eba55f'); |
| 303 | + }); |
| 304 | + }); |
| 305 | + |
| 306 | + describe('setFromVectorTileLayer', () => { |
| 307 | + describe("layer.type==='fill'", () => { |
| 308 | + const imgId = 'filler'; |
| 309 | + const vectorTileLayer = { |
| 310 | + type: 'fill', |
| 311 | + paint: { |
| 312 | + 'fill-pattern': imgId, |
| 313 | + 'fill-outline-color': '#eba55f', |
| 314 | + }, |
| 315 | + }; |
| 316 | + it('with fill-pattern (and sprites)', () => { |
| 317 | + const sprites = { |
| 318 | + filler: { x: 0, y: 0, width: 0, height: 0, pixelRatio: 1 }, |
| 319 | + source: 'ImgUrl', |
| 320 | + }; |
| 321 | + const style = Style.setFromVectorTileLayer(vectorTileLayer, sprites); |
| 322 | + // fill-pattern |
| 323 | + assert.equal(style.fill.pattern.id, imgId); |
| 324 | + assert.equal(style.fill.pattern.cropValues, sprites[imgId]); |
| 325 | + }); |
| 326 | + it('without fill-pattern (or sprites)', () => { |
| 327 | + const style = Style.setFromVectorTileLayer(vectorTileLayer); |
| 328 | + // fill-outline-color |
| 329 | + assert.equal(style.stroke.color, '#eba55f'); |
| 330 | + }); |
| 331 | + }); |
| 332 | + it("layer.type==='line'", () => { |
| 333 | + const vectorTileLayer = { |
| 334 | + type: 'line', |
| 335 | + paint: { |
| 336 | + 'line-color': '#eba55f', |
| 337 | + }, |
| 338 | + }; |
| 339 | + const style = Style.setFromVectorTileLayer(vectorTileLayer); |
| 340 | + assert.equal(style.stroke.color, '#eba55f'); |
| 341 | + }); |
| 342 | + it("layer.type==='circle'", () => { |
| 343 | + const vectorTileLayer = { |
| 344 | + type: 'circle', |
| 345 | + paint: { |
| 346 | + 'circle-color': '#eba55f', |
| 347 | + }, |
| 348 | + }; |
| 349 | + const style = Style.setFromVectorTileLayer(vectorTileLayer); |
| 350 | + assert.equal(style.point.color, '#eba55f'); |
| 351 | + }); |
| 352 | + it("layer.type==='symbol'", () => { |
| 353 | + const vectorTileLayer = { |
| 354 | + type: 'symbol', |
| 355 | + layout: { |
| 356 | + 'symbol-z-order': 'auto', |
| 357 | + }, |
| 358 | + }; |
| 359 | + const style = Style.setFromVectorTileLayer(vectorTileLayer); |
| 360 | + assert.equal(style.text.zOrder, 'Y'); |
| 361 | + }); |
| 362 | + }); |
281 | 363 | }); |
0 commit comments