Electron with ArcGIS API for JavaScript

Electron with ArcGIS API for JavaScript

Rene Rubalcava | April 26, 2017

Many moons ago, I tried my hand at some Electron. I even tried it out with esri-leaflet and it was pretty straightforward.

Recently, a couple of github issues popped up related to this and I realized, I had not talked about how I was using the ArcGIS API for JavaScript with Electron. There is one small tweak you need to do for the AMD loader to work as expected.

const nodereq = window.require;

That's it. Just rename the default Node require in the Browser app of your Electron project and the AMD loader will play nicely. Once you get that far, the wheels are off and you can go full steam using Node modules in your application, and ipc to communicate with the main node process to do some really neat stuff.

In my browser app, referred to as the renderer process, I can do something like this.

ipcRenderer.send("upload-shp", filepath);

Then in the main process, I can listen for that message.

ipcMain.on("upload-shp", (event, arg) => {...})

In this sample app I just build an app that lets me drop shapefiles into the app, that file is passed on to the main process via ipc messaging, and the parsed results are returned to the browser app and displayed. Eazy-peezy.

I'm sure there's a lot of really cool stuff you could do with Electron and the ArcGIS API for JavaScript, I'm just scratching the surface and really just wanted to share with you how to get the ball rolling.

I hope you enjoy the video, comment, like, subscribe!