Ich versuche, den gleichen Effekt auf meiner Seite wie hier react-google-map demo zu haben. Ich habe react-google-maps verwendet. Die Sache ist, dass ich Daten mit Markierungen Informationen abhole und ich weiß nicht, wie ich mit Klick umgehen kann, der InfoWindow anzeigen/verbergen wird. Wahrscheinlich ist der Grund irgendwo mit Staat, ich weiß nicht, wie man die Variable "isShown" für jeden Marker im Marker-Array wahr/falsch macht. Hier ist mein Code:React-google-maps + redux - InfoWindow auf Marker klicken
const GettingStartedGoogleMap = withGoogleMap(props => (
<GoogleMap
ref={props.onMapLoad}
defaultZoom={16}
defaultCenter={props.defCenter}
onClick={props.onMapClick}
>
{props.markers.map((marker,i) => (
<Marker
key={i}
position={marker.location}
time={marker.time}
onClick={() => props.onMarkerClick(marker)}
// HERE I TRIED SOMETHING LIKE marker.isShown=true; but it is NOT WORKING
>
{
<InfoWindow>
<div className="marker-text">{marker.time}</div>
</InfoWindow>
}
</Marker>
))}
</GoogleMap>
));
class GettingStartedExample extends Component {
componentDidMount(){
this.props.fetchMarkers();
}
state = {
markers: this.props.markers,
};
handleMapLoad = this.handleMapLoad.bind(this);
handleMarkerClick = this.handleMarkerClick.bind(this);
handleMapLoad(map) {
this._mapComponent = map;
if (map) {
console.log(map.getZoom());
}
}
handleMarkerClick(targetMarker) {
/*
* All you modify is data, and the view is driven by data.
* This is so called data-driven-development. (And yes, it's now in
* web front end and even with google maps API.)
*/
const nextMarkers = this.state.markers.filter(marker => marker !== targetMarker);
console.log(targetMarker.showInfo)
this.setState({
markers: nextMarkers,
});
}
render() {
return (
<div className='container map-container'>
<GettingStartedGoogleMap
containerElement={
<div style={{ height: `100%` }} />
}
mapElement={
<div style={{ height: `100%` }} />
}
onMapLoad={this.handleMapLoad}
markers={this.props.markers}
onMarkerClick={this.handleMarkerClick}
defCenter={{lat: 50.07074, lng: 19.915718}}
/>
</div>
);
}
}
GettingStartedExample.propTypes={
markers: React.PropTypes.array.isRequired,
fetchMarkers: React.PropTypes.func.isRequired
}
function mapStateToProps(state){
return{
markers:state.markers
}
}
export default connect(mapStateToProps,{fetchMarkers})(GettingStartedExample);
Derzeit sieht es so aus:
In meinem letzten Effekt würde Ich mag Infofenster auf dem neuesten Marker haben und Griff klicken, mit dem Ihnen zum Anzeigen/InfoWindows auf allen Markern ausblenden.
Wie kann ich erreichen, dass InfoWindow auf jedem Marker angezeigt wird?
Vielen Dank für jede Hilfe!
verwenden, können Sie die Lösung finden Haben ? –