Skip to content

Commit 18c38cb

Browse files
author
Bojan Zivkovic
committed
Updating code for v4 of ESRI ArcGIS API
1 parent 369bd8d commit 18c38cb

File tree

3 files changed

+73
-32
lines changed

3 files changed

+73
-32
lines changed

build/resources/App4.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@import "https://js.arcgis.com/4.5/esri/css/main.css";
2+
3+
html, body, #root, .App {
4+
height: 100%;
5+
width: 100%;
6+
background-color: #cfcfd4;
7+
}
8+
9+
.App {
10+
text-align: center;
11+
}
12+
13+
.App-header {
14+
background-color: #222;
15+
height: 80px;
16+
padding: 20px;
17+
color: white;
18+
box-sizing: border-box;
19+
}
20+
21+
h1 {
22+
margin: 0.25em;
23+
}
24+
25+
/* Map view */
26+
#mapContainer {
27+
height: calc(100% - 80px);
28+
}

build/resources/App4.js

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,62 @@
11
import React, {Component} from 'react';
2-
import './App.css';
32
import * as esriLoader from 'esri-loader';
3+
import './App.css';
4+
5+
class App extends Component {
6+
constructor() {
7+
super();
48

5-
if (!esriLoader.isLoaded()) {
6-
esriLoader.bootstrap((err) => {
7-
if (err) {
8-
console.error(err);
9+
if (!esriLoader.isLoaded()) {
10+
esriLoader.bootstrap((err) => {
11+
if (err) {
12+
console.error(err);
13+
} else {
14+
this.createMap();
15+
}
16+
}, {
17+
// url: 'https://js.arcgis.com/4.4/' // Here you can change API version
18+
});
919
} else {
10-
createMap();
20+
this.createMap();
1121
}
12-
}, {
13-
// url: 'https://js.arcgis.com/4.4/' // Here you can change API version
14-
});
15-
} else {
16-
createMap();
17-
}
1822

19-
function createMap() {
20-
esriLoader.dojoRequire([
21-
"esri/Map",
22-
"esri/views/MapView"
23-
], function(Map, MapView){
24-
let map = new Map({
25-
basemap: "gray-vector"
26-
});
27-
window.map = map;
28-
let view = new MapView({
29-
map: map,
30-
container: "mapNode",
31-
basemap: 'gray-vector',
32-
center: [-100, 30],
33-
zoom: 3
23+
this.state = {
24+
map: null,
25+
view: null
26+
}
27+
}
28+
29+
createMap = () => {
30+
esriLoader.dojoRequire([
31+
"esri/Map",
32+
"esri/views/MapView"
33+
], (Map, MapView) => {
34+
let map = new Map({
35+
basemap: "gray-vector"
36+
});
37+
window.map = map;
38+
let view = new MapView({
39+
map: map,
40+
container: "mapContainer",
41+
basemap: 'gray-vector',
42+
center: [-100, 30],
43+
zoom: 3
44+
});
45+
46+
this.setState({
47+
map,
48+
view
49+
})
3450
});
35-
});
36-
}
51+
};
3752

38-
class App extends Component {
3953
render() {
4054
return (
4155
<div className="App">
4256
<div className="App-header">
4357
<h1>Welcome to ESRI React App</h1>
4458
</div>
45-
<div id="mapNode" />
59+
<div id="mapContainer" />
4660
</div>
4761
);
4862
}

build/resources/index-api-4.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
55
<meta name="theme-color" content="#000000">
66
<meta name="author" content="Bojan Zivkovic">
7-
<link rel="preload stylesheet" href="https://js.arcgis.com/4.4/esri/css/main.css">
87
<!--
98
manifest.json provides metadata used when your web app is added to the
109
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/

0 commit comments

Comments
 (0)