Converting ArcGIS JSON to GeoJSONThere in pure Browser
there are 2 ways you can do
1) TERRAFORMER
Note: use in node.js and use in browser are different, details see link
2) Esri/arcgis-to-geojson-utils
use in browser, ArcgisToGeojsonUtils is global var reference the entry point of this module
<script src="https://unpkg.com/@esri/[email protected]/dist/arcgis-to-geojson.js"></script>
// parse ArcGIS JSON, convert it to GeoJSON
const geojson = ArcgisToGeojsonUtils.arcgisToGeoJSON({
"x":-122.6764,
"y":45.5165,
"spatialReference": {
"wkid": 4326
}
});
However, if you want to bundle by yourself, just for learning, follow steps
a) You need to compile all the module source file into a single bundle.js
rollup.js install by
npm install --global rollup
then go to your js lib root folder, find the entry point js file, in this case it is index.js
$ rollup index.js --format umd --name "esri_arcgis_to_geojson" --file bundle.js
You should find a new file bundle.js in your root directory.
Now in your browser html file, include this bundle.js file
<script src='.../.../.../bundle.js'>
You can use it now by
// parse ArcGIS JSON, convert it to GeoJSON
var geojson = esri_arcgis_to_geojson.arcgisToGeoJSON({
"x":-122.6764,
"y":45.5165,
"spatialReference": {
"wkid": 4326
}
});
// take GeoJSON and convert it to ArcGIS JSON
var arcgis = esri_arcgis_to_geojson.geojsonToArcGIS({
"type": "Point",
"coordinates": [45.5165, -122.6764]
});enter code here
Remember esri_arcgis_to_geojson is the name you named the lib
This becomes the global variable name, available in browser.
The trick is, bundle process add instant implement function like (function xx {}) here is the top part from bundle.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ?
factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'],
factory) :
(factory((global.arcgis_to_geojson = {})));
}(this, (function (exports) { 'use strict';
***ORIGINAL SOURCE CODE OF JS MODULE***
})));
arcgis-to-geojson-utils