You can use scale-based stylers or SLD stylers with scale denominator rules to define styles based on view scale. Styles get applied as the user zooms in or out on the view.

You may find it useful to control the scale that’s used for these stylers, independently of the map scale displayed in the view. For example, the map user has zoomed in to a specific scale, and the layers have received the styling defined for that scale. Now you want to keep that styling when the user zooms out again, even beyond the scale range tied to that style.

You can achieve such control by using a custom ILspMapScaleProvider.

Be careful when using map scale providers. Using a highly detailed style in a zoomed-out area may lead to large amounts of data being queried and painted. This can affect performance negatively.

In this example, we create a custom map scale provider that allows the user to lock the style to a certain scale level. When the user locks the scale, zooming in or out doesn’t influence the style used in rendering. When the user unlocks the scale, the current view map scale determines the style of the layer again.

Program: Create a custom map scale provider
public static class LockableMapScaleProvider implements ILspMapScaleProvider {

  private final ILspMapScaleProvider fDelegate = ILspMapScaleProvider.fromView();

  private final CopyOnWriteArrayList<ILspMapScaleChangeListener> fListeners = new CopyOnWriteArrayList<>();
  private final ILspView fView;
  private final MapScaleFromViewListener fMapScaleFromViewListener;

  private boolean fLocked = false;
  private TLcdMapScale fLatest;

  public LockableMapScaleProvider(ILspView aView) {
    fView = aView;
    fLatest = fDelegate.getMapScale(aView);
    fMapScaleFromViewListener = new MapScaleFromViewListener();
    fDelegate.addMapScaleChangeListener(fMapScaleFromViewListener);
  }

  @Override
  public synchronized TLcdMapScale getMapScale(ILspView aView) {
    return fLatest;
  }

  public synchronized void toggle() {
    fLocked = !fLocked;
    fLatest = fDelegate.getMapScale(fView);
    this.fireScaleChangedEvent(this);
  }

  public final void fireScaleChangedEvent(ILspMapScaleProvider aSource) {
    for (ILspMapScaleChangeListener listener : fListeners) {
      listener.scaleChanged(new TLspMapScaleChangeEvent(aSource, fView));
    }
  }

  @Override
  public void addMapScaleChangeListener(ILspMapScaleChangeListener aListener) {
    fListeners.add(aListener);
  }

  @Override
  public void removeMapScaleChangeListener(ILspMapScaleChangeListener aListener) {
    fListeners.remove(aListener);
  }

  public void cleanup() {
    fDelegate.removeMapScaleChangeListener(fMapScaleFromViewListener);
  }

  private class MapScaleFromViewListener implements ILspMapScaleChangeListener {
    @Override
    public void scaleChanged(TLspMapScaleChangeEvent event) {
      synchronized (LockableMapScaleProvider.this) {
        if (!fLocked) {
          fLatest = fDelegate.getMapScale(fView);
          LockableMapScaleProvider.this.fireScaleChangedEvent(event.getSource());
        }
      }
    }
  }
}

You can configure this map scale provider on a scale-based styler or an SLD styler as follows:

Program: Using a custom map scale provider with a scale-based styler
LockableMapScaleProvider mapScaleProvider = new LockableMapScaleProvider(aView);

TLspScaleBasedStyler styler = TLspScaleBasedStylerBuilder.newBuilder()
                                                         /* configuration of the styler can be done here */
                                                         .build();

aLayer.setStyler(REGULAR_BODY, styler);
aLayer.setStyler(REGULAR_LABEL, styler);
aLayer.setMapScaleProvider(mapScaleProvider);

// later, for example in a UI event handler, we can toggle the behaviour of the map scale provider:
mapScaleProvider.toggle();

// if we don't need the map scale provider anymore, we should unregister ourselves from the default provider:
mapScaleProvider.cleanup();
Program: Using a custom map scale provider with an SLD styler
LockableMapScaleProvider mapScaleProvider = new LockableMapScaleProvider(aView);

aLayer.configureForSLDStyling(aSLDFeatureTypeStyle);
aLayer.setMapScaleProvider(mapScaleProvider);

// later:
mapScaleProvider.toggle();

mapScaleProvider.cleanup();