• This repository has been archived on 08/Jul/2022
  • Stars
    star
    314
  • Rank 133,353 (Top 3 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A few components to help you get started using the ArcGIS API for JavaScript and esri-loader with React

react-arcgis

Version build status Test Coverage

The react-arcgis repository is now archived (July 2022)

This project provided a library with a few ready to use React components (<Map />, <Scene />, <WebMap />, and <WebScene />) to get you started using the ArcGIS API for JavaScript in your React application. These components used esri-loader under the hood to lazy-load the ArcGIS API modules.

However, for a few years you have NOT needed react-arcgis to use the ArcGIS API in your React application. Instead it is best to use either @arcgis/core or esri-loader directly in your React application.

Please take a look at these modern alternatives to using react-arcgis:

Do you have a question related to JavaScript that isn’t specific to React? Post these questions in the GeoNET forum for the ArcGIS API for JavaScript.

Installation

IMPORTANT: This repository is now archived (July 2022) - please see above for how to use either @arcgis/core or esri-loader directly in your React application.

  1. Run npm i --save esri-loader @esri/react-arcgis in your React application

If you need to support browsers lacking a native promise implementation, you will have to add a global Promise constructor polyfill to your project, as react-arcgis does not include one. See the esri-loader documentation for more details.

Basic Usage

IMPORTANT: You must load ArcGIS API styles before using the components in this library. The snippets below assume you've already used one of the ways that esri-loader provides you with to load the ArcGIS API CSS.

Render a simple map in React:

import React from 'react';
import * as ReactDOM from 'react-dom';
import { Map } from '@esri/react-arcgis';

ReactDOM.render(
  <Map />,
  document.getElementById('container')
);

map

Or, render a 3D web-scene:

import React from 'react';
import * as ReactDOM from 'react-dom';
import { Scene } from '@esri/react-arcgis';

ReactDOM.render(
  <Scene />,
  document.getElementById('container')
);

You can also add webmaps and webscenes from ArcGIS Online:

import React from 'react';
import * as ReactDOM from 'react-dom';
import { WebMap, WebScene } from '@esri/react-arcgis';

ReactDOM.render(
    <div style={{ width: '100vw', height: '100vh' }}>
        <WebMap id="6627e1dd5f594160ac60f9dfc411673f" />
        <WebScene id="f8aa0c25485a40a1ada1e4b600522681" />
    </div>,
  document.getElementById('container')
);

webmap

If you want to change the style of the Map or Scene, just give it a class:

import React from 'react';
import * as ReactDOM from 'react-dom';
import { Scene } from '@esri/react-arcgis';

ReactDOM.render(
  <Scene className="full-screen-map" />,
  document.getElementById('container')
);

You can also pass properties into the Map, MapView, or SceneView via the viewProperties or mapProperties props:

import React from 'react';
import { Map } from '@esri/react-arcgis';

export default (props) => (
    <Map
        class="full-screen-map"
        mapProperties={{ basemap: 'satellite' }}
    />
)

map-properties

These properties are passed directly to the available properties on the corresponding ArcGIS API classes:

import React from 'react';
import { Scene } from '@esri/react-arcgis';

export default (props) => (
    <Scene
        style={{ width: '100vw', height: '100vh' }}
        mapProperties={{ basemap: 'satellite' }}
        viewProperties={{
            center: [-122.4443, 47.2529],
            zoom: 6
        }}
    />
)

scene

If you want to access the map and view instances directly after they are loaded, pass in an onLoad handler:

import React from 'react';
import { Map } from '@esri/react-arcgis';

export default class MakeAMap extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            map: null,
            view: null
        };

        this.handleMapLoad = this.handleMapLoad.bind(this)
    }

    render() {
        return <Map className="full-screen-map" onLoad={this.handleMapLoad} />;
    }

    handleMapLoad(map, view) {
        this.setState({ map, view });
    }
}

Don't forget an onFail handler in case something goes wrong:

import React from 'react';
import { WebScene } from '@esri/react-arcgis';

export default class MakeAScene extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            status: 'loading'
        };

        this.handleFail = this.handleFail.bind(this);
    }

    render() {
        return <WebScene className="full-screen-map" id="foobar" onFail={this.handleFail} />;
    }

    handleFail(e) {
        console.error(e);
        this.setState({ status: 'failed' });
    }
}

Advanced Usage

Configuring esri-loader

By default, the components in this library will use esri-loader's default options, which means they will lazy-load the modules from the CDN version of the ArcGIS API for JavaScript used by the version of esri-loader you have installed. See the esri-loader configuration documentation for information on how you can customize esri-loader's behavior.

Using setDefaultOptions()

The easiest way to do this is by calling esri-loader's setDefaultOptions() once at application startup before any of the components in this library are rendered.

import React from 'react';
import * as ReactDOM from 'react-dom';
import { setDefaultOptions } from 'esri-loader';
// app contains react-arcgis components
import { App } from './components/App.js';

// configure esri-loader to lazy load the CSS
// the fisrt time any react-arcgis components are rendered
setDefaultOptions({ css: true });

ReactDOM.render(
  <App />,
  document.getElementById('app')
);

This requires esri-loader@^2.12.0. If you are using an older version of esri-loader you should probably upgrade.

Using loaderOptions

If you can't use setDefaultOptions(), you can use the loaderOptions prop provided by each of the components in this library. That will be passed as options to loadModules(). Keep in mind that if you use loaderOptions, you must pass the same options to all react-arcgis components in your application, as well as any places where your application calls loadModules() directly.

Creating Your Own Components

The functionality available through the ArcGIS API for JavaScript goes well beyond just rendering maps, and if your application needs to do more with the map than simply show it, you will likely need to load and use additional classes from the ArcGIS API and provide the instances of those classes with references to the maps you've created with the components in this library.

Fortunately you've already installed esri-loader, which allows you to load any additional ArcGIS API modules your application might need. Also, react-arcgis provides the children of <Map />, <Scene />, <WebMap />, and <WebScene /> with access to their parent's map and view instances through props.

For example, let's convert a Bermuda Triangle graphic from this example into a react component:

import { useState, useEffect } from 'react';
import { loadModules } from 'esri-loader';

const BermudaTriangle = (props) => {

    const [graphic, setGraphic] = useState(null);
    useEffect(() => {

        loadModules(['esri/Graphic']).then(([Graphic]) => {
            // Create a polygon geometry
            const polygon = {
                type: "polygon", // autocasts as new Polygon()
                rings: [
                    [-64.78, 32.3],
                    [-66.07, 18.45],
                    [-80.21, 25.78],
                    [-64.78, 32.3]
                ]
            };

            // Create a symbol for rendering the graphic
            const fillSymbol = {
                type: "simple-fill", // autocasts as new SimpleFillSymbol()
                color: [227, 139, 79, 0.8],
                outline: { // autocasts as new SimpleLineSymbol()
                    color: [255, 255, 255],
                    width: 1
                }
            };

            // Add the geometry and symbol to a new graphic
            const graphic = new Graphic({
                geometry: polygon,
                symbol: fillSymbol
            });
            setGraphic(graphic);
            props.view.graphics.add(graphic);
        }).catch((err) => console.error(err));

        return function cleanup() {
            props.view.graphics.remove(graphic);
        };
    }, []);

    return null;

}

export default BermudaTriangle;

Now we can use the <BermudaTriangle /> component within our <Map />, <Scene />, <WebMap />, or <WebScene />, and the map and view props will automatically be supplied by react-arcgis:

import * as React from 'react';
import { Scene } from '@esri/react-arcgis';
import BermudaTriangle from './BermudaTriangle'; // The Graphic component we just made

export default (props) => (
    <Scene class="full-screen-map">
        <BermudaTriangle />
    </Scene>
)

bermuda-triangle

Using the ArcGIS Types

See the esri-loader documentation on working with ArcGIS types.

Migrating

From v4 to v5

First, make sure esri-loader is installed as a dependency of your application:

npm install --save esri-loader

Then, update any import statements for loadModules():

// Replace old `loadModules` imports...
// import { Map, loadModules } from '@esri/react-arcgis';

// With a new, separate esri-loader import:
import { Map } from '@esri/react-arcgis';
import { loadModules } from 'esri-loader';

Contributions

Anyone is welcome to contribute to this package. However, we do not plan to add any more components to this library. If you have created a component that you'd like to share, we encourage you to share it via CodeSandbox or a gist. Once you've done that feel free to open an issue and we'll help spread the word.

We gladly welcome bug fixes or improvements to documentation.

Here are some commands that may be helpful for development:

  • npm test: Runs the unit tests
  • npm run build: Builds the application

To run the demo application against the code you are developing, you'll need to run these commands:

npm link
npm run build
cd demo
npm i
npm link @esri/react-arcgis
npm start

Keep in mind that the start script only watches for changes to code in the demo app. You'll have to re-run npm run build each time you make changes in to the library and want to verify them in the demo app.

License

Copyright Β© 2017-2019 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's LICENSE file.

More Repositories

1

arcgis-python-api

Documentation and samples for ArcGIS API for Python
Python
1,885
star
2

esri-leaflet

A lightweight set of tools for working with ArcGIS services in Leaflet. πŸš€
JavaScript
1,551
star
3

jsapi-resources

A collection of resources for developers using the ArcGIS Maps SDK for JavaScript.
JavaScript
708
star
4

wind-js

An demo animation of wind on a Canvas layer in the JSAPI
JavaScript
690
star
5

geometry-api-java

The Esri Geometry API for Java enables developers to write custom applications for analysis of spatial data. This API is used in the Esri GIS Tools for Hadoop and other 3rd-party data processing solutions.
Java
679
star
6

terraformer

A geographic toolkit for dealing with geometry, geography, formats, and building geo databases
JavaScript
673
star
7

arcgis-runtime-samples-android

ArcGIS Runtime SDK for Android Samples
Java
665
star
8

esri.github.io

Esri GitHub landing page
JavaScript
510
star
9

gis-tools-for-hadoop

The GIS Tools for Hadoop are a collection of GIS tools for spatial analysis of big data.
507
star
10

esri-loader

A tiny library to help load ArcGIS API for JavaScript modules in non-Dojo applications
TypeScript
457
star
11

deep-learning-frameworks

Installation support for Deep Learning Frameworks for the ArcGIS System
426
star
12

arcgis-maps-sdk-dotnet-samples

Sample code for ArcGIS Maps SDK for .NET – WPF, WinUI, .NET MAUI
C#
407
star
13

arcgis-osm-editor

ArcGIS Editor for OpenStreetMap is a toolset for GIS users to access and contribute to OpenStreetMap through their Desktop or Server environment.
C#
399
star
14

arcgis-js-api

Minified version of the ArcGIS API for JavaScript
SCSS
391
star
15

resource-proxy

Proxy files for DotNet, Java and PHP.
PHP
370
star
16

bootstrap-map-js

A light-weight JS/CSS extension for building awesome mapping apps with Bootstrap and ArcGIS.
HTML
366
star
17

spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Java
354
star
18

arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
TypeScript
352
star
19

arcgis-runtime-samples-ios

Swift samples demonstrating various capabilities of ArcGIS Runtime SDK for iOS
Swift
324
star
20

i3s-spec

This repository hosts the specification for Scene Layers which are containers for arbitrarily large amounts of geographic data. The delivery and persistence model for Scene Layers, referred to as Indexed 3d Scene Layer (I3S) and Scene Layer Package (SLPK) respectively, are specified.
319
star
21

arcgis-pro-sdk

ArcGIS Pro SDK for Microsoft .NET is the new .NET SDK for the ArcGIS Pro Application.
282
star
22

arcgis-cookbook

Chef cookbooks for ArcGIS
Ruby
274
star
23

arcade-expressions

ArcGIS Arcade expression templates for all supported profiles in the ArcGIS platform.
JavaScript
273
star
24

developer-support

Proof of concept developer code and samples to help be successful with all ArcGIS developer products (Python, NET, JavaScript, Android…). The repository is designed to be an exchange for sharing coding conventions and wisdom to developers at all skill levels.
C#
258
star
25

calcite-design-system

A monorepo containing the packages for Esri's Calcite Design System
TypeScript
252
star
26

cedar

JavaScript Charts for ArcGIS
Handlebars
250
star
27

geoportal-server

Geoportal Server is a standards-based, open source product that enables discovery and use of geospatial resources including data and services.
C#
244
star
28

calcite-maps

A Bootstrap theme for designing, styling and creating modern map apps.
JavaScript
237
star
29

awesome-arcgis-developers

A curated list of resources to help you with ArcGIS development, APIs, SDKs, tools, and location services
230
star
30

esri-leaflet-geocoder

helpers for using the ArcGIS World Geocoding Service in Leaflet
JavaScript
227
star
31

quickstart-map-js

ArcGIS JavaScript mapping samples to get you started fast.
HTML
218
star
32

vitruvio

Vitruvio brings the powerful ArcGIS CityEngine procedural modeling capabilities to Unreal Engine.
C++
215
star
33

angular-esri-map

