i cannot find the document for hosted locally arcgis js api v4.2,
It seems different from all previous versions.
how can i do
Solved! Go to Solution.
Hello,
If you look in the extracted download of 4.2 you will find a document that outlines how to host it locally:
<API extraction folder>/arcgis_js_v420_api/arcgis_js_v420_api/arcgis_js_api/javascript/downloads/install-windows/index.html
The instructions below assume that you are installing the ArcGIS API for JavaScript library in the following location https://www.example.com/javascript/api/4.20/ (C:\Inetpub\wwwroot\javascript\api\4.20\) on Internet Information Services (IIS) for Windows® Server, where www.example.com is the combination of the fully qualified domain name and top level domain of your web site.
If you are using a non-Windows operating system, please see the instructions on deploying the library on Unix/Linux.
The ArcGIS API for JavaScript library can be copied in its entirety to your web server directory. After copying the files to your web server, you will need to edit some files to specify the baseUrl (www.example.com/javascript/api/4.20/) for the configuration. (C:\Inetpub\wwwroot\javascript\api\4.20\). Copy \arcgis_js_v420_api\arcgis_js_api\javascript\4.20\ and all its contents from the ArcGIS API for JavaScript download to your web server. In this example the files are copied to: C:\Inetpub\wwwroot\javascript\api\4.20\.
The default hosting configuration for both the ArcGIS API for JavaScript library and documentation is HTTPS.
.ttf | application/octet-stream | True Type Fonts |
.wasm | application/wasm | WebAssembly |
.woff | application/font-woff | Web Open Font Format |
.woff2 | application/font-woff2 | WOFF File Format 2.0 |
.wsv | application/octet-stream | Supports SceneView's stars visualization |
Note: Scripting the update might be useful in a multi-machine deployment. Otherwise, it is not necessary.
This section will modify the ArcGIS API for JavaScript library [HOSTNAME_AND_PATH_TO_JSAPI]dojo text with www.example.com/javascript/api/4.20/init.js.
The code sample below is written in JavaScript for Node.js and will automate replacing the ArcGIS API for JavaScript library [HOSTNAME_AND_PATH_TO_JSAPI]dojo text with www.example.com/javascript/api/4.20/init.js.
Note: A script like update-library.js could be written in any scripting language that supports reading/writing files and some type of string substitution manipulation such as regular expressions.
// --------------------------------------------------------------------
// update-library.js
//
// Helper script to replace the ArcGIS API for JavaScript library
// `[HOSTNAME_AND_PATH_TO_JSAPI]dojo` text with `www.example.com/javascript/api/4.20/init.js`.
//
// Note: requires node version 7.10.0 and npm version 4.2.0 or higher.
// --------------------------------------------------------------------
let fs = require("fs"),
path = require("path"),
util = require("util"),
// --------------------------------------------------------------------
// hostname to replace js.arcgis.com in the library such as:
// www.example.com
// apiDirectory would be the virtual directory in the web server hosting
// the ArcGIS API for JavaScript library
// --------------------------------------------------------------------
localHost = "www.example.com",
apiDirectory = "javascript/api/4.20/init.js",
// --------------------------------------------------------------------
// path to the downloaded ArcGIS API for JavaScript library
// download archive contents arcgis_js_v%jsapi_version.replace(".", "")%_api\arcgis_js_api\4.20\
// to IIS virtual directory C:\Inetpub\wwwroot\javascript\api\4.20\
// --------------------------------------------------------------------
jsapiDownloadLocation = path.join("C:", "inetpub", "wwwroot", "javascript", "api", "4.20"),
// --------------------------------------------------------------------
// Regular expression to match the template text
// [HOSTNAME_AND_PATH_TO_JSAPI] in
// baseUrl:"https://[HOSTNAME_AND_PATH_TO_JSAPI]dojo"
// --------------------------------------------------------------------
hostnameAndPathRegEx = /\[HOSTNAME_AND_PATH_TO_JSAPI\]dojo/i,
// --------------------------------------------------------------------
// base url for the locally hosted ArcGIS API for JavaScript such as:
// www.example.com/javascript/api/4.20/
// --------------------------------------------------------------------
jsapiURLBaseLocal = util.format("%s/%s", localHost, apiDirectory),
// --------------------------------------------------------------------
// Dojo file containing the CDN link to ArcGIS API for JavaScript
//C:\Inetpub\wwwroot\javascript\api4.20\init.js
// --------------------------------------------------------------------
jsapiInitFile = path.join(jsapiDownloadLocation, "init.js");
// --------------------------------------------------------------------
// 1) Read the ArcGIS API for JavaScript library files
// 2) Replace the script src attribute for the ArcGIS API for JavaScript CDN
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// Read the init file contents from disk
// --------------------------------------------------------------------
console.log("library - reading %s", jsapiInitFile);
let rawInitContent = fs.readFileSync(jsapiInitFile, "utf-8");
// --------------------------------------------------------------------
// Replace the script src attribute for the ArcGIS API for JavaScript CDN
// --------------------------------------------------------------------
console.log("library - replacing script tag for %s", jsapiInitFile);
let updatedInitContent = rawInitContent.replace(hostnameAndPathRegEx, jsapiURLBaseLocal);
// --------------------------------------------------------------------
// Save the init file contents to disk
// --------------------------------------------------------------------
console.log("library - saving %s", jsapiInitFile);
fs.writeFileSync(jsapiInitFile, updatedInitContent, "utf-8");
Now you should be able to access the ArcGIS API for JavaScript library from your web server using the following URL:
<script src="https://www.example.com/javascript/api/4.20/init.js"></script>
Test your installation. You can use the following test code to validate your ArcGIS API for JavaScript library installation.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Test Map</title>
<link rel="stylesheet" href="https://www.example.com/javascript/api/4.20/esri/themes/light/main.css" />
<style> html,
body,
#viewDiv {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<script src="https://www.example.com/javascript/api/4.20/init.js"></script>
<script> require([
"esri/Basemap",
"esri/layers/TileLayer",
"esri/Map",
"esri/views/MapView"
], function (Basemap, TileLayer, Map, MapView){
// --------------------------------------------------------------------
// If you do not have public internet access then use the Basemap class
// and point this URL to your own locally accessible cached service.
//
// Otherwise you can just use one of the named hosted ArcGIS services.
// https://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer
// --------------------------------------------------------------------
const layer = new TileLayer({
url: "https://www.example.com/arcgis/rest/services/Folder/Custom_Base_Map/MapServer"
});
const customBasemap = new Basemap({
baseLayers: [layer],
title: "Custom Basemap",
id: "myBasemap"
});
const myMap = new Map({
basemap: customBasemap
});
const view = new MapView({
center: [-111.87, 40.57], // long, lat
container: "viewDiv",
map: myMap,
zoom: 6
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
For assistance installing Node.js on Windows, see the Installing Node.js topic in the Windows: Hosting the ArcGIS API for JavaScript documentation help topic.
Hello,
If you look in the extracted download of 4.2 you will find a document that outlines how to host it locally:
<API extraction folder>/arcgis_js_v420_api/arcgis_js_v420_api/arcgis_js_api/javascript/downloads/install-windows/index.html
The instructions below assume that you are installing the ArcGIS API for JavaScript library in the following location https://www.example.com/javascript/api/4.20/ (C:\Inetpub\wwwroot\javascript\api\4.20\) on Internet Information Services (IIS) for Windows® Server, where www.example.com is the combination of the fully qualified domain name and top level domain of your web site.
If you are using a non-Windows operating system, please see the instructions on deploying the library on Unix/Linux.
The ArcGIS API for JavaScript library can be copied in its entirety to your web server directory. After copying the files to your web server, you will need to edit some files to specify the baseUrl (www.example.com/javascript/api/4.20/) for the configuration. (C:\Inetpub\wwwroot\javascript\api\4.20\). Copy \arcgis_js_v420_api\arcgis_js_api\javascript\4.20\ and all its contents from the ArcGIS API for JavaScript download to your web server. In this example the files are copied to: C:\Inetpub\wwwroot\javascript\api\4.20\.
The default hosting configuration for both the ArcGIS API for JavaScript library and documentation is HTTPS.
.ttf | application/octet-stream | True Type Fonts |
.wasm | application/wasm | WebAssembly |
.woff | application/font-woff | Web Open Font Format |
.woff2 | application/font-woff2 | WOFF File Format 2.0 |
.wsv | application/octet-stream | Supports SceneView's stars visualization |
Note: Scripting the update might be useful in a multi-machine deployment. Otherwise, it is not necessary.
This section will modify the ArcGIS API for JavaScript library [HOSTNAME_AND_PATH_TO_JSAPI]dojo text with www.example.com/javascript/api/4.20/init.js.
The code sample below is written in JavaScript for Node.js and will automate replacing the ArcGIS API for JavaScript library [HOSTNAME_AND_PATH_TO_JSAPI]dojo text with www.example.com/javascript/api/4.20/init.js.
Note: A script like update-library.js could be written in any scripting language that supports reading/writing files and some type of string substitution manipulation such as regular expressions.
// --------------------------------------------------------------------
// update-library.js
//
// Helper script to replace the ArcGIS API for JavaScript library
// `[HOSTNAME_AND_PATH_TO_JSAPI]dojo` text with `www.example.com/javascript/api/4.20/init.js`.
//
// Note: requires node version 7.10.0 and npm version 4.2.0 or higher.
// --------------------------------------------------------------------
let fs = require("fs"),
path = require("path"),
util = require("util"),
// --------------------------------------------------------------------
// hostname to replace js.arcgis.com in the library such as:
// www.example.com
// apiDirectory would be the virtual directory in the web server hosting
// the ArcGIS API for JavaScript library
// --------------------------------------------------------------------
localHost = "www.example.com",
apiDirectory = "javascript/api/4.20/init.js",
// --------------------------------------------------------------------
// path to the downloaded ArcGIS API for JavaScript library
// download archive contents arcgis_js_v%jsapi_version.replace(".", "")%_api\arcgis_js_api\4.20\
// to IIS virtual directory C:\Inetpub\wwwroot\javascript\api\4.20\
// --------------------------------------------------------------------
jsapiDownloadLocation = path.join("C:", "inetpub", "wwwroot", "javascript", "api", "4.20"),
// --------------------------------------------------------------------
// Regular expression to match the template text
// [HOSTNAME_AND_PATH_TO_JSAPI] in
// baseUrl:"https://[HOSTNAME_AND_PATH_TO_JSAPI]dojo"
// --------------------------------------------------------------------
hostnameAndPathRegEx = /\[HOSTNAME_AND_PATH_TO_JSAPI\]dojo/i,
// --------------------------------------------------------------------
// base url for the locally hosted ArcGIS API for JavaScript such as:
// www.example.com/javascript/api/4.20/
// --------------------------------------------------------------------
jsapiURLBaseLocal = util.format("%s/%s", localHost, apiDirectory),
// --------------------------------------------------------------------
// Dojo file containing the CDN link to ArcGIS API for JavaScript
//C:\Inetpub\wwwroot\javascript\api4.20\init.js
// --------------------------------------------------------------------
jsapiInitFile = path.join(jsapiDownloadLocation, "init.js");
// --------------------------------------------------------------------
// 1) Read the ArcGIS API for JavaScript library files
// 2) Replace the script src attribute for the ArcGIS API for JavaScript CDN
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// Read the init file contents from disk
// --------------------------------------------------------------------
console.log("library - reading %s", jsapiInitFile);
let rawInitContent = fs.readFileSync(jsapiInitFile, "utf-8");
// --------------------------------------------------------------------
// Replace the script src attribute for the ArcGIS API for JavaScript CDN
// --------------------------------------------------------------------
console.log("library - replacing script tag for %s", jsapiInitFile);
let updatedInitContent = rawInitContent.replace(hostnameAndPathRegEx, jsapiURLBaseLocal);
// --------------------------------------------------------------------
// Save the init file contents to disk
// --------------------------------------------------------------------
console.log("library - saving %s", jsapiInitFile);
fs.writeFileSync(jsapiInitFile, updatedInitContent, "utf-8");
Now you should be able to access the ArcGIS API for JavaScript library from your web server using the following URL:
<script src="https://www.example.com/javascript/api/4.20/init.js"></script>
Test your installation. You can use the following test code to validate your ArcGIS API for JavaScript library installation.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Test Map</title>
<link rel="stylesheet" href="https://www.example.com/javascript/api/4.20/esri/themes/light/main.css" />
<style> html,
body,
#viewDiv {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<script src="https://www.example.com/javascript/api/4.20/init.js"></script>
<script> require([
"esri/Basemap",
"esri/layers/TileLayer",
"esri/Map",
"esri/views/MapView"
], function (Basemap, TileLayer, Map, MapView){
// --------------------------------------------------------------------
// If you do not have public internet access then use the Basemap class
// and point this URL to your own locally accessible cached service.
//
// Otherwise you can just use one of the named hosted ArcGIS services.
// https://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer
// --------------------------------------------------------------------
const layer = new TileLayer({
url: "https://www.example.com/arcgis/rest/services/Folder/Custom_Base_Map/MapServer"
});
const customBasemap = new Basemap({
baseLayers: [layer],
title: "Custom Basemap",
id: "myBasemap"
});
const myMap = new Map({
basemap: customBasemap
});
const view = new MapView({
center: [-111.87, 40.57], // long, lat
container: "viewDiv",
map: myMap,
zoom: 6
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
For assistance installing Node.js on Windows, see the Installing Node.js topic in the Windows: Hosting the ArcGIS API for JavaScript documentation help topic.
Hello sir
I downloaded the API 4.21from this link https://developers.arcgis.com/downloads/#javascript
and I can not find the [HOSTNAME_AND_PATH_TO_JSAPI] in the init.js to replace it with my host location.
thank you very much!