A few things worked that I worked out this week:
The require
statement that precedes the Javascript in Esri’s examples is actually a part of Node.js, which explains the need for outFields
within module-defined objects
You can move all the stuff out of the index.html file and into its own script file (e.g., geofence.js
) and call the script by adding the following line at the end of your head tag. I’ve found this to be easier to work with, especially in CodePen.io.
<script src="./geofence.js"></script>
I had trouble using Locate.graphic.geometry and trying to run Arcade’s Intersects tool on completely failed. Additionally, I want to be able to save multiple locations, so I am trying to record each time I click the Locate button.
The Locate widget has an event called locate
that triggers with a Position object. I can inspect the page using through my browser’s Console (see here for instructions) and I can see the position object that I get from the triggered event (see image below).
Taking a closer look at what the console is printing, the highest level braces (curly brackets) represent the object, which I arbitrarily called ‘position’ in my code; however, the object has a property that is also called ‘position’ because that’s the position object. So, here I was thinking that ‘position’ was referencing my object called ‘position’ but it is actually referencing the parameter ‘position’ that is inside my object! A slight adjustment to the code changing my function’s variable name from position
to evt
(it’s an event object) and adding the variable name before the word position
, like so:
var data = {
LATITUDE: evt.position.coords.latitude,
LONGITUDE: evt.position.coords.longitude,
NAME: "Test Point"
};
I now get my points created and they are successfully added to a new feature class with the assigned symbology of blue circles with a black outline (see image below).
That should be a good start to get a geofencing storytelling application off the ground.
It seems Esri is using Google APIs for returning geolocations and there may be an issue with usage limits (see here).
UPDATE 4/27
This is where I got with testing locations (html).
Lessons Learned:
Challenges:
This is what it looks like: