如何在ReactJs Project中使用Esri Arcgis Map? [英] How can I use Esri Arcgis Map in ReactJs Project?

查看:348
本文介绍了如何在ReactJs Project中使用Esri Arcgis Map?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Esri地图.要在我的项目中包含地图,这是我发现的内容:

I'm trying to use Esri map. To include map in my project, here is what I found:

require([
    "esri/map",
    "esri/dijit/Search",
    "esri/dijit/LocateButton",
    "esri/geometry/Point",
    "esri/symbols/SimpleFillSymbol",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/symbols/SimpleLineSymbol",

但是没有任何esri文件夹或npm软件包.因此,我在这里感到困惑. esri如何在项目中导入?

But there isn't any esri folder or npm package. Therefore, I'm confused here. How esri is imported in project?

推荐答案

使用esri-loader加载所需的esri模块.这是一个组件渲染底图.

Use esri-loader to load the required esri modules. This is a component rendering basemap.

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;

这将呈现基本地图,但没有响应.如果移除视图div周围的div或将外部div的高度和宽度(周围的viewDiv)指定为相对高度({height:'100%',width:'100%'}),则地图不会渲染.不知道为什么.任何使它具有响应性的建议将不胜感激.

This renders a base map but this is not 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 ({ height: '100%', width: '100%'}), the map does not render. No idea why. Any suggestions to make it responsive would be appreciated.

这篇关于如何在ReactJs Project中使用Esri Arcgis Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