Skip to content

Commit

Permalink
Merge pull request #244 from emilhe/zoomfix
Browse files Browse the repository at this point in the history
Use PR from leaflet core lib
  • Loading branch information
emilhe authored Oct 7, 2024
2 parents c14ee8a + d510627 commit 23691d6
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/ts/components/TileLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import React from 'react';
import { TileLayer as ReactLeafletTileLayer } from 'react-leaflet';
import {TileLayerProps, assignLoadEventHandlers, LoadComponent, Modify} from "../props";
import React, { useEffect, useRef, useState } from 'react';
import { TileLayer as ReactLeafletTileLayer, useMap } from 'react-leaflet';
import { TileLayerProps, assignLoadEventHandlers, LoadComponent, Modify } from "../props";
import L from 'leaflet';

// https://github.com/Leaflet/Leaflet/pull/8613
L.GridLayer.include({
redraw() {
if (this._map) {
this._removeAllTiles();
const tileZoom = Math.round(this._clampZoom(this._map.getZoom()));
if (tileZoom !== this._tileZoom) {
this._tileZoom = tileZoom;
this._updateLevels();
}
this._update();
}
return this;
},
});

type Props = Modify<TileLayerProps, {
/**
* The URL template in the form 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'. [MUTABLE, DL]
*/
url?: string;
/**
* The URL template in the form 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'. [MUTABLE, DL]
*/
url?: string;
} & LoadComponent>;

/**
* Used to load and display tile layers on the map. Note that most tile servers require attribution.
*/
const TileLayer = ({
// Set default to OSM
url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
...props
const TileLayer = ({
// Set default to OSM
url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
...props
}: Props) => {
return (
return (
<ReactLeafletTileLayer url={url} {...assignLoadEventHandlers(props)}></ReactLeafletTileLayer>
)
}
Expand Down

0 comments on commit 23691d6

Please sign in to comment.