@@ -18,16 +18,6 @@ import MouseTool from '../mousetool';
1818
1919const Component = React . Component ;
2020const Children = React . Children ;
21- const ComponentList = [
22- Circle ,
23- GroundImage ,
24- InfoWindow ,
25- Markers ,
26- Marker ,
27- Polyline ,
28- Polygon ,
29- MouseTool
30- ] ;
3121
3222const configurableProps = [
3323 'layers' ,
@@ -146,7 +136,12 @@ class Map extends Component {
146136 renderChildren ( ) {
147137 return Children . map ( this . props . children , ( child ) => {
148138 if ( child ) {
149- if ( ComponentList . indexOf ( child . type ) === - 1 ) {
139+ const cType = child . type ;
140+ /* 针对下面两种组件不注入地图相关属性
141+ * 1. 明确声明不需要注入的
142+ * 2. DOM 元素
143+ */
144+ if ( cType . preventAmap || ( typeof cType === 'string' ) ) {
150145 return child ;
151146 }
152147 return React . cloneElement ( child , {
@@ -160,22 +155,6 @@ class Map extends Component {
160155
161156 initMapInstance ( ) {
162157 if ( ! this . map ) {
163- // let opts = {};
164- // if ('createOptions' in this.props) {
165- // opts = this.props.createOptions;
166- // } else {
167- // if ('zoom' in this.props) {
168- // opts.zoom = this.props.zoom;
169- // this.prevZoom = opts.zoom;
170- // }
171- // if ('center' in this.props) {
172- // opts.center = new window.AMap.LngLat(
173- // this.props.center.longitude,
174- // this.props.center.latitude
175- // );
176- // this.prevCenter = opts.center;
177- // }
178- // }
179158 const options = this . buildCreateOptions ( ) ;
180159 this . map = new window . AMap . Map ( this . mapWrapper , options ) ;
181160 const events = this . exposeMapInstance ( ) ;
0 commit comments