Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda