Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react leaflet recenter map

import { MapContainer, TileLayer, Marker, Popup, useMap } from 'react-leaflet';

function ChangeView({ center, zoom }) {
  const map = useMap();
  map.setView(center, zoom);
}

function Map({ center, zoom }) {
  return (
    <div className="map">
      <MapContainer center={center} zoom={zoom} scrollWheelZoom={false}>
        <ChangeView center={center} zoom={zoom} /> 
        <TileLayer
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
          attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        />
      </MapContainer>
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js v13 if dm 
Javascript :: jQuery onclick not firing on dynamically inserted HTML elements 
Javascript :: how to empty a filled input in cypress 
Javascript :: javascript how to select radio button 
Javascript :: closure in js 
Javascript :: npm got 
Javascript :: vue scroll div to bottom 
Javascript :: react render component after fetch 
Javascript :: javascript string normalize method 
Javascript :: react chart js 2 
Javascript :: javascript convert string with square brackets to array 
Javascript :: deploy vue js to shared hosting 
Javascript :: socket.io how do i get a list of connected sockets clients 
Javascript :: js sort number array 
Javascript :: ngrok live port vue js 
Javascript :: get option value jquery 
Javascript :: select selected option value jquery 
Javascript :: javascript explode space 
Javascript :: get id of an element 
Javascript :: namespace in javascript 
Javascript :: react native paper modal background 
Javascript :: how to read a file in javascript 
Javascript :: javascript array.find 
Javascript :: js read file json 
Javascript :: api fetch in react js 
Javascript :: new Date() get speicifc hours min sec 
Javascript :: react 18 render 
Javascript :: discord js lockdown command 
Javascript :: frequency of characters in a string in javascript 
Javascript :: json decode android 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =