<commit_before>// import WaterStressLegend from 'components/LayerPanel/WaterStressLegend';
// import LandCoverLegend from 'components/LayerPanel/LandCoverLegend';
// import SedimentLegend from 'components/LayerPanel/SedimentLegend';
// import DensityDisplay from 'components/LayerPanel/DensityDisplay';
// import WetlandsLegend from 'components/LayerPanel/WetlandsLegend';
import LayerCheckbox from 'components/LayerPanel/LayerCheckbox';
import FiresControls from 'components/LayerPanel/FiresControls';
import LossControls from 'components/LayerPanel/LossControls';
import LayerGroup from 'components/LayerPanel/LayerGroup';
import BasemapGroup from 'components/LayerPanel/BasemapGroup';
import LandsatLayer from 'components/LayerPanel/LandsatLayer';
import BasemapLayer from 'components/LayerPanel/BasemapLayer';
import basemaps from 'esri/basemaps';
import resources from 'resources';
// import DamsLegend from 'components/LayerPanel/DamsLegend';
import mapStore from 'stores/MapStore';
// import layersHelper from 'js/helpers/LayersHelper';
import React, {
  Component,
  PropTypes
} from 'react';

export default class LayerPanel extends Component {

  static contextTypes = {
    language: PropTypes.string.isRequired,
    settings: PropTypes.object.isRequired
  };

  constructor (props) {
    super(props);
    mapStore.listen(this.storeUpdated.bind(this));
    this.state = mapStore.getState();
  }

  storeUpdated () {
    this.setState(mapStore.getState());
  }

  renderLayerGroup = (group, layers) => {
    return (
      <LayerGroup key={group} activeLayers={this.state.activeLayers} label={group}>
        {layers.map(this.checkboxMap(group), this)}
      </LayerGroup>
    );
  };

  renderBasemapGroup = (extraBasemaps) => {
    let basemapLayers = [];
    if (basemaps) {
      let basemapNames = Object.keys(basemaps);
      basemapLayers = basemapNames.map((bm) => {
        return (
          <BasemapLayer icon={basemaps[bm].thumbnailUrl} label={basemaps[bm].title} basemap={bm} />
        );
      });
    }

    let landsat = extraBasemaps[0];
    if (landsat) {
      basemapLayers.unshift(
        <LandsatLayer icon={landsat.thumbnailUrl} label={landsat.title} years={landsat.years} />
      );
    }

    return (
      <BasemapGroup label='Basemap'>
        {basemapLayers}
      </BasemapGroup>
    );
  };

  render() {
    const {settings, language} = this.context;
    const layers = settings.layers && settings.layers[language] || [];
    const extraBasemaps = settings.basemaps && settings.basemaps[language] || [];
    let groups = [];
    //- Get a unique list of groups
    layers.forEach((layer) => {
      if (groups.indexOf(layer.group) === -1) {
        groups.push(layer.group);
      }
    });
    //- Create the layerGroup components
    let layerGroups = groups.map((group) => {
      return this.renderLayerGroup(group, layers);
    });

    layerGroups.push(this.renderBasemapGroup(extraBasemaps));

    return (
      <div className={`layer-panel custom-scroll`}>
        {layerGroups}
      </div>
    );
  }

  checkboxMap (group) {
    return layer => {
      let {activeLayers, dynamicLayers} = this.state;
      // Exclude Layers not part of this group
      if (layer.group !== group) { return null; }
      // TODO: Remove once current layer panel design is approved
      // If it is just a label, render the grop label
      // if (layer.isGroupLabel) { return <div key={layer.id} className='layer-group-label'>{layer.label}</div>; }
      // Some layers have legends or tools and they should be rendered inside the layer checkbox
      let childComponent;
      switch (layer.id) {
      //   case KEYS.waterStress:
      //     childComponent = <WaterStressLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.sediment:
      //     childComponent = <SedimentLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.majorDams:
      //     childComponent = <DamsLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
        case 'ACTIVE_FIRES':
          childComponent = <FiresControls loaded={this.props.loaded} {...this.state} />;
          break;
        case 'TREE_COVER_LOSS':
          childComponent = <LossControls layerId={layer.id} loaded={this.props.loaded} {...this.state} />;
          break;
      //   case KEYS.treeCover:
      //     childComponent = <DensityDisplay {...this.state} />;
      //     break;
      //   case KEYS.landCover:
      //     childComponent = <LandCoverLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.wetlands:
      //     childComponent = <WetlandsLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
        default:
          childComponent = null;
      }

      if (layer.esriLayer && layer.esriLayer.updating) {
        console.log('\tlayer still updating', layer.subId, layer);
        return null;
      }

      let checkbox;
      if (layer.subId) {
        // console.log('dynamicLayers', dynamicLayers);
        // console.log('LayerPanel::checkbox', layer);
        let checked = dynamicLayers[layer.id] && dynamicLayers[layer.id].indexOf(layer.subIndex) > -1;
        // let checked = activeLayers.indexOf(layer.id) > -1;
        // console.log('checked for', layer.subId, checked);
        checkbox = <LayerCheckbox key={layer.subId} layer={layer} subLayer={true} checked={checked}>
          {childComponent}
        </LayerCheckbox>
      } else {
        checkbox = <LayerCheckbox key={layer.id} layer={layer} checked={activeLayers.indexOf(layer.id) > -1}>
          {childComponent}
        </LayerCheckbox>;
      }
      return checkbox;
      // return <LayerCheckbox key={layer.id} layer={layer} checked={activeLayers.indexOf(layer.id) > -1}>
      // </LayerCheckbox>;

    };
  }

}<commit_msg>Don't show duplicate basemaps, only show vector basemaps.<commit_after>// import WaterStressLegend from 'components/LayerPanel/WaterStressLegend';
// import LandCoverLegend from 'components/LayerPanel/LandCoverLegend';
// import SedimentLegend from 'components/LayerPanel/SedimentLegend';
// import DensityDisplay from 'components/LayerPanel/DensityDisplay';
// import WetlandsLegend from 'components/LayerPanel/WetlandsLegend';
import LayerCheckbox from 'components/LayerPanel/LayerCheckbox';
import FiresControls from 'components/LayerPanel/FiresControls';
import LossControls from 'components/LayerPanel/LossControls';
import LayerGroup from 'components/LayerPanel/LayerGroup';
import BasemapGroup from 'components/LayerPanel/BasemapGroup';
import LandsatLayer from 'components/LayerPanel/LandsatLayer';
import BasemapLayer from 'components/LayerPanel/BasemapLayer';
import basemaps from 'esri/basemaps';
import resources from 'resources';
// import DamsLegend from 'components/LayerPanel/DamsLegend';
import mapStore from 'stores/MapStore';
// import layersHelper from 'js/helpers/LayersHelper';
import React, {
  Component,
  PropTypes
} from 'react';

export default class LayerPanel extends Component {

  static contextTypes = {
    language: PropTypes.string.isRequired,
    settings: PropTypes.object.isRequired
  };

  constructor (props) {
    super(props);
    mapStore.listen(this.storeUpdated.bind(this));
    this.state = mapStore.getState();
  }

  storeUpdated () {
    this.setState(mapStore.getState());
  }

  renderLayerGroup = (group, layers) => {
    return (
      <LayerGroup key={group} dynamicLayers={this.state.dynamicLayers} activeLayers={this.state.activeLayers} label={group}>
        {layers.map(this.checkboxMap(group), this)}
      </LayerGroup>
    );
  };

