Skip to content

Url tiles #654

Answered by usefulthink
tubadan33 asked this question in Q&A
Dec 31, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Tile-based layers can be added using the mapTypes registry and ImageMapType class.

Something along these lines:

const TILE_URL = 'https://example.com/sample/{z}_{x}_{y}.jpg';

const TileLayer = () => {
  const map = useMap();
  useEffect(() => {
    if (!map) return;
  
    const mapType = new google.maps.ImageMapType({
      name: 'my-map-type',
      getTileUrl(coord, zoom) {
        return TILE_URL
          .replace('{x}', coord.x)
          .replace('{y}', coord.y)
          .replace('{z}', zoom);
      },
      tileSize: new google.maps.Size(256, 256),
      minZoom: 1,
      maxZoom: 20
    });
  
    map.mapTypes.set('my-map-type', mapType);
  }, [map]);
  
  return <></>;
};

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tubadan33
Comment options

@usefulthink
Comment options

@tubadan33
Comment options

Answer selected by tubadan33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants