<commit_before>import {ImageWMS, TileWMS, XYZ} from 'ol/source';
export default {
  template: require('./layer-editor-dimensions.html'),
  bindings: {
    olLayer: '<',
  },
  controller: [
    '$scope',
    'hs.dimensionService',
    'hs.utils.service',
    function ($scope, dimensionService, utils) {
      const vm = this;
      angular.extend(vm, {
        dimensionType: dimensionService.dimensionType,

        /**
         * @function isLayerWithDimensions
         * @memberOf hs.layer-editor-dimensions
         * @description Test if layer has dimensions
         * @returns {Boolean} Returns if layers has any dimensions
         */
        isLayerWithDimensions() {
          const layer = vm.olLayer;
          if (angular.isUndefined(layer)) {
            return false;
          }
          if (angular.isUndefined(layer.get('dimensions'))) {
            return false;
          }
          return Object.keys(layer.get('dimensions')).length > 0;
        },

        dimensionChanged(dimension) {
          const src = vm.olLayer.getSource();
          if (utils.instOf(src, TileWMS) || utils.instOf(src, ImageWMS)) {
            const params = src.getParams();
            params[dimension.name] = dimension.value;
            src.updateParams(params);
          } else if (utils.instOf(src, XYZ)) {
            src.refresh();
          }
          $scope.$emit('layermanager.dimension_changed', {
            layer: vm.olLayer,
            dimension,
          });
        },

        dimensions() {
          const layer = vm.olLayer;
          if (angular.isUndefined(layer)) {
            return [];
          }
          return layer.get('dimensions');
        },
      });
    },
  ],
};<commit_msg>Support shared dimension between multiple layers<commit_after>import {ImageWMS, TileWMS, XYZ} from 'ol/source';
export default {
  template: require('./layer-editor-dimensions.html'),
  bindings: {
    olLayer: '<',
  },
  controller: [
    '$scope',
    'hs.dimensionService',
    'hs.utils.service',
    'hs.map.service',
    function ($scope, dimensionService, utils, hsMap) {
      const vm = this;
      angular.extend(vm, {
        dimensionType: dimensionService.dimensionType,

        /**
         * @function isLayerWithDimensions
         * @memberOf hs.layer-editor-dimensions
         * @description Test if layer has dimensions
         * @returns {Boolean} Returns if layers has any dimensions
         */
        isLayerWithDimensions() {
          const layer = vm.olLayer;
          if (angular.isUndefined(layer)) {
            return false;
          }
          if (angular.isUndefined(layer.get('dimensions'))) {
            return false;
          }
          return Object.keys(layer.get('dimensions')).length > 0;
        },

        dimensionChanged(dimension) {
          //Dimension can be linked to multiple layers
          hsMap.map.getLayers().forEach((layer) => {
            const iteratedDimensions = layer.get('dimensions');
            if (
              iteratedDimensions &&
              Object.keys(iteratedDimensions).filter(
                (dimensionIterator) =>
                  iteratedDimensions[dimensionIterator] == dimension
              ).length > 0 //Dimension also linked to this layer?
            ) {
              const src = layer.getSource();
              if (utils.instOf(src, TileWMS) || utils.instOf(src, ImageWMS)) {
                const params = src.getParams();
                params[dimension.name] = dimension.value;
                src.updateParams(params);
              } else if (utils.instOf(src, XYZ)) {
                src.refresh();
              }
              $scope.$emit('layermanager.dimension_changed', {
                layer: layer,
                dimension,
              });
            }
          });
        },

        dimensions() {
          const layer = vm.olLayer;
          if (angular.isUndefined(layer)) {
            return [];
          }
          return layer.get('dimensions');
        },
      });
    },
  ],
};
{'fraction_non_alphanumeric': 0.12218649517684887, 'fraction_numerical': 0.0007420232500618352, 'mean_word_length': 1.7435549525101763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7661580', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1076, 'n_words': 216}