|
| 1 | +import assert from 'assert'; |
| 2 | +import FeatureProcessing from 'Process/FeatureProcessing'; |
| 3 | +import LayerUpdateState from 'Layer/LayerUpdateState'; |
| 4 | +import Style from 'Core/Style'; |
| 5 | +import Feature2Mesh from 'Converter/Feature2Mesh'; |
| 6 | +import GeoJsonParser from 'Parser/GeoJsonParser'; |
| 7 | + |
| 8 | +import geojson from '../data/geojson/map.geojson'; |
| 9 | + |
| 10 | +describe('FeatureProcessing', function () { |
| 11 | + const parsed = GeoJsonParser.parse(geojson, { |
| 12 | + in: { crs: 'EPSG:4326' }, |
| 13 | + out: { crs: 'EPSG:4326', buildExtent: true, mergeFeatures: false, structure: '3d' }, |
| 14 | + }); |
| 15 | + |
| 16 | + it('should update style for child meshes when layer style changes', function (done) { |
| 17 | + parsed.then((collection) => { |
| 18 | + const style = new Style({ fill: { color: 'red' } }); |
| 19 | + const layer = { |
| 20 | + id: 'test-layer', |
| 21 | + object3d: { add: () => {} }, |
| 22 | + style, |
| 23 | + convert: Feature2Mesh.convert(), |
| 24 | + }; |
| 25 | + |
| 26 | + // Convert the collection to create feature meshes |
| 27 | + const featureNode = layer.convert.call(layer, collection); |
| 28 | + |
| 29 | + // Create mock node (tile) with feature attached |
| 30 | + const node = { |
| 31 | + parent: { id: 'parent' }, |
| 32 | + visible: true, |
| 33 | + layerUpdateState: {}, |
| 34 | + link: {}, |
| 35 | + }; |
| 36 | + node.layerUpdateState[layer.id] = new LayerUpdateState(); |
| 37 | + node.layerUpdateState[layer.id].canTryUpdate = () => false; |
| 38 | + node.link[layer.id] = [{ |
| 39 | + collection: featureNode.collection, |
| 40 | + meshes: featureNode.meshes, |
| 41 | + layer: { object3d: { add: () => {} } }, |
| 42 | + }]; |
| 43 | + |
| 44 | + const context = { view: {} }; |
| 45 | + |
| 46 | + // Get the child mesh and store initial version |
| 47 | + const childMesh1 = featureNode.meshes.children[0]; |
| 48 | + const colorAttr1 = childMesh1.geometry.getAttribute('color'); |
| 49 | + const initialColorVersion1 = colorAttr1.version; |
| 50 | + |
| 51 | + style.fill.color = 'blue'; |
| 52 | + FeatureProcessing.update(context, layer, node); |
| 53 | + |
| 54 | + // Verify color attributes were updated (version incremented) |
| 55 | + assert.ok(colorAttr1.version > initialColorVersion1); |
| 56 | + |
| 57 | + assert.strictEqual(colorAttr1.array[0], 0); |
| 58 | + assert.strictEqual(colorAttr1.array[1], 0); |
| 59 | + assert.strictEqual(colorAttr1.array[2], 255); |
| 60 | + done(); |
| 61 | + }).catch(done); |
| 62 | + }); |
| 63 | +}); |
0 commit comments