A collection of directives to help you use Esri maps and services in your Angular applications
JavaScript
213
star
34

arcgis-pro-sdk-community-samples

ArcGIS Pro SDK for Microsoft .NET Framework Community Samples
C#
210
star
35

cityengine-sdk

CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
204
star
36

arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
C#
198
star
37

ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Python
194
star
38

raster-functions

A curated set of lightweight but powerful tools for on-the-fly image processing and raster analysis in ArcGIS.
Python
188
star
39

arcgis-to-geojson-utils

Tools to convert ArcGIS JSON geometries to GeoJSON geometries and vice-versa.
JavaScript
188
star
40

raster-deep-learning

ArcGIS built-in python raster functions for deep learning to get you started fast.
Python
187
star
41

lerc

Limited Error Raster Compression
C++
179
star
42

generator-esri-appbuilder-js

Yeoman generator to help customize Esri's WebAppBuilder
JavaScript
179
star
43

public-transit-tools

Tools for working with GTFS public transit data in ArcGIS
Python
159
star
44

geodev-hackerlabs

A place to learn how to build geo apps with the ArcGIS Platform.
HTML
157
star
45

offline-editor-js

ArcGIS JavaScript library for handling offline editing and tiling.
JavaScript
156
star
46

ago-assistant

A swiss army knife for your ArcGIS Online and Portal for ArcGIS accounts
JavaScript
152
star
47

storymap-tour

The Story Map Tour is ideal when you want to present a linear, place-based narrative featuring images or videos.
JavaScript
149
star
48

joint-military-symbology-xml

Joint Military Symbology Markup Language is a data encapsulation of MIL-STD-2525D and APP-6(D).
C#
143
star
49

arcgis-js-cli

CLI to build a template application and widgets using the ArcGIS API for JavaScript
TypeScript
137
star
50

arcgis-viewer-flex

Source code for ArcGIS Viewer for Flex - a great application framework for web applications.
ActionScript
135
star
51

arcgis-webpack-plugin

Webpack plugin for the ArcGIS API for JavaScript
JavaScript
134
star
52

solutions-geoprocessing-toolbox

Models, scripts, and tools for use in ArcGIS Desktop and Server to support defense and intelligence workflows.
Python
133
star
53

file-geodatabase-api

FileGeodatabaseAPI_1.4 (1.4.0.183) The File Geodatabase C++ API for Windows, MacOS and Linux
131
star
54

arcgis-maps-sdk-samples-qt

ArcGIS Maps SDK for Qt Samples
C++
129
star
55

geojson-layer-js

An easy way to load GeoJSON data into your ArcGIS map
JavaScript
126
star
56

OptimizeRasters

OptimizeRasters is a set of tools for converting raster data to optimized Tiled TIF or MRF files, moving data to cloud storage, and creating Raster Proxies.
HTML
126
star
57

arcgis-experience-builder-sdk-resources

ArcGIS Experience Builder samples
TypeScript
125
star
58

geojson-utils

A set of utilities for converting between standard geojson and other json formats
JavaScript
123
star
59

arcobjects-sdk-community-samples

