checkFeatureMatchesStyleRule.ts 933 B

1234567891011121314151617181920212223242526272829
  1. import { FeatureLike } from 'ol/Feature';
  2. import { FeatureRuleConfig, ComparisonOperation } from '../types';
  3. /**
  4. * Check whether feature has property value that matches rule
  5. * @param rule - style rule with an operation, property, and value
  6. * @param feature - feature with properties and values
  7. * @returns boolean
  8. */
  9. export const checkFeatureMatchesStyleRule = (rule: FeatureRuleConfig, feature: FeatureLike) => {
  10. const val = feature.get(rule.property);
  11. switch (rule.operation) {
  12. case ComparisonOperation.EQ:
  13. return `${val}` === `${rule.value}`;
  14. case ComparisonOperation.NEQ:
  15. return val !== rule.value;
  16. case ComparisonOperation.GT:
  17. return val > rule.value;
  18. case ComparisonOperation.GTE:
  19. return val >= rule.value;
  20. case ComparisonOperation.LT:
  21. return val < rule.value;
  22. case ComparisonOperation.LTE:
  23. return val <= rule.value;
  24. default:
  25. return false;
  26. }
  27. };