【发布时间】:2020-11-30 12:28:50
【问题描述】:
我正在使用带有传单的 React,但我不知道如何将标记的颜色从蓝色更改为红色。我查看了文档,但没有找到任何内容。
这是我的代码:
import React from 'react';
import { render } from 'react-dom';
import Map from './Map';
class App extends React.Component {
state = { markerPosition: { lat: 49.8419, lng: 24.0315 } };
moveMarker = () => {
const { lat, lng } = this.state.markerPosition;
this.setState({
markerPosition: {
lat: lat + 0.0001,
lng: lng + 0.0001,
}
});
};
render() {
const { markerPosition } = this.state;
return (
<div>
<Map markerPosition={markerPosition} />
<div>Current markerPosition: lat: {markerPosition.lat}, lng: {markerPosition.lng}</div>
<button
onClick={this.moveMarker}
>
Move marker
</button>
</div>
);
}
}
render(<App />, document.getElementById('root'));
https://codesandbox.io/s/m4k3x1ynl8
你知道我该怎么做吗?
非常感谢!
【问题讨论】:
-
标记是一个图像,你可以用任何你想要的替换它。
dist/images/marker-icon.png,见this -
如何导入L?
-
@Peter 你已经在链接沙箱的
Map组件中完成了这项工作。
标签: javascript reactjs