2022
##💡 Alternativa: LEAFLET https://react-leaflet.js.org/docs/start-installation/
npm install react-leaflet
src/components/Map.jsx
import React from 'react';
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet'
import Icon from '../assets/marker.png'
// import { Icon } from 'leaflet'
import '../styles/Map.css';
const position = [51.505, -0.09]
const ChartMap = () => {
return (
<MapContainer center={position} zoom={13}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={position} >
<Popup icon={Icon}>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
);
};
export default ChartMap;
src/styles/Map.css
.leaflet-container {
width: 100%;
height: 500px;
}
src/public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="" />
<title>Document</title>
</head>
<div id="app"></div>
<body>
</body>
</html>
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?