import React, { Component } from 'react'; import cx from 'classnames'; import './App.css'; import loadJs from './lib/loadScript'; import { loadMap } from './lib/api'; import Map from './lib/Map'; import Marker from './lib/Marker'; import MassMarks from './lib/MassMarks'; import LayerTraffic from './lib/LayerTraffic'; import Polygon from './lib/Polygon'; import Polyline from './lib/Polyline'; import Circle from './lib/Circle'; import InfoWindow from './lib/InfoWindow'; class MarkerTest extends Component { constructor() { super(); this.state = {}; this._setMapRefer = this._setMapRefer.bind(this); this._setMarkerRefer = this._setMarkerRefer.bind(this); } componentDidMount() { loadMap('0325e3d6d69cd56de4980b4f28906fd8').then(AMap => { this.setState({ AMap }); }); } _setMapRefer (refer) { this.mapRefer = refer; window.$map = this.mapRefer; console.log('_setMapRefer:', this.mapRefer, this.markerRefer); } _setMarkerRefer (refer) { this.markerRefer = refer; window.$marker = this.markerRefer; console.log('_setMarkerRefer:', this.mapRefer, this.markerRefer); } render() { let center = [116.39, 39.9]; window.$map = this.mapRefer; window.$marker = this.markerRefer; console.log('render:', this.mapRefer, this.markerRefer); let markerIcon = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png'; switch (this.state.markerIndex) { case 1: markerIcon = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png'; break; case 2: markerIcon = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png'; break; default: case 0: markerIcon = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png'; break; } return (
This is content of this info window
Click 'Change Value' Button: