你好(第一次在堆栈溢出上发帖,所以对任何违反礼仪的行为表示歉意.)
我目前正在构建一个React应用程序,其中包含一个使用反应简单地图构建的交互式SVG地图。在我的桌面浏览器中,一切正常工作,但是地图本身并没有加载到移动设备上(我已经测试过几个),我也不知道为什么。我已经从下面讨论的组件中包含了代码(我删除了代码中的一些无关部分):
import React, { memo, Component } from 'react';
import { ZoomableGroup, ComposableMap, Geographies, Geography } from "react-simple-maps";
import geoUrl from "../data/topo.json";
import Country from './Country'
import { CSSTransition, SwitchTransition } from "react-transition-group";
class Map extends Component {
constructor(props){
super(props);
this.state = {
country: "",
dish: "",
description: "",
photo: "",
recipe: "",
selected: false,
}
this.handleBack = this.handleBack.bind(this);
this.handleAbout = this.handleAbout.bind(this);
this.handleList = this.handleList.bind(this);
}
handleEnter(country, dish, description, photo, recipe){
this.setState({
country: country,
dish: dish,
description: description,
photo: photo,
recipe: recipe
})
}
render(){
const { country, dish, description, photo, recipe, selected } = this.state;
const countries = geoUrl.objects.ne_50m_admin_0_countries.geometries;
return(
<SwitchTransition>
<CSSTransition
classNames="transition"
transitionAppearTimeout={50000}
key={ selected }
in={ selected }
unmountOnExit
appear
>
<>
<section className="map">
<div className="container">
<ComposableMap width="1200" data-tip="" projectionConfig={{ scale: 200 }} >
<ZoomableGroup>
<Geographies geography={geoUrl}>
{({ geographies }) =>
geographies.map(geo =>
<a href="#country">
<Geography
key={geo.rsmKey}
geography={geo}
onMouseEnter={() => {
const { NAME } = geo.properties;
this.props.setTooltipContent(`${NAME}`);
}}
onMouseLeave={() => {
this.props.setTooltipContent("");
}}
onClick={() => {
const { NAME, DISH, DESCRIPTION, PHOTO, RECIPE } = geo.properties;
this.handleEnter(NAME, DISH, DESCRIPTION, PHOTO, RECIPE);
}}
fill="#44BBA4"
stroke="#E94F37"
strokeWidth="0.5"
style={{
default: {
outline: 'none'
},
hover: {
fill: "#E94F37",
outline: 'none'
},
pressed: {
outline: 'none'
}
}}
/>
</a>
)
}
</Geographies>
</ZoomableGroup>
</ComposableMap>
</div>
</section>
</>
</CSSTransition>
</SwitchTransition>
);
}
}
export default memo(Map);如果有人有任何洞察力的话,那就太棒了!如果你想看更多的代码/截图等,请告诉我。谢谢!
发布于 2020-10-21 09:17:23
感谢@Maitham帮我弄清楚了答案--通过向style={{width: "100%"}}添加<ComposableMap>属性,这个问题现在似乎已经解决了!这不应替换width="1200"属性(如果删除此属性,则地图将根本不会在移动或桌面上呈现),但应该是附加的:
<ComposableMap width="1200" style={{ width: "100%" }} data-tip="" projectionConfig={{ scale: 200 }} >https://stackoverflow.com/questions/64449042
复制相似问题