Giter Club home page Giter Club logo

react-arcgis's Introduction

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.

react-arcgis's People

Contributors

abdel-abdelrazek avatar alukach avatar dependabot-preview[bot] avatar favna avatar gavinr avatar gavinr-maps avatar jgravois avatar jlyman avatar maka-io avatar monkalways avatar nicksenger avatar tomwayson avatar tsarapke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-arcgis's Issues

Legend out of a map

Hello,

please we would need Legend component from Widgets put out of a WebScene. Is that possible?
Actually we have reach our goal to create it out of the WebScene container through the 'view' attribute but after its loaded the legend is shown still in the Map.
We really appreciate your work!

Thank you,
Jakub

"react-arcgis": "^3.1.0" Can't resolve 'esri-promise'

1st off - amazing library! I have been using 3.0.0 without issue.

I had to add: "esri-promise": "^0.4.1" to my package.json
otherwise I get the following error when trying to use 3.1.0

Module not found: Can't resolve 'esri-promise' in '<PROJECT_PATH>\node_modules\react-arcgis'

Looking @ the 3.1.0 index.js - it still contains:

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("esri-promise"))

I'm not sure if you intended consumers of your package to have to explicitly depend on esri-promise, esp. when your 3.1.0 notes say you have moved away from it.

Popup Template not working properly

I am having some issues with the popup template not working properly. It somehow works, since it is able to select my marker once clicked, however the popup template doesn't show. Here is a picture of how it looks when the marker is clicked https://github.com/lauritapear/ReactJS/blob/master/noPopup.png and below is my code.

import * as React from 'react';

import { Map } from 'react-arcgis';

import { Scene } from 'react-arcgis';

import EsriMarker from '../EsriMarker';



class EsriMap extends React.Component{

    render() {

        return (

        <Scene style={{ width: '100vw', height: '100vh' }}

          mapProperties={{ basemap: 'streets-navigation-vector' }}

          viewProperties={{

              center: [172.58804957425, -43.5106019527023],

              zoom: 25

          }}>



           <EsriMarker  {...this.props}/>



        </Scene>

     );

    }

}



export default EsriMap;
import React from 'react';
import {loadModules} from 'react-arcgis';

class EsriMarker extends React.Component {
  render() {
    return null;
  }

  componentWillMount() {
    this.renderMarker();
  }

  renderMarker() {

    loadModules(["esri/layers/GraphicsLayer", "esri/Graphic",
    "esri/geometry/Point", "esri/PopupTemplate"])
    .then(([GraphicsLayer, Graphic, Point, PopupTemplate]) => {

      let markerLayer = new GraphicsLayer();
      this.props.markers.forEach(marker => {

        let point = new Point({
          x: parseFloat(marker.position.lng),
          y: parseFloat(marker.position.lat)
        });

        let markerSymbol = {
          type: "picture-marker",
          height: 25,
          width: 25,
          url: "../../images/blue.png"
        };

        let theAtt = {
          Name: "some name",
          Owner: "some Owner",
          Length: "some lengthß"
        };

        let pop = new PopupTemplate({
          title: "pop title",
          content: '<div className="info">ID: someID ' + '<br/><span>ZONE: someZone </span>'
        });

        const graphic = new Graphic({
          geometry: point,
          symbol: markerSymbol,
          attributes: theAtt,
          popupTemplate: pop
        });

        markerLayer.add(graphic);
      });

      this.props.view.map.add(markerLayer);
    }).catch((err) => console.error(err));
  }
}

export default EsriMarker;

Map is not responsive

import React, { Component } from 'react';
import { Map } from 'react-arcgis';

class App extends Component {
render() {
return (
<div style={{ width: '100vw', height: '100vh' }}>
<Map />
</div>
) } } default export App;`

The Map does not render if I remove the div around <Map /> component. It does not even render if I make the height and width relative:
<div style={{ width: '100%', height: '100%' }}>
<Map />
</div>

So, basically I am unable to make the map responsive. I want it to take the height and width of its parent div.

Identity Manager

Users would benefit from a component which wraps the identity manager, and provides a simple way to retrieve the login token.

Painting graphic in a map does not work

Hi, I am trying to paint a simple circle in a map. I can see the circle painted before the map load. Once is loaded the circle is not there. Looks like is behind the map.

Thank you for the library.

<Map
    style={{ width: '100%', height: '500px' }}
    mapProperties={{
        basemap: "topo-vector",
    }}
    viewProperties={{
        center: [4.305098, 51.895311],
        zoom: 10
    }}
>
    <Graphic>
        <Geometry.Point
            geometryProperties={{
                latitude: 51.895311,
                longitude: 4.305098
            }}
        />
        <Symbols.SimpleMarkerSymbol
            symbolProperties={{
                color: [226, 119, 40],
                outline: {
                    color: [255, 255, 255],
                    width: 2
                }
            }}
        />
    </Graphic>
</Map>

Showing maps from two different portals

Hi,

I am writing an app in React to show maps and reports in a "dashboard" style.

I saw a link to Issue 53 talking about being able to assign different portal urls using esri/config (which I had used before), and gave it a go.

    componentWillMount() {
        loadModules([
            'dojo/_base/lang',
            'esri/config',    
            'esri/identity/OAuthInfo',
            'esri/identity/IdentityManager'
        ]).then(([ 
            lang,
            esriConfig, 
            OAuthInfo, 
            IdentityManager 
        ]) => {
            var portalUrl = this.props.portalUrl;
            esriConfig.portalUrl = portalUrl;

The problem is, having two of these different components trying to load from two separate portals runs into an issue where esri/config is static in the background, and only one portalUrl will be used.

I was able to figure out authenticating for two different portals at the same time using the IdentityManager class, but esri/config is not quite as flexible.

Am I missing something? Or will there be future support for being able to pass in full URLs for WebMaps, or the ability to set more configuration settings on the WebMap?

Feature Layer not Rendering

For whatever reason I can't get loadModules() to work with a FeatureLayer. Console.log(layer) shows the layer, so it's there. I've tried adding a new graphic too, similar to the example, but that won't render either.


/*=======App.js========*/

import React, { Component } from 'react';
import { Map } from 'react-arcgis';
import FeatureLayer from './FeatureLayer'

class App extends Component {

  render() {
    return (
      <div style={{ width: '100%', height: '100vh', backgroundColor: 'green'}}>
        <Map 
          mapProperties={{ basemap: 'streets' }}
          viewProperties={{ center: [-73.950, 40.702], zoom: 15 }}
        >
          <FeatureLayer />
        </Map>
      </div>
    )
  }
}

export default App



/*=======FeatureLayer.js========*/

import React, { Component } from 'react';
import { loadModules } from 'react-arcgis';
 
export default class FeatureLayer extends Component {
    constructor(props) {
        super(props);
        this.state = {
            layer: null,
        };
    }
 
    render() {
        return null;
    }
 
    componentWillMount() {
        const { map, view, url } = this.props

        loadModules(['esri/layers/FeatureLayer', 'esri/Graphic']).then(([ FeatureLayer, Graphic ]) => {
            const layer = new FeatureLayer({
                url: 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/NYCDemographics1/FeatureServer/0',
                outFields: ['*']
            })
            this.props.map.add(layer)

            const point = { type: 'point', x: -73.950, y: 40.702, spatialReference: { wkid: 4326 } }
            const simpleMarker = {
                type: 'simple-marker',
                color: 'red',
                size: '10px',
                outline: {
                    color: 'black',
                    width: 3
                }
            }

            const graphic = new Graphic({
                geometry: point,
                symbol: simpleMarker
            })
            this.props.view.graphics.add(graphic)

            this.setState({ layer });
        }).catch((err) => console.error(err))
    }
 
    componentWillUnmount() {
        this.props.map.remove(this.state.layer)
    }
}

The ArcGIS API failed to load.

Using Meteor 1.6, React, and GraphQL with this simple example:

import { graphql, compose } from 'react-apollo';
import gql from 'graphql-tag';

import React, { Component } from 'react';
import { Map } from 'react-arcgis';

class HomeComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }


    render() {
        return (
            <Map style={{ height: '95vh', width: '95vw' }} />
        );
    }
}

const geoJSON = gql`
    {
        features
    }
`;
const Home = compose(
    graphql(geoJSON),
)(HomeComponent);

export { Home, HomeComponent };

Typescript emitted no output for C:\Dev\Test\react-test\node_modules\react-arcgis\index.ts.

Module build failed when using react-arcgis

ERROR in ./node_modules/react-arcgis/index.ts
Module build failed: Error: Typescript emitted no output for C:\Dev\Test\react-test\node_modules\react-arcgis\index.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Dev\Test\react-test\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Dev\Test\react-test\node_modules\ts-loader\dist\index.js:29:12)
 @ ./src/components/well/well.tsx 14:21-44
 @ ./src/app.tsx

My package dependencies are as follows:

 "devDependencies": {
    "source-map-loader": "^0.2.3",
    "ts-loader": "^3.2.0",
    "typescript": "^2.6.2",
    "webpack": "^3.10.0"
  },
  "dependencies": {
    "@types/react": "^16.0.34",
    "@types/react-dom": "^16.0.3",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  }

Unable to change portalHostname for WebMap

Hello, I just recently started using the package, and everything works great as intended for my use case except the ability to change the portalHostaname for a WebMap. Our organization uses an internal maps server, and I am wondering if there is a plan for the WebMap to overwrite the arcgis online hostname. For example:
<WebMap portalHostname="https://<portal location>/portal/sharing/rest/content/items" id="6627e1dd5f594160ac60f9dfc411673f" />

Is there a possibility to set the map spatialReference?

Hello.
I'm using this library to create all the v4 widgets and a custom BasemapGallery. I want to use my own imagery using a spatialReference WKT i have from my client. Do you know if its is possible to change viewProperties spatialReference with WKT text?

Error: [esri.core.Promise] DEPRECATED

First of all, excuse my English, I had a help from the Google Translator ... =]

I'm starting to use your library and congratulations, it's very intuitive and functional, but in the most current version (3.3.0) when events occur in zoom in or zoom out a warning related to a promise is triggered:

capturar

I think I would have to make the changes in the library, right?

The MapView does not get resolved

Hi,
Refering to this react-arcgis repo. I wrote the following component to render basemap.

`import React, { Component } from 'react';
import { loadModules } from 'esri-loader';

class BaseMap extends Component {
constructor(props) {
super(props);

this.state = {
  mapContainerId: 'basemap',
  status: 'loading'
}

}
componentDidMount() {
loadModules(['esri/Map', 'esri/views/MapView'])
.then(([Map, View]) => {
const map = new Map(this.props.mapProperties);
const viewProperties = {
map,
container: this.state.mapContainerId,
...this.props.viewProperties
};
const rView = new View(viewProperties);
rView.then((view) => {
this.setState({
map,
view,
status: 'loaded'
});
})
.catch((e) => {
this.setState({ status: 'failed' });
throw e;
})
})
.catch((e) => {
this.setState({ status: 'failed' });
throw e;
})
}

render() {
if (this.state.status === 'loaded') {
return (
<div id={this.state.mapContainerId} style={{ width: '100%', height: '100%' }}>
);
}
else if(this.state.status === 'loading') {
return (

Loading

);
}
else {
return (
Failed loading map

);
}
}
}

export default BaseMap;
`

But the status does not change to loaded. It is stuck at loading.
On debugging I found that the MapView promise inside componentDidMount() function is not getting resolved. It's not going into the catch block too. It is stuck there.

I also tried using the BaseMap component you provided in react-arcgis

import React, { Component } from 'react'; import { Map } from 'react-arcgis'; export default class App extends Component { render() { return ( <div> <Map /> </div> ); } }

But no map is loaded. Initially I can see loading after that the div remains just blank.
The map loaded after I wrapped it inside a div like this
<div style={{ width: '100vw', height: '100vh' }}> <Map /> </div>

Update React and @types

Need to update the React version and use the latest @types for React and the JS API.

There are various issues when strict rules are set in .tsconfig which need to be addressed for typescript users.

Cannot find namespace '_esri'

This looks like an amazing esri wrapper, but I'm gettings the following error when I try to build it:

Cannot find namespace '_esri'

Any ideas?

Thanks!

Failing to get most basic example working

Hi, I write with a very vague issue: I'm unable to get any example from the README.md to work. I feel like I may very well be missing something basic or obvious but can't figure out what that would be.

I'm using create-react-app with the react-scripts-ts scripts (i.e. create-react-app myApp --scripts-version-react-scripts-ts), as described in the Microsoft Typescript-React-Starter .

The Map component renders as "Loading.." and never proceeds further. Neither the onLoad or onError handlers seem to be called.

You can find an example of the application here: https://codesandbox.io/s/170ooj28l

Use of Widgets in v3

Hi, I am on v 2.0.7 and am using the named widget component in my code. I'm using the search widget. Can you give an example of how to use the widget with version 3 of your api? thanks !

Typescript error

I've got an existing React app (built in Typescript) and when I install this component, my project will no longer build and yields a rather (to me at least) unhelpful error around ReactElement<P, T>. Weirdly, the build error occurs even if I'm not importing the module anywhere. The map will render ever so briefly but then the app will dump me to an error screen once Typescript has done its thing.
Is this some issue on my end or the esri-react end?

My setup:

  • Existing app with CRA
  • React 16.8.6
  • Typescript 3.3.4000

Reproduce:

  • Just npm install @esri/react-arcgis

My code:

import React, { useEffect, useRef, useState } from 'react';
import { Container } from 'reactstrap';
// tslint:disable-next-line: no-var-requires
require('../../sass/PGRFMap.scss');
import { Map } from '@esri/react-arcgis';
import * as ReactDOM from 'react-dom';

const PGRFMap: React.FC = () => {
    const viewDiv = useRef(null);

    useEffect(() => {
        ReactDOM.render(<Map />, viewDiv.current);
    }, [viewDiv]);

    return (
        <Container fluid className="h-100 p-0 m-0 fixed-top">
            <div id="viewDiv" ref={viewDiv} />
        </Container>
    );
};

export default PGRFMap;

Error:

TypeScript error: Type 'T' does not satisfy the constraint 'string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)'.
  Type 'string | number | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)' is not assignable to type 'string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)'.
    Type 'number' is not assignable to type 'string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)'.
      Type 'T' is not assignable to type 'string'.
        Type 'string | number | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)' is not assignable to type 'string'.
          Type 'number' is not assignable to type 'string'.  TS2344

     98 |         T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>,
     99 |         P = Pick<ComponentProps<T>, Exclude<keyof ComponentProps<T>, 'key' | 'ref'>>
  > 100 |     > extends ReactElement<P, T> { }
        |                               ^
    101 | 
    102 |     /**
    103 |      * @deprecated Please use `FunctionComponentElement`

Displaying text graphics

We are using react-arcgis to display maps for our application and I'd like to display text on the map. I'm not real familiar with creating esri maps but it seems like this would be done using a TextSymbol inside Graphic. However, I'm not seeing TextSymbol as an option of the Symbols component. Is there another way to display text on a map with react-arcgis or is TextSymbol something that could be added to the package. Thanks for any direction you might provide.

Map not loading

I am working on adding the react-arcgis library to my application but I am not able to get the map to complete the initial load.

As of right now it just renders "Loading..." at the top of the screen and never completes beyond that. If I remove the stylesheet link in the index.html page, the map will render but just infinitely scroll.

My package.json is using

"@esri/react-arcgis": "^4.0.0",
"react": "^16.7.0"

My index.html looks like so:

<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
    <style>
      html,
      body,
      #root {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

And my React component is

import * as React from "react";
import { Map } from "@esri/react-arcgis";

export class App extends React.Component<{}, {}> {
    public render() {
        return (
            <div>
                <Map />
            </div>
        );
    }
}

[esri.core.Promise] DEPRECATED: then() -- use .when(callback, errback) instead

Since v.3.1.0, I'm getting a bunch of these console errors:

[esri.core.Promise] DEPRECATED: then() -- use .when(callback, errback) instead

This happens even when just rendering a map component and the error gets spammed over and over when implementing a promise. When I revert the package to version 3.0.0, it is fine and the error doesn't occur at all.

BTW - Thanks for the package though! It's great :)

Using FeatureLayer with hundreds of Points

Hi, thanks for the excellent implementation. I'm trying to render a Map with hundreds of Points. While I am able to do so following the examples here, I found that the performance is really bad when the data is large. For this, I was adding to the Map an array of Graphics objects, one per point.

const myGraphs = features.map(function (item) {
      return (
        <Graphic key={`article_${item.id}`}  >
          <Symbols.SimpleMarkerSymbol
            symbolProperties={{
              color: [0, 0, 0],
              outline: {
                color: [100, 100, 100],
                width: 0.0005
              }
            }}
          />
          <Geometry.Point
            geometryProperties={{
              x: item.geometry.coordinates[0],
              y: item.geometry.coordinates[1]
            }}
          />
        </Graphic>);
    });
  <Map
              dataFlow="oneWay"
              mapProperties={{ basemap: 'oceans' }}
              viewProperties={this.state.viewProperties}
              onLoad={this.handleMapLoad}
              onDrag={this.handleDrag}
              onMouseWheel={this.handleMouseWheel}
     >{myGraphs}</Map>

In the conventional ArcGIS API you can wrap everything into a FeatureLayer and produce a single SVG. So, what I'd like to do is source an array of Points into the FeatureLayer:

 var layer = new FeatureLayer({
            source: graphics, // autocast as an array of esri/Graphic
            // create an instance of esri/layers/support/Field for each field object
            fields: fields, // This is required when creating a layer from Graphics
            objectIdField: "ObjectID", // This must be defined when creating a layer from Graphics
            renderer: my_renderer, // set the visualization on the layer
            geometryType: "point", // Must be set when creating a layer from Graphics
            popupTemplate: my_template
        });
        map.add(layer);

where the source: graphics is an array of objects like this:

   [ {
            geometry: new Point({
                x: feature.geometry.coordinates[0],
                y: feature.geometry.coordinates[1]
            }),
            // select only the attributes you care about
            attributes: {
                ObjectID: feature.id,
                Foo: feature.Foo
            }
    },....];

Is something like this doable with your implementation?

Thanks!

The zoom property of Scene does't work.

what's wrong with my code?
render() {
return (
<div style={{ width: '100vw', height: '100vh' }}>
<Scene class="full-screen-map"
mapProperties={{ basemap: 'satellite' }}
viewProperties={{
center: [-64.78, 32.3],
zoom: 3
}}
>



)

}

Infinite loading

Hi, I use the basic example you provided, it gives an error 'Warning: Prop id did not match. Server: "0.paaefptyspn" Client: "0.h4bxsnwbfl"', and doesn't render the map, only shows "Loading" message.

Using the "Map" component renders strangely.

Code such as:

ReactDOM.render(<Map style={{ width: '20vw', height: '20vh' }}/>, document.getElementById('root'));

creates a map of the appropriate size however the actual component appears to be 40vh in height and is split in half with the top half being the map and the bottom half containing any graphics placed within the map component. EX:
ReactDOM.render(<Map style={{ width: '20vw', height: '20vh' }}><MapGraphic/></Map>, document.getElementById('root'));

where MapGraphic is an exact copy of the 'BermudaTriangle ' code renders as
https://imgur.com/5b8u8gd

Replacing Map with Scene works as one would expect, only the Map component seems effected.

"ArcGIS API failed to load" Due to view_1.then is not a function

A dependency seems to have changed since I last did an npm install (I believe on 4/24) that is now causing react-arcgis to fail.

This issue is happening in this code block:

Lines 26 to 50 from react-arcgis/dist/esm/components/ArcComposites.js

        var Map = _a[0], View = _a[1];  
        var mapData = new Promise(function (resolve, reject) {  
            try {  
                var map_1 = new Map(props.mapProperties); // Make the map  
                var viewProperties = __assign({ map: map_1, container: containerId }, props.viewProperties);  
                var view_1 = new View(viewProperties); // Make the view  
                var typedView_1 = view_1;  
                Object.keys(eventMap).forEach(function (key) {  
                    if (props[key]) {  
                        typedView_1.on(eventMap[key], props[key]);  
                    }  
                });  
                view_1.then(function () {  
                    resolve({ map: map_1, view: view_1 });  
                }, function (err) {  
                    reject(err);  
                });  
            }  
            catch (err) {  
                reject(err);  
            }  
        });  
        return mapData;  
    } }))); };

The Issue

The exception is being caught on line 51 (of dist file) with TypeError: view_1.then is not a function:
image

I've been digging to find where the issue is originating, but I'm stumped. My code worked an hour ago, and it's now throwing this exception for both Scene and Map Views. It looks like esri-loader updated from 4.6 to 4.7 as the default build in the last few days, but I'm not thinking that this is the most likely culprit.

It seems that View was previously returning a Promise but is now just returning an object? It doesn't appear that Promise support is the underlying issue as the Promise was created on line 33 just fine (and the exception is being thrown within a Promise).

Do any ideas come to mind?

P.S. This is a fabulous wrapper for the Esri API. Thank you!

Popups as part of the API

Popups should probably have their own component in react-arcgis, so that the user can avoid having to interact directly with the map instances.

The Arcgis API failed to load

Hello,
Is there possibility to use ArcGIS version 4.4 with this library? I wrote app using version 4.9 and now I found out that I cannot display the results on another computer, only version 4.4 of ArcGIS API is working.

Example of loading kml?

Is there an example of loading a kml file? Or could someone suggest how I might load a kml file into a map?

The ArcGIS API failed to load

Hi,

I am not able to load the map at the UI, no error found anywhere.
I just get the display at frontend as 'The ArcGIS API failed to load'

Is there any configuration that needs to be done additionally?

Below the code snippet i am using
import React from 'react';
import { Map } from 'react-arcgis';

class Recepient extends React.Component {

constructor(props) { super(props); this.state = { viewProperties: { center: [-122.4443, 47.2529], scale: 50000 } }; }

`handleMapLoad(map, view) {
    view.ui.remove("compass");
    view.ui.remove("zoom");
    view.ui.remove("navigation-toggle");
}`

render() { return ( <div style={{ width: '100vw', height: '100vh' }}> <Map dataFlow="oneWay" viewProperties={this.state.viewProperties} onLoad={this.handleMapLoad} onDrag={(e) => { e.stopPropagation() }} onMouseWheel={(e) => { e.stopPropagation() }} /> </div> ); }
}`

export default Recepient;

Thanks & Regards,
Kunal

ElevationLayer Loading Error

Hi, thank you so much for your excellent working, I'm using this in our project now and it helps me a lot~~

According to the official SDK, the ElevationLayer should be added like this:
map.ground.layers.add(elevLyr);
If using map.layers.add(), ArcGIS API will just ignore the elevation layer and print some error message in the console.

I solved this by adding some if clause in the LayerBase.tsx, maybe you could fix this in future.

wanted: additional project maintainers/contributors (all experience levels welcome)

even if you don't consider yourself an experienced React or ArcGIS API for JavaScript developer, this popular project is a great opportunity to get your hands as dirty as you want with some tech that continues to grow in popularity and help other developers 💻.

if you're willing, even sporadically, to review issues, help with documentation or chip in with an enhancement request or bug fix, please click the Watch button and jump on in 🏊‍♀️!

the repository is a friendly place and i guarantee you'll learn something in the process 📚.

cc/ @NoashX, @odoe, ??

Featurelayer

when I add Featurelayer to the map it is rendered correctly in development mode in all browser, but when I build the project it does so only in chrome and Edge but not in IE11,
So kindly if there is something I should do to have it working in IE11, I will be grateful if you let me know.

Question: How to config the js API URL?

Hi, Nick Senger:

Thank your work so much, and i like this react component very much.

But i notice that there is no flag to control which version or url address of the arcgis js API server.

Is it possible to config for this?

thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.