import React from "react"; import { ComposableMap, Geographies, Geography, Marker } from…
- User
import React from "react"; import { ComposableMap, Geographies, Geography, Marker } from "react-simple-maps";
const geoUrl = "https://raw.githubusercontent.com/deldersveld/topojson/master/world-countries.json" const markers = [ { markerOffset: -30, name: "Buenos Aires", coordinates: [-58.3816, -34.6037] }, { markerOffset: 15, name: "La Paz", coordinates: [-68.1193, -16.4897] }, { markerOffset: 15, name: "Brasilia", coordinates: [-47.8825, -15.7942] }, { markerOffset: 15, name: "Santiago", coordinates: [-70.6693, -33.4489] }, { markerOffset: 15, name: "Bogota", coordinates: [-74.0721, 4.711] }, { markerOffset: 15, name: "Quito", coordinates: [-78.4678, -0.1807] }, { markerOffset: -30, name: "Georgetown", coordinates: [-58.1551, 6.8013] }, { markerOffset: -30, name: "Asuncion", coordinates: [-57.5759, -25.2637] }, { markerOffset: 15, name: "Paramaribo", coordinates: [-55.2038, 5.852] }, { markerOffset: 15, name: "Montevideo", coordinates: [-56.1645, -34.9011] }, { markerOffset: 15, name: "Caracas", coordinates: [-66.9036, 10.4806] }, { markerOffset: 15, name: "Lima", coordinates: [-77.0428, -12.0464] } ];
const MapChart = () => { return ( <ComposableMap projection="geoNaturalEarth1" projectionConfig={{ rotate: [0, 0, 0], scale: 0 }} > {({ geographies }) => geographies.map((geo) => ( )) } {markers.map(({ name, coordinates, markerOffset }) => ( <text textAnchor="middle" y={markerOffset} style={{ fontFamily: "system-ui", fill: "#5D5A6D" }} > {name} ))} ); };
export default MapChart;
нужно сделать, чтобы когда я наводил мышкой на страну, она подсвечивалась. нужно убрать антарктиду с карты
- Assistant
Чтобы реализовать подсветку страны при наведении мышкой, вам потребуется добавить состояние для хранения информации о текущей подсвеченной стране и обработчики событий для наведения и снятия подсветки.
Также вам потребуется изменить источник данных для отображения географических данных, чтобы исключить Антарктиду.
Вот обновленный код:
import React, { useState } from "react"; import { ComposableMap, Geographies, Geography, Marker } from "react-simple-maps"; const geoUrl = "https://raw.githubusercontent.com/deldersveld/topojson/master/world-countries.json"; const markers = [ { markerOffset: -30, name: "Buenos Aires", coordinates: [-58.3816, -34.6037] }, { markerOffset: 15, name: "La Paz", coordinates: [-68.1193, -16.4897] }, { markerOffset: 15, name: "Brasilia", coordinates: [-47.8825, -15.7942] }, { markerOffset: 15, name: "Santiago", coordinates: [-70.6693, -33.4489] }, { markerOffset: 15, name: "Bogota", coordinates: [-74.0721, 4.711] }, { markerOffset: 15, name: "Quito", coordinates: [-78.4678, -0.1807] }, { markerOffset: -30, name: "Georgetown", coordinates: [-58.1551, 6.8013] }, { markerOffset: -30, name: "Asuncion", coordinates: [-57.5759, -25.2637] }, { markerOffset: 15, name: "Paramaribo", coordinates: [-55.2038, 5.852] }, { markerOffset: 15, name: "Montevideo", coordinates: [-56.1645, -34.9011] }, { markerOffset: 15, name: "Caracas", coordinates: [-66.9036, 10.4806] }, { markerOffset: 15, name: "Lima", coordinates: [-77.0428, -12.0464] } ]; const MapChart = () => { const [highlightedCountry, setHighlightedCountry] = useState(null); const handleMouseEnter = (geo) => { setHighlightedCountry(geo.properties.NAME); }; const handleMouseLeave = () => { setHighlightedCountry(null); }; return ( <ComposableMap projection="geoNaturalEarth1" projectionConfig={{ rotate: [0, 0, 0], scale: 150 }} > <Geographies geography={geoUrl}> {({ geographies }) => geographies .filter((geo) => geo.properties.CONTINENT !== "Antarctica") // Исключаем Антарктиду .map((geo) => ( <Geography key={geo.rsmKey} geography={geo} fill={highlightedCountry === geo.properties.NAME ? "#FF5533" : "#EAEAEC"} stroke="#D6D6DA" onMouseEnter={() => handleMouseEnter(geo)} onMouseLeave={handleMouseLeave} /> )) } </Geographies> {markers.map(({ name, coordinates, markerOffset }) => ( <Marker key={name} coordinates={coordinates}> <g fill="none" stroke="#FF5533" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" transform="translate(-12, -24)" > <circle cx="12" cy="10" r="3" /> <path d="M12 21.7C17.3 17 20 13 20 10a8 8 0 1 0-16 0c0 3 2.7 6.9 8 11.7z" /> </g> <text textAnchor="middle" y={markerOffset} style={{ fontFamily: "system-ui", fill: "#5D5A6D" }} > {name} </text> </Marker> ))} </ComposableMap> ); }; export default MapChart;Теперь, когда вы наводите мышкой на страну, она будет подсвечиваться красным цветом, а при снятии наведения подсветка исчезнет. Кроме того, Антарктида будет исключена из отображения.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.