Skip to content

Map has no maxZoom specified #46

@bpatrik

Description

@bpatrik

This is just an FYI issue, if anyone else runs into this:

markercluster throws error Map has no maxZoom specified if max zoom is not specified.
A solution can be specifying max zoom, but than that would override the tile's max zoom (leading to too little, or too much zoom)

Relevant code part that cause the issue:

    <div
      leaflet
      [leafletOptions]="mapOptions"
      (leafletMapReady)="onMapReady($event)">
    </div>   
mapOptions: MapOptions = {
    zoom: 2,
    center: latLng(0, 0),
    layers: [markerClusterGroup()]
  };

Possible workaround:

  1. setting dummy max zoom by default:
mapOptions: MapOptions = {
    zoom: 2,
    // setting max zoom is needed to MarkerCluster https://github.com/Leaflet/Leaflet.markercluster/issues/611
    maxZoom: 2,
    center: latLng(0, 0),
    layers: [markerClusterGroup()]
  };
  1. Then removing it once the map loaded, so it can fallback to the tile's max zoom:
onMapReady(map: Map): void {
    this.leafletMap = map;
    this.leafletMap.setMaxZoom(undefined);
  }

Related issue at leaflet: Leaflet/Leaflet.markercluster#611

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions