function _setDiffStyle(prevStyle, nextStyle) {
    var map = this._getMap();
    var prevKeysMap = prevStyle && styleKeysMap(prevStyle) || {};
    var nextKeysMap = styleKeysMap(nextStyle);
    function styleKeysMap(style) {
      return style.map(function _map() {
        return true;
      }).delete('layers').delete('sources').toJS();
    }
    function propsOtherThanLayersOrSourcesDiffer() {
      var prevKeysList = Object.keys(prevKeysMap);
      var nextKeysList = Object.keys(nextKeysMap);
      if (prevKeysList.length !== nextKeysList.length) {
        return true;
      }
      // `nextStyle` and `prevStyle` should not have the same set of props.
      if (nextKeysList.some(function forEach(key) {
        // But the value of one of those props is different.
        return prevStyle.get(key) !== nextStyle.get(key);
      })) {
        return true;
      }
      return false;
    }

    if (!prevStyle || propsOtherThanLayersOrSourcesDiffer()) {
      map.setStyle(nextStyle.toJS());
      return;
    }

    var sourcesDiff = this._diffSources(prevStyle, nextStyle);
    var layersDiff = this._diffLayers(prevStyle, nextStyle);

    // TODO: It's rather difficult to determine style diffing in the presence
    // of refs. For now, if any style update has a ref, fallback to no diffing.
    // We can come back to this case if there's a solid usecase.
    if (layersDiff.updates.some(function updatedNodeHasRef(node) {
      return node.layer.get('ref');
    })) {
      map.setStyle(nextStyle.toJS());
      return;
    }

    map.batch(function batchStyleUpdates(batch) {
      sourcesDiff.enter.forEach(function each(enter) {
        batch.addSource(enter.id, enter.source.toJS());
      });
      sourcesDiff.update.forEach(function each(update) {
        batch.removeSource(update.id);
        batch.addSource(update.id, update.source.toJS());
      });
      sourcesDiff.exit.forEach(function each(exit) {
        batch.removeSource(exit.id);
      });
      layersDiff.exiting.forEach(function forEach(exit) {
        if (map.style.getLayer(exit.id)) {
          batch.removeLayer(exit.id);
        }
      });
      layersDiff.updates.forEach(function forEach(update) {
        if (!update.enter) {
          // This is an old layer that needs to be updated. Remove the old layer
          // with the same id and add it back again.
          batch.removeLayer(update.id);
        }
        batch.addLayer(update.layer.toJS(), update.before);
      });
    });
  }
// styles only change sources or layers.
styles only change sources or layers.
styles only change sources or layers .
function _setDiffStyle(prevStyle, nextStyle) {
    var map = this._getMap();
    var prevKeysMap = prevStyle && styleKeysMap(prevStyle) || {};
    var nextKeysMap = styleKeysMap(nextStyle);
    function styleKeysMap(style) {
      return style.map(function _map() {
        return true;
      }).delete('layers').delete('sources').toJS();
    }
    function propsOtherThanLayersOrSourcesDiffer() {
      var prevKeysList = Object.keys(prevKeysMap);
      var nextKeysList = Object.keys(nextKeysMap);
      if (prevKeysList.length !== nextKeysList.length) {
        return true;
      }
      if (nextKeysList.some(function forEach(key) {
        return prevStyle.get(key) !== nextStyle.get(key);
      })) {
        return true;
      }
      return false;
    }
    if (!prevStyle || propsOtherThanLayersOrSourcesDiffer()) {
      map.setStyle(nextStyle.toJS());
      return;
    }
    var sourcesDiff = this._diffSources(prevStyle, nextStyle);
    var layersDiff = this._diffLayers(prevStyle, nextStyle);
    if (layersDiff.updates.some(function updatedNodeHasRef(node) {
      return node.layer.get('ref');
    })) {
      map.setStyle(nextStyle.toJS());
      return;
    }
    map.batch(function batchStyleUpdates(batch) {
      sourcesDiff.enter.forEach(function each(enter) {
        batch.addSource(enter.id, enter.source.toJS());
      });
      sourcesDiff.update.forEach(function each(update) {
        batch.removeSource(update.id);
        batch.addSource(update.id, update.source.toJS());
      });
      sourcesDiff.exit.forEach(function each(exit) {
        batch.removeSource(exit.id);
      });
      layersDiff.exiting.forEach(function forEach(exit) {
        if (map.style.getLayer(exit.id)) {
          batch.removeLayer(exit.id);
        }
      });
      layersDiff.updates.forEach(function forEach(update) {
        if (!update.enter) {
          batch.removeLayer(update.id);
        }
        batch.addLayer(update.layer.toJS(), update.before);
      });
    });
  }
function _setDiffStyle ( prevStyle , nextStyle ) { var map = this . _getMap ( ) ; var prevKeysMap = prevStyle && styleKeysMap ( prevStyle ) || { } ; var nextKeysMap = styleKeysMap ( nextStyle ) ; function styleKeysMap ( style ) { return style . map ( function _map ( ) { return true ; } ) . delete ( 'layers' ) . delete ( 'sources' ) . toJS ( ) ; } function propsOtherThanLayersOrSourcesDiffer ( ) { var prevKeysList = Object . keys ( prevKeysMap ) ; var nextKeysList = Object . keys ( nextKeysMap ) ; if ( prevKeysList . length !== nextKeysList . length ) { return true ; } if ( nextKeysList . some ( function forEach ( key ) { return prevStyle . get ( key ) !== nextStyle . get ( key ) ; } ) ) { return true ; } return false ; } if ( ! prevStyle || propsOtherThanLayersOrSourcesDiffer ( ) ) { map . setStyle ( nextStyle . toJS ( ) ) ; return ; } var sourcesDiff = this . _diffSources ( prevStyle , nextStyle ) ; var layersDiff = this . _diffLayers ( prevStyle , nextStyle ) ; if ( layersDiff . updates . some ( function updatedNodeHasRef ( node ) { return node . layer . get ( 'ref' ) ; } ) ) { map . setStyle ( nextStyle . toJS ( ) ) ; return ; } map . batch ( function batchStyleUpdates ( batch ) { sourcesDiff . enter . forEach ( function each ( enter ) { batch . addSource ( enter . id , enter . source . toJS ( ) ) ; } ) ; sourcesDiff . update . forEach ( function each ( update ) { batch . removeSource ( update . id ) ; batch . addSource ( update . id , update . source . toJS ( ) ) ; } ) ; sourcesDiff . exit . forEach ( function each ( exit ) { batch . removeSource ( exit . id ) ; } ) ; layersDiff . exiting . forEach ( function forEach ( exit ) { if ( map . style . getLayer ( exit . id ) ) { batch . removeLayer ( exit . id ) ; } } ) ; layersDiff . updates . forEach ( function forEach ( update ) { if ( ! update . enter ) { batch . removeLayer ( update . id ) ; } batch . addLayer ( update . layer . toJS ( ) , update . before ) ; } ) ; } ) ; }
styles only change sources or layers.
styles only change sources or layers .
// `nextStyle` and `prevStyle` should not have the same set of props. // But the value of one of those props is different. // TODO: It's rather difficult to determine style diffing in the presence // of refs. For now, if any style update has a ref, fallback to no diffing. // We can come back to this case if there's a solid usecase. // This is an old layer that needs to be updated. Remove the old layer // with the same id and add it back again.