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
Esri does not provide the bundle.js, so you can NOT use this lib in browser directly
As of today, you can not load module in browser.
You can only use ESIR lib in node.js, not browser.
To use this esri lib in browser, you should use some bundler, please follow:
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
Failure: Unable to open datasource
from ogr2ogr when trying that with my json data.