Arcgis map in react js not reponsive

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

Following is the component I wrote to load a basic arcgis map using react js

import React, { Component } from 'react'; import { loadModules } from 'esri-loader';  const options = {   url: 'https://js.arcgis.com/4.6/' };  const styles =  {   container: {     height: '100vh',     width: '100vw'   },   mapDiv: {     padding: 0,     margin: 0,     height: '100%',     width: '100%'   }, }  class BaseMap extends Component {    constructor(props) {     super(props);     this.state = {       status: 'loading'     }   }    componentDidMount() {     loadModules(['esri/Map', 'esri/views/MapView'], options)       .then(([Map, MapView]) => {         const map = new Map({ basemap: "streets" });         const view = new MapView({           container: "viewDiv",           map,           zoom: 15,           center: [78.4867, 17.3850]         });         view.then(() => {           this.setState({             map,             view,             status: 'loaded'           });         });       })    }    renderMap() {     if(this.state.status === 'loading') {       return <div>loading</div>;     }   }    render() {      return(           <div style={styles.container}>             <div id='viewDiv' style={ styles.mapDiv } >               {this.renderMap()}             </div>           </div>     )   } }  export default BaseMap; 

The map is loading. However, I'm unable to make it responsive.

If I remove the div around the view div or if I give the height and width of the outer div (surrounding viewDiv) as relative (styles.container: { height: '100%', width: '100%'}), the map does not render. No idea why. Any suggestions to make it responsive would be appreciated.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!