This repo contains the source code samples (.Net c#, .Net vb, and C++) that demonstrate the usage of the ArcObject SDK.
C#
118
star
60

ago-admin-wiki

A collection of code samples, scripts, hacks, tools, and information for ArcGIS Online administrators.
117
star
61

arcgis-maps-sdk-java-samples

ArcGIS Maps SDK for Java samples
Java
112
star
62

arcgis-maps-sdk-toolkit-qt

ArcGIS Maps SDK for Qt Toolkit
C++
112
star
63

android-gps-test-tool

Test all aspects of Android's location capabilities. Configurable for trying out different scenarios.
Java
111
star
64

arcgis-powershell-dsc

This repository contains scripts, code and samples for automating the install and configuration of ArcGIS (Enterprise and Desktop) using Microsoft Windows PowerShell DSC (Desired State Configuration).
PowerShell
111
star
65

calcite-web

Authoritative front-end development resources for Calcite design initiative. Includes extendable base components and styles, as well as a modular and efficient framework for ArcGIS properties.
SCSS
108
star
66

arcgis-maps-sdk-unity-samples

Sample code for the ArcGIS Maps SDK for Unity.
C#
107
star
67

palladio

Palladio enables the execution of CityEngine CGA rules inside of SideFX Houdini.
C++
101
star
68

maps-app-android

Your organisations mapping app built with the runtime SDK for android
Java
101
star
69

storymap-journal

The Story Map Journal is ideal when you want to combine narrative text with maps and other embedded content.
JavaScript
97
star
70

arcgis-appstudio-samples

Collection of samples available in AppStudio for ArcGIS desktop to learn and help build your next app.
QML
97
star
71

geoportal-server-catalog

Esri Geoportal Server is a next generation open-source metadata catalog and editor, based on elasticsearch.
JavaScript
95
star
72

storymap-cascade

The Story Map Cascadeβ„  app lets you combine narrative text with maps, images, and multimedia content in an engaging, full-screen scrolling experience.
JavaScript
94
star
73

dojo-theme-flat

Custom flat theme based on Twitter's Bootstrap for Dojo dijits, dgrid, and esri widgets.
CSS
92
star
74

html5-geolocation-tool-js

Mobile ArcGIS API for JavaScript samples for testing various geolocation configurations.
HTML
92
star
75

application-boilerplate-3x-js

Starter application that simplifies the process of building templates for the ArcGIS.com template gallery.
JavaScript
90
star
76

angular-cli-esri-map

Example Angular component for building mapping applications with the ArcGIS API for JavaScript
TypeScript
88
star
77

arcgis-vectortile-style-editor

A simple Vector Tile Style Editor to update the styles of Esri Vector Basemaps
CSS
88
star
78

feedback-js-api-next

Try out the next release of the ArcGIS Maps SDK for JavaScript and share your feedback. Be warned: this release is still in development and is unstable.
87
star
79

workforce-scripts

A set of scripts to help administer Workforce projects.
Jupyter Notebook
77
star
80

ago-tools

A Python package to assist with administering ArcGIS Online Organizations.
Python
77
star
81

esri-leaflet-doc

Documentation, API Reference and Samples
Handlebars
77
star
82

cordova-plugin-advanced-geolocation

Highly configurable native Android interface to both GPS and NETWORK on-device location providers.
Java
74
star
83

maps-app-javascript

Your organizations maps app built with ArcGIS API for Javascript
TypeScript
73
star
84

collector-tools

A set of python scripts and geoprocessing tools to automate common tasks and workflows in conjunction with Collector for ArcGIS
Python
73
star
85

arcgis-maps-sdk-unreal-engine-samples

Sample code for the ArcGIS Maps SDK for Unreal Engine.
C++
73
star
86

webhooks-samples

Sample receivers, scripts, and workflows to help you get started with Webhooks in ArcGIS Enterprise
Python
72
star
87

terraformer-wkt-parser

Well-Known Text parser for Terraformer
JavaScript
71
star
88

geoprocessing-tools-for-hadoop

The Hadoop GP Toolbox provides tools to exchange features between a Geodatabase and Hadoop and run Hadoop workflow jobs.
Python
71
star
89

dojo-bootstrap-map-js

Samples for how to use the Esri ArcGIS API for JavaScript w/ Bootstap via Dojo-bootstrap
JavaScript
71
star
90

public-information-map-template-js

An ArcGIS Online mapping template to showcase social media on a map for disaster response and public information.
JavaScript
69
star
91

geoform-template-js

GeoForm is a configurable template for form based data editing of a Feature Service.
JavaScript
67
star
92

react-redux-js4

Boilerplate ArcGIS JS API 4.x app using React and Redux
JavaScript
66
star
93

calcite-ui-icons

A collection of UI icons built by Esri for applications.
JavaScript
64
star
94

pyprt

Python bindings for the "Procedural Runtime" (PRT) of CityEngine by Esri.
C++
64
star
95

mdcs-py

MDCS is an acronym for Mosaic Dataset Configuration Script and is the entry point to a collection of Python classes/libraries that could be consumed by a Python client application to complete a given workflow for creating a mosaic dataset, populating it with data, and setting all required/desired parameters.
Python
64
star
96

arcgis-maps-sdk-dotnet-demos

Demo applications provided by the ArcGIS Runtime SDK for .NET Team
C#
63
star
97

storymap-series

The Story Map Series lets you present a series of maps via tabs, numbered bullets, or a side accordion.
JavaScript
63
star
98

node-geoservices-adaptor

This is a node.js implementation of the ArcGIS REST API
JavaScript
63
star
99

cluster-layer-js

One example of how to cluster many point features
JavaScript
62
star
100

local-government-desktop-addins

A series of ArcGIS Desktop Add-ins used in the ArcGIS for Local Government editing maps.
C#
61
star