  renderBasemapGroup = (extraBasemaps) => {
    let basemapLayers = [];
    if (basemaps) {
      let basemapNames = Object.keys(basemaps);
      console.log('basemapNames', basemapNames);
      basemapNames = basemapNames.filter(bm => {
        // Rather than showing traditional tiled and vector tile basemap options,
        // only show the vector tile basemap.
        return !basemaps.hasOwnProperty(bm+'-vector');
      });
      basemapLayers = basemapNames.map(bm => {
        return (
          <BasemapLayer icon={basemaps[bm].thumbnailUrl} label={basemaps[bm].title} basemap={bm} />
        );
      });
    }

    let landsat = extraBasemaps[0];
    if (landsat) {
      basemapLayers.unshift(
        <LandsatLayer icon={landsat.thumbnailUrl} label={landsat.title} years={landsat.years} />
      );
    }

    return (
      <BasemapGroup label='Basemap'>
        {basemapLayers}
      </BasemapGroup>
    );
  };

  render() {
    const {settings, language} = this.context;
    const layers = settings.layers && settings.layers[language] || [];
    const extraBasemaps = settings.basemaps && settings.basemaps[language] || [];
    let groups = [];
    //- Get a unique list of groups
    layers.forEach((layer) => {
      if (groups.indexOf(layer.group) === -1) {
        groups.push(layer.group);
      }
    });
    //- Create the layerGroup components
    let layerGroups = groups.map((group) => {
      return this.renderLayerGroup(group, layers);
    });

    layerGroups.push(this.renderBasemapGroup(extraBasemaps));

    return (
      <div className={`layer-panel custom-scroll`}>
        {layerGroups}
      </div>
    );
  }

  checkboxMap (group) {
    return layer => {
      let {activeLayers, dynamicLayers} = this.state;
      // Exclude Layers not part of this group
      if (layer.group !== group) { return null; }
      // TODO: Remove once current layer panel design is approved
      // If it is just a label, render the grop label
      // if (layer.isGroupLabel) { return <div key={layer.id} className='layer-group-label'>{layer.label}</div>; }
      // Some layers have legends or tools and they should be rendered inside the layer checkbox
      let childComponent;
      switch (layer.id) {
      //   case KEYS.waterStress:
      //     childComponent = <WaterStressLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.sediment:
      //     childComponent = <SedimentLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.majorDams:
      //     childComponent = <DamsLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
        case 'ACTIVE_FIRES':
          childComponent = <FiresControls loaded={this.props.loaded} {...this.state} />;
          break;
        case 'TREE_COVER_LOSS':
          childComponent = <LossControls layerId={layer.id} loaded={this.props.loaded} {...this.state} />;
          break;
      //   case KEYS.treeCover:
      //     childComponent = <DensityDisplay {...this.state} />;
      //     break;
      //   case KEYS.landCover:
      //     childComponent = <LandCoverLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
      //   case KEYS.wetlands:
      //     childComponent = <WetlandsLegend url={layer.url} layerIds={layer.layerIds} />;
      //     break;
        default:
          childComponent = null;
      }

      if (layer.esriLayer && layer.esriLayer.updating) {
        // console.log('\tlayer still updating', layer.subId, layer);
        return null;
      }

      let checkbox;
      if (layer.subId) {
        let checked = dynamicLayers[layer.id] && dynamicLayers[layer.id].indexOf(layer.subIndex) > -1;
        checkbox = <LayerCheckbox key={layer.subId} layer={layer} subLayer={true} checked={checked}>
          {childComponent}
        </LayerCheckbox>
      } else {
        checkbox = <LayerCheckbox key={layer.id} layer={layer} checked={activeLayers.indexOf(layer.id) > -1}>
          {childComponent}
        </LayerCheckbox>;
      }
      return checkbox;
    };
  }

}
{'fraction_non_alphanumeric': 0.13191850594227505, 'fraction_numerical': 0.0008488964346349745, 'mean_word_length': 2.8563011456628478, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 68, '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': '5989952', 'n_tokens_mistral': 3603, 'n_tokens_neox': 3522, 'n_words': 731}