agentleFS
GeoDaoyuGeoDaoyu/arcgis-maps-sdk-js-ai-context/skills/arcgis-interaction/AGENTS.md

arcgis-maps-sdk-js-ai-context / arcgis-interaction

AGENTS.md0 starsChanged 7 months agoMITView on GitHub

Quick-reference decisions, checklists, and tables for user interaction patterns. Recommendation: Use immediate-click for hit testing and feature selection. It fires instantly without waiting for a potential double-click. Always clean up handles and event listeners to prevent memory leaks.

The file

We split this AGENTS.md into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always clean up handles and event listeners to prevent memory leaks.

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Agent Guide: arcgis-interaction

Quick-reference decisions, checklists, and tables for user interaction patterns.

Hit Test vs Query vs Popup Decision Matrix

NeedApproachMethod
User clicks a feature and sees infoPopup (built-in)Set popupTemplate on layer, it works automatically
User clicks and you run custom logicHit testview.hitTest(event) in a click handler
Find all features in an areaSpatial queryfeatureLayer.queryFeatures(query)
Highlight features by attributeAttribute query + highlightqueryObjectIds() then layerView.highlight(oids)
Show a cursor change on hoverHit test on pointer-moveview.hitTest(event) in a pointer-move handler
Draw a shape and select features in itSketch + spatial querySketch widget for drawing, then query with the geometry

When to use each:

  • Popup -- Simplest. Just configure popupTemplate on the layer. No code for the interaction itself.
  • Hit test -- Returns the graphic at a screen point. Use when you need the actual feature object for custom behavior (not just a popup).
  • Server query -- Returns features matching SQL/spatial criteria from the service. Use for bulk operations or features not visible on screen.
  • Client query -- layerView.queryFeatures() queries only loaded features. Faster but limited to what is in the view.

Click Event Selection Guide

EventDelayUse Case
click~300ms (waits for double-click check)When double-click behavior matters
immediate-clickNoneHit testing, feature selection (recommended)
double-clickN/AOverride default zoom-in
immediate-double-clickNoneCannot be prevented by immediate-click stopPropagation

Recommendation: Use immediate-click for hit testing and feature selection. It fires instantly without waiting for a potential double-click.

Click-to-Select Implementation Checklist

  • Get a reference to the target FeatureLayer
  • Get the LayerView: const layerView = await view.whenLayerView(featureLayer)
  • Store a highlight handle variable: let highlightHandle = null
  • Add click handler: view.on("immediate-click", async (event) => { ... })
  • Inside handler, run hit test: const response = await view.hitTest(event, { include: [featureLayer] })
  • Remove previous highlight: highlightHandle?.remove()
  • If results found, highlight: highlightHandle = layerView.highlight(graphic)
  • Optionally open popup or update side panel with feature attributes

Cleanup Pattern

Always clean up handles and event listeners to prevent memory leaks.

Handle-based cleanup (highlight, watch)

const handle = layerView.highlight(graphic);
// Later:
handle.remove();

Event listener cleanup

const handle = view.on("click", handler);
// Later:
handle.remove();

reactiveUtils cleanup

import * as reactiveUtils from "@arcgis/core/core/reactiveUtils.js";

const handle = reactiveUtils.watch(() => view.zoom, callback);
// Later:
handle.remove();

Destroy pattern (widgets)

widget.destroy();  // Removes from DOM and cleans up

Checklist for cleanup

  • Store all view.on() return handles
  • Store all reactiveUtils.watch() / when() / once() return handles
  • Store all layerView.highlight() return handles
  • Call .remove() on handles when the interaction is no longer needed
  • Call .destroy() on widgets when removing them
  • In frameworks (React/Angular): clean up in unmount/destroy lifecycle hooks

Event Types Quick Reference

EventFires whenCommon use
clickUser clicks the map (with delay)Non-latency-sensitive selection
immediate-clickUser clicks (no delay)Feature selection, hit testing
double-clickUser double-clicksOverride default zoom behavior
immediate-double-clickDouble-click (no delay)Cannot be stopped by immediate-click
pointer-moveMouse moves over mapHover highlighting, coordinate display
pointer-down / pointer-upMouse button pressed/releasedCustom drag interactions
dragUser drags the mapCustom pan behavior
key-down / key-upKeyboard input while map focusedKeyboard shortcuts
holdLong pressMobile context menu

Preventing Default Behavior

view.on("double-click", (event) => {
  event.stopPropagation();  // Prevents default zoom-in
});

Coordinate Conversion Quick Reference

DirectionMethod
Screen (pixels) to Map (geographic)view.toMap({ x, y })
Map (geographic) to Screen (pixels)view.toScreen(mapPoint)
Click event to Map pointevent.mapPoint (already available)
Pointer event to Map pointview.toMap(event) (must convert)

Highlight Options

PropertyDefaultPurpose
color[0, 255, 255, 1] (cyan)Highlight outline/halo color
haloOpacity1Opacity of the halo around features
fillOpacity0.25Opacity of the fill inside features

Set on view.highlightOptions at the MapView / SceneView level.

Sketch Component vs Widget vs Draw

ApproachUISnappingUndo/RedoUse Case
<arcgis-sketch>Full toolbarYesYesQuick setup with web components
Sketch widgetFull toolbarYesYesCore API with programmatic control
Draw toolNoneNoNoLow-level drawing with custom UI

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.