Skip to content

How to use onLoad to switch displayed language of a map? #2019

Answered by belkocik
belkocik asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to solve it, but there is no Polish language, whaaaaaat?

import { useRef, useState } from "react";
import "mapbox-gl/dist/mapbox-gl.css";
import MapboxMap, { ViewState, MapRef } from "react-map-gl";

interface IProps {}

const Mapbox = ({}: IProps) => {
  const mapRef = useRef<MapRef | null>(null);
  const [viewport, setViewport] = useState<ViewState>({
    latitude: 50.102242,
    longitude: 21.338631,
    zoom: 6,
    bearing: 0,
    pitch: 0,
    padding: { left: 0, right: 0, top: 0, bottom: 0 },
  });

  const onMapLoad = () => {
    const map = mapRef.current?.getMap();
    map?.getStyle().layers.forEach((thisLayer) => {
      if (thisLayer.id.indexOf("-label") > 0) {
        

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by belkocik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant