Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
How to disable scrolling outside of polygon in react leaflet

I created a simple map in the react project with the help of the leaflet library. Now I need to make the map be focused on one specific country so it won't be possible to scroll the map outside its borders.

So far, I have found solutions that apply only to a standard Java Script / HTML project and not something that integrates with the leaflet library for react.

Also, even these solutions only need to define an area where only the map is loaded and the other tiles are not loaded, and as can be understood from the description at the beginning of my question, This is not exactly what I need and I realized there is another option.

(However, if you are familiar with another option to make the map be focused on a specific country in some way, even if it doesn't exactly do what I described, feel free to list below. I'd be happy for any advice)

Anyone have an idea?

Here is my code:

import './App.css';
import { MapContainer, TileLayer} from 'react-leaflet';
import 'leaflet/dist/leaflet.css';

function App() {
  return (
    <div>
       <MapContainer
        style={{ height: "400vh" }}
        center={[51.505, -0.09]}
        zoom={13}
        scrollWheelZoom={false}
      >
        <TileLayer
          attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
      </MapContainer>
    </div>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To load tiles only in a defined area you can use the bounds option on the TileLayer. And to restrict the "scroll" / moving outside of the area you can use the maxBounds option on the map.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda