GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
86 stars 25 forks source link

Cluster style parser and spread. #1331

Closed dbauszus-glx closed 6 days ago

dbauszus-glx commented 1 week ago

Working on the cluster and icon scaling plugin we noticed a couple of small issues in regards to the cluster style assignment.

The style.cluster must be spread into the feature.style object to preserve cluster scaling properties.

The logScale is a cluster property not a layer.style property.

The zoomOutScale must be used for the zoomOutScale, not the zoomInScale.

The scale key must not be removed outside the icon in the style.default.

A warning should be issued for the keys which are removed.

    Object.keys(layer.style.default)
      .filter(key => !['icon', 'scale'].includes(key))
      .forEach(key => {

        console.warn(`Cluster Layer: ${layer.key}; ${key} key removed from default style.`)

        delete layer.style.default[key]
      })

The a scale maybe inside and outside an icon. These are all valid.

{
  scale: 2,
  icon: {
    type: 'dot'
  }
},
{
  icon: {
    scale: 3,
    type: 'dot'
  }
},
{
  scale: 0.5,
  icon: {
    scale: 2,
    type: 'dot'
  }
},
{
  scale: 0.5,
  icon: [{
    scale: 1,
    type: 'dot',
    color: 'red'
  },{
    scale: 2,
    type: 'dot',
    color: 'blue'
  }]
},
RobAndrewHurst commented 1 week ago

I have updated the tests for the styleParse module.

The check for if keys other than icon and scale occurring in the style.default object is still failing as bogus keys are not being removed.

it('should remove keys that are not in the default icon object', () => {
    const layer = {
      format: 'wkt',
      key: 'test-layer',
      style: {
        default: {
          testkey: 'test',
          icon: {
            type: 'target',
            fillColor: '#000000',
          }
        }
      }
    };

    styleParser(layer);

    const expected = {
      format: 'wkt',
      key: 'test-layer',
      style: {
        default: {
          icon: {
            type: 'target',
            fillColor: '#000000',
          }
        },
        'highlight': { 'zIndex': null }

      }
    }

    // Non-icon key should be removed 
    assertFalse('testkey' in layer.style.default, 'There should be no other keys other than icon and scale in the default style');
  });
dbauszus-glx commented 1 week ago

Spreading the style should retain the scale property.

https://github.com/GEOLYTIX/xyz/pull/1331/commits/83df594731b8594ff4e61694d6513975e5dd77e5