@saschabrunnerch/arcgis-maps-sdk-js-ai-context 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -203
- package/bin/cli.js +157 -173
- package/contexts/4.34/{claude → skills}/arcgis-3d-advanced/SKILL.md +586 -586
- package/contexts/4.34/{claude → skills}/arcgis-advanced-layers/SKILL.md +431 -431
- package/contexts/4.34/{claude → skills}/arcgis-analysis-services/SKILL.md +607 -607
- package/contexts/4.34/{claude → skills}/arcgis-authentication/SKILL.md +301 -301
- package/contexts/4.34/{claude → skills}/arcgis-cim-symbols/SKILL.md +486 -486
- package/contexts/4.34/{claude → skills}/arcgis-coordinates-projection/SKILL.md +406 -406
- package/contexts/4.34/{claude → skills}/arcgis-core-maps/SKILL.md +739 -739
- package/contexts/4.34/{claude → skills}/arcgis-core-utilities/SKILL.md +732 -732
- package/contexts/4.34/{claude → skills}/arcgis-custom-rendering/SKILL.md +445 -445
- package/contexts/4.34/{claude → skills}/arcgis-editing-advanced/SKILL.md +702 -702
- package/contexts/4.34/{claude → skills}/arcgis-feature-effects/SKILL.md +393 -393
- package/contexts/4.34/{claude → skills}/arcgis-geometry-operations/SKILL.md +489 -489
- package/contexts/4.34/{claude → skills}/arcgis-imagery/SKILL.md +307 -307
- package/contexts/4.34/{claude → skills}/arcgis-interaction/SKILL.md +572 -572
- package/contexts/4.34/{claude → skills}/arcgis-knowledge-graphs/SKILL.md +582 -582
- package/contexts/4.34/{claude → skills}/arcgis-layers/SKILL.md +601 -601
- package/contexts/4.34/{claude → skills}/arcgis-map-tools/SKILL.md +668 -668
- package/contexts/4.34/{claude → skills}/arcgis-media-layers/SKILL.md +290 -290
- package/contexts/4.34/{claude → skills}/arcgis-portal-content/SKILL.md +679 -679
- package/contexts/4.34/{claude → skills}/arcgis-scene-effects/SKILL.md +512 -512
- package/contexts/4.34/{claude → skills}/arcgis-smart-mapping/SKILL.md +686 -686
- package/contexts/4.34/{claude → skills}/arcgis-starter-app-extended/SKILL.md +649 -649
- package/contexts/4.34/{claude → skills}/arcgis-tables-forms/SKILL.md +877 -877
- package/contexts/4.34/{claude → skills}/arcgis-time-animation/SKILL.md +722 -722
- package/contexts/4.34/{claude → skills}/arcgis-utility-networks/SKILL.md +301 -301
- package/contexts/4.34/{claude → skills}/arcgis-visualization/SKILL.md +580 -580
- package/contexts/4.34/{claude → skills}/arcgis-widgets-ui/SKILL.md +574 -574
- package/lib/installer.js +19 -104
- package/package.json +45 -45
- package/contexts/4.34/copilot/arcgis-3d.instructions.md +0 -267
- package/contexts/4.34/copilot/arcgis-analysis.instructions.md +0 -294
- package/contexts/4.34/copilot/arcgis-arcade.instructions.md +0 -234
- package/contexts/4.34/copilot/arcgis-authentication.instructions.md +0 -187
- package/contexts/4.34/copilot/arcgis-cim-symbols.instructions.md +0 -177
- package/contexts/4.34/copilot/arcgis-core-maps.instructions.md +0 -246
- package/contexts/4.34/copilot/arcgis-core-utilities.instructions.md +0 -247
- package/contexts/4.34/copilot/arcgis-editing.instructions.md +0 -262
- package/contexts/4.34/copilot/arcgis-geometry.instructions.md +0 -225
- package/contexts/4.34/copilot/arcgis-layers.instructions.md +0 -278
- package/contexts/4.34/copilot/arcgis-popup-templates.instructions.md +0 -266
- package/contexts/4.34/copilot/arcgis-portal-advanced.instructions.md +0 -275
- package/contexts/4.34/copilot/arcgis-smart-mapping.instructions.md +0 -184
- package/contexts/4.34/copilot/arcgis-starter-app-extended.instructions.md +0 -643
- package/contexts/4.34/copilot/arcgis-starter-app.instructions.md +0 -268
- package/contexts/4.34/copilot/arcgis-time-animation.instructions.md +0 -112
- package/contexts/4.34/copilot/arcgis-visualization.instructions.md +0 -321
- package/contexts/4.34/copilot/arcgis-widgets-ui.instructions.md +0 -277
- /package/contexts/4.34/{claude → skills}/arcgis-arcade/SKILL.md +0 -0
- /package/contexts/4.34/{claude → skills}/arcgis-popup-templates/SKILL.md +0 -0
- /package/contexts/4.34/{claude → skills}/arcgis-starter-app/SKILL.md +0 -0
|
@@ -1,668 +1,668 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: arcgis-map-tools
|
|
3
|
-
description: Interactive map tools including swipe comparison, measurement, identify, and routing. Use for layer comparison, distance/area measurement, and navigation services.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# ArcGIS Map Tools
|
|
7
|
-
|
|
8
|
-
Use this skill for swipe comparison, measurement tools, identify operations, and routing services.
|
|
9
|
-
|
|
10
|
-
## Swipe Widget
|
|
11
|
-
|
|
12
|
-
### Swipe Component
|
|
13
|
-
```html
|
|
14
|
-
<arcgis-map zoom="15" center="-154.88, 19.46">
|
|
15
|
-
<arcgis-zoom slot="top-left"></arcgis-zoom>
|
|
16
|
-
<arcgis-swipe swipe-position="32"></arcgis-swipe>
|
|
17
|
-
</arcgis-map>
|
|
18
|
-
|
|
19
|
-
<script type="module">
|
|
20
|
-
import Map from "@arcgis/core/Map.js";
|
|
21
|
-
import TileLayer from "@arcgis/core/layers/TileLayer.js";
|
|
22
|
-
|
|
23
|
-
const viewElement = document.querySelector("arcgis-map");
|
|
24
|
-
const arcgisSwipe = document.querySelector("arcgis-swipe");
|
|
25
|
-
|
|
26
|
-
const layer1 = new TileLayer({ url: "..." });
|
|
27
|
-
const layer2 = new TileLayer({ url: "..." });
|
|
28
|
-
|
|
29
|
-
viewElement.map = new Map({
|
|
30
|
-
basemap: "satellite",
|
|
31
|
-
layers: [layer1, layer2]
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Configure swipe when ready
|
|
35
|
-
arcgisSwipe.addEventListener("arcgisPropertyChange", (e) => {
|
|
36
|
-
if (e.detail.name === "state" && arcgisSwipe.state === "ready") {
|
|
37
|
-
arcgisSwipe.leadingLayers.add(layer1);
|
|
38
|
-
arcgisSwipe.trailingLayers.add(layer2);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
</script>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Swipe Widget (Core API) - Deprecated
|
|
45
|
-
|
|
46
|
-
> **DEPRECATED since 4.32:** Use the `arcgis-swipe` component shown above instead. For information on widget deprecation, see [Esri's move to web components](https://developers.arcgis.com/javascript/latest/components-transition-plan/).
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
// DEPRECATED - Use arcgis-swipe component instead
|
|
50
|
-
import Swipe from "@arcgis/core/widgets/Swipe.js";
|
|
51
|
-
|
|
52
|
-
const swipe = new Swipe({
|
|
53
|
-
view: view,
|
|
54
|
-
leadingLayers: [layer1],
|
|
55
|
-
trailingLayers: [layer2],
|
|
56
|
-
position: 50, // Percentage from left
|
|
57
|
-
direction: "horizontal" // or "vertical"
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
view.ui.add(swipe);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Measurement
|
|
64
|
-
|
|
65
|
-
### Measurement Components
|
|
66
|
-
```html
|
|
67
|
-
<!-- 2D Measurement -->
|
|
68
|
-
<arcgis-map>
|
|
69
|
-
<arcgis-distance-measurement-2d slot="top-right"></arcgis-distance-measurement-2d>
|
|
70
|
-
<arcgis-area-measurement-2d slot="top-right"></arcgis-area-measurement-2d>
|
|
71
|
-
</arcgis-map>
|
|
72
|
-
|
|
73
|
-
<!-- 3D Measurement -->
|
|
74
|
-
<arcgis-scene>
|
|
75
|
-
<arcgis-direct-line-measurement-3d slot="top-right"></arcgis-direct-line-measurement-3d>
|
|
76
|
-
<arcgis-area-measurement-3d slot="top-right"></arcgis-area-measurement-3d>
|
|
77
|
-
</arcgis-scene>
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Measurement Widget (Core API)
|
|
81
|
-
```javascript
|
|
82
|
-
import Measurement from "@arcgis/core/widgets/Measurement.js";
|
|
83
|
-
|
|
84
|
-
const measurement = new Measurement({
|
|
85
|
-
view: view
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
view.ui.add(measurement, "bottom-right");
|
|
89
|
-
|
|
90
|
-
// Activate distance measurement
|
|
91
|
-
// For 2D: "distance", For 3D: "direct-line"
|
|
92
|
-
measurement.activeTool = view.type === "2d" ? "distance" : "direct-line";
|
|
93
|
-
|
|
94
|
-
// Activate area measurement
|
|
95
|
-
measurement.activeTool = "area";
|
|
96
|
-
|
|
97
|
-
// Clear measurements
|
|
98
|
-
measurement.clear();
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### 2D Measurement Widgets (Core API)
|
|
102
|
-
```javascript
|
|
103
|
-
import DistanceMeasurement2D from "@arcgis/core/widgets/DistanceMeasurement2D.js";
|
|
104
|
-
import AreaMeasurement2D from "@arcgis/core/widgets/AreaMeasurement2D.js";
|
|
105
|
-
|
|
106
|
-
// Distance measurement
|
|
107
|
-
const distanceWidget = new DistanceMeasurement2D({
|
|
108
|
-
view: view,
|
|
109
|
-
unit: "kilometers"
|
|
110
|
-
});
|
|
111
|
-
view.ui.add(distanceWidget, "top-right");
|
|
112
|
-
|
|
113
|
-
// Area measurement
|
|
114
|
-
const areaWidget = new AreaMeasurement2D({
|
|
115
|
-
view: view,
|
|
116
|
-
unit: "square-kilometers"
|
|
117
|
-
});
|
|
118
|
-
view.ui.add(areaWidget, "top-right");
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### 3D Measurement Widgets (Core API)
|
|
122
|
-
```javascript
|
|
123
|
-
import DirectLineMeasurement3D from "@arcgis/core/widgets/DirectLineMeasurement3D.js";
|
|
124
|
-
import AreaMeasurement3D from "@arcgis/core/widgets/AreaMeasurement3D.js";
|
|
125
|
-
|
|
126
|
-
// Direct line measurement (3D)
|
|
127
|
-
const lineWidget = new DirectLineMeasurement3D({
|
|
128
|
-
view: sceneView,
|
|
129
|
-
unit: "meters"
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Area measurement (3D)
|
|
133
|
-
const areaWidget = new AreaMeasurement3D({
|
|
134
|
-
view: sceneView,
|
|
135
|
-
unit: "square-meters"
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## Identify
|
|
140
|
-
|
|
141
|
-
### Identify on MapImageLayer
|
|
142
|
-
```javascript
|
|
143
|
-
import identify from "@arcgis/core/rest/identify.js";
|
|
144
|
-
import IdentifyParameters from "@arcgis/core/rest/support/IdentifyParameters.js";
|
|
145
|
-
|
|
146
|
-
const identifyURL = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/MtBaldy_BaseMap/MapServer";
|
|
147
|
-
|
|
148
|
-
// Set up parameters
|
|
149
|
-
const params = new IdentifyParameters({
|
|
150
|
-
tolerance: 3,
|
|
151
|
-
layerIds: [0, 1, 2, 3, 4],
|
|
152
|
-
layerOption: "top", // "top", "visible", "all"
|
|
153
|
-
width: view.width,
|
|
154
|
-
height: view.height
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Execute on click
|
|
158
|
-
view.on("click", async (event) => {
|
|
159
|
-
params.geometry = event.mapPoint;
|
|
160
|
-
params.mapExtent = view.extent;
|
|
161
|
-
|
|
162
|
-
const response = await identify.identify(identifyURL, params);
|
|
163
|
-
|
|
164
|
-
const features = response.results.map(result => {
|
|
165
|
-
const feature = result.feature;
|
|
166
|
-
feature.attributes.layerName = result.layerName;
|
|
167
|
-
|
|
168
|
-
// Set popup template based on layer
|
|
169
|
-
if (result.layerName === "Roads") {
|
|
170
|
-
feature.popupTemplate = {
|
|
171
|
-
title: "Road",
|
|
172
|
-
content: "<b>Length:</b> {Shape_Length}"
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
return feature;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
if (features.length > 0) {
|
|
179
|
-
view.openPopup({
|
|
180
|
-
features: features,
|
|
181
|
-
location: event.mapPoint
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## Routing
|
|
188
|
-
|
|
189
|
-
### Basic Route
|
|
190
|
-
```javascript
|
|
191
|
-
import route from "@arcgis/core/rest/route.js";
|
|
192
|
-
import RouteParameters from "@arcgis/core/rest/support/RouteParameters.js";
|
|
193
|
-
import FeatureSet from "@arcgis/core/rest/support/FeatureSet.js";
|
|
194
|
-
import Graphic from "@arcgis/core/Graphic.js";
|
|
195
|
-
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer.js";
|
|
196
|
-
|
|
197
|
-
const routeUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
|
|
198
|
-
|
|
199
|
-
const routeLayer = new GraphicsLayer();
|
|
200
|
-
map.add(routeLayer);
|
|
201
|
-
|
|
202
|
-
const routeParams = new RouteParameters({
|
|
203
|
-
apiKey: "YOUR_API_KEY",
|
|
204
|
-
stops: new FeatureSet(),
|
|
205
|
-
outSpatialReference: { wkid: 3857 }
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// Add stop on click
|
|
209
|
-
view.on("click", async (event) => {
|
|
210
|
-
const stop = new Graphic({
|
|
211
|
-
geometry: event.mapPoint,
|
|
212
|
-
symbol: {
|
|
213
|
-
type: "simple-marker",
|
|
214
|
-
style: "cross",
|
|
215
|
-
size: 15
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
routeLayer.add(stop);
|
|
219
|
-
routeParams.stops.features.push(stop);
|
|
220
|
-
|
|
221
|
-
// Solve route when 2+ stops
|
|
222
|
-
if (routeParams.stops.features.length >= 2) {
|
|
223
|
-
const result = await route.solve(routeUrl, routeParams);
|
|
224
|
-
const routeResult = result.routeResults[0].route;
|
|
225
|
-
routeResult.symbol = {
|
|
226
|
-
type: "simple-line",
|
|
227
|
-
color: [0, 0, 255, 0.5],
|
|
228
|
-
width: 5
|
|
229
|
-
};
|
|
230
|
-
routeLayer.add(routeResult);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### Route with Options
|
|
236
|
-
```javascript
|
|
237
|
-
const routeParams = new RouteParameters({
|
|
238
|
-
apiKey: "YOUR_API_KEY",
|
|
239
|
-
stops: new FeatureSet({ features: stopGraphics }),
|
|
240
|
-
returnDirections: true,
|
|
241
|
-
directionsLanguage: "en",
|
|
242
|
-
returnRoutes: true,
|
|
243
|
-
returnStops: true,
|
|
244
|
-
impedanceAttribute: "TravelTime", // or "Miles", "Kilometers"
|
|
245
|
-
restrictionAttributes: ["Avoid Toll Roads"],
|
|
246
|
-
outSpatialReference: { wkid: 4326 }
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const result = await route.solve(routeUrl, routeParams);
|
|
250
|
-
|
|
251
|
-
// Get directions
|
|
252
|
-
const directions = result.routeResults[0].directions;
|
|
253
|
-
directions.features.forEach(feature => {
|
|
254
|
-
console.log(feature.attributes.text);
|
|
255
|
-
});
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Directions Widget
|
|
259
|
-
|
|
260
|
-
### Directions Component
|
|
261
|
-
```html
|
|
262
|
-
<arcgis-map>
|
|
263
|
-
<arcgis-directions slot="top-right"></arcgis-directions>
|
|
264
|
-
</arcgis-map>
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### Directions Widget (Core API)
|
|
268
|
-
```javascript
|
|
269
|
-
import Directions from "@arcgis/core/widgets/Directions.js";
|
|
270
|
-
|
|
271
|
-
const directions = new Directions({
|
|
272
|
-
view: view,
|
|
273
|
-
apiKey: "YOUR_API_KEY"
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
view.ui.add(directions, "top-right");
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## Print
|
|
280
|
-
|
|
281
|
-
### Print Component
|
|
282
|
-
```html
|
|
283
|
-
<arcgis-map item-id="YOUR_WEBMAP_ID">
|
|
284
|
-
<arcgis-expand slot="top-right" expand-tooltip="Print">
|
|
285
|
-
<arcgis-print></arcgis-print>
|
|
286
|
-
</arcgis-expand>
|
|
287
|
-
</arcgis-map>
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Print Service
|
|
291
|
-
```javascript
|
|
292
|
-
import print from "@arcgis/core/rest/print.js";
|
|
293
|
-
import PrintTemplate from "@arcgis/core/rest/support/PrintTemplate.js";
|
|
294
|
-
import PrintParameters from "@arcgis/core/rest/support/PrintParameters.js";
|
|
295
|
-
|
|
296
|
-
const printUrl = "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
|
|
297
|
-
|
|
298
|
-
const template = new PrintTemplate({
|
|
299
|
-
format: "pdf",
|
|
300
|
-
layout: "a4-landscape",
|
|
301
|
-
layoutOptions: {
|
|
302
|
-
titleText: "My Map",
|
|
303
|
-
authorText: "Author Name"
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const params = new PrintParameters({
|
|
308
|
-
view: view,
|
|
309
|
-
template: template
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
const result = await print.execute(printUrl, params);
|
|
313
|
-
console.log("PDF URL:", result.url);
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
### PrintTemplate Configuration
|
|
317
|
-
|
|
318
|
-
```javascript
|
|
319
|
-
import PrintTemplate from "@arcgis/core/rest/support/PrintTemplate.js";
|
|
320
|
-
|
|
321
|
-
const template = new PrintTemplate({
|
|
322
|
-
// Output format
|
|
323
|
-
format: "pdf", // pdf, png32, png8, jpg, gif, eps, svg, svgz
|
|
324
|
-
|
|
325
|
-
// Layout template name (from print service)
|
|
326
|
-
layout: "a4-landscape", // Or custom layout name
|
|
327
|
-
|
|
328
|
-
// Export options for map-only output
|
|
329
|
-
exportOptions: {
|
|
330
|
-
width: 800,
|
|
331
|
-
height: 600,
|
|
332
|
-
dpi: 300
|
|
333
|
-
},
|
|
334
|
-
|
|
335
|
-
// Layout customization
|
|
336
|
-
layoutOptions: {
|
|
337
|
-
titleText: "Map Title",
|
|
338
|
-
authorText: "Created by",
|
|
339
|
-
copyrightText: "Copyright 2024",
|
|
340
|
-
scalebarUnit: "Kilometers", // Kilometers, Miles
|
|
341
|
-
legendLayers: [], // Layers to include in legend
|
|
342
|
-
customTextElements: [
|
|
343
|
-
{ customText: "Custom field value" }
|
|
344
|
-
]
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
// Preserve scale or extent
|
|
348
|
-
outScale: 50000, // Fixed scale
|
|
349
|
-
scalePreserved: true, // Maintain current scale
|
|
350
|
-
|
|
351
|
-
// Include attribution
|
|
352
|
-
attributionVisible: true
|
|
353
|
-
});
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Print Formats
|
|
357
|
-
|
|
358
|
-
| Format | Description |
|
|
359
|
-
|--------|-------------|
|
|
360
|
-
| `pdf` | Adobe PDF |
|
|
361
|
-
| `png32` | PNG with transparency (32-bit) |
|
|
362
|
-
| `png8` | PNG 8-bit |
|
|
363
|
-
| `jpg` | JPEG |
|
|
364
|
-
| `gif` | GIF |
|
|
365
|
-
| `eps` | Encapsulated PostScript |
|
|
366
|
-
| `svg` | Scalable Vector Graphics |
|
|
367
|
-
| `svgz` | Compressed SVG |
|
|
368
|
-
|
|
369
|
-
### Print Layouts
|
|
370
|
-
|
|
371
|
-
```javascript
|
|
372
|
-
// Get available layouts from print service
|
|
373
|
-
const printInfo = await print.getInfo(printUrl);
|
|
374
|
-
|
|
375
|
-
console.log("Available layouts:");
|
|
376
|
-
printInfo.layouts.forEach(layout => {
|
|
377
|
-
console.log(`- ${layout.name}`);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
console.log("Available formats:");
|
|
381
|
-
printInfo.formats.forEach(format => {
|
|
382
|
-
console.log(`- ${format}`);
|
|
383
|
-
});
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
### Map-Only Export (No Layout)
|
|
387
|
-
|
|
388
|
-
```javascript
|
|
389
|
-
const template = new PrintTemplate({
|
|
390
|
-
format: "png32",
|
|
391
|
-
layout: "map-only", // No layout template
|
|
392
|
-
exportOptions: {
|
|
393
|
-
width: 1920,
|
|
394
|
-
height: 1080,
|
|
395
|
-
dpi: 96
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
### High-Resolution Export
|
|
401
|
-
|
|
402
|
-
```javascript
|
|
403
|
-
const template = new PrintTemplate({
|
|
404
|
-
format: "pdf",
|
|
405
|
-
layout: "a3-landscape",
|
|
406
|
-
exportOptions: {
|
|
407
|
-
dpi: 300 // High DPI for print quality
|
|
408
|
-
},
|
|
409
|
-
layoutOptions: {
|
|
410
|
-
titleText: "High Resolution Map",
|
|
411
|
-
scalebarUnit: "Miles"
|
|
412
|
-
},
|
|
413
|
-
scalePreserved: true
|
|
414
|
-
});
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### Print with Custom Extent
|
|
418
|
-
|
|
419
|
-
```javascript
|
|
420
|
-
const template = new PrintTemplate({
|
|
421
|
-
format: "pdf",
|
|
422
|
-
layout: "letter-ansi-a-landscape",
|
|
423
|
-
outScale: 24000 // 1:24000 scale
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
const params = new PrintParameters({
|
|
427
|
-
view: view,
|
|
428
|
-
template: template,
|
|
429
|
-
extraParameters: {
|
|
430
|
-
// Custom extent (optional)
|
|
431
|
-
extent: {
|
|
432
|
-
xmin: -117.2,
|
|
433
|
-
ymin: 34.0,
|
|
434
|
-
xmax: -117.1,
|
|
435
|
-
ymax: 34.1,
|
|
436
|
-
spatialReference: { wkid: 4326 }
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
### Print Widget (Core API)
|
|
443
|
-
```javascript
|
|
444
|
-
import Print from "@arcgis/core/widgets/Print.js";
|
|
445
|
-
|
|
446
|
-
const print = new Print({
|
|
447
|
-
view: view,
|
|
448
|
-
printServiceUrl: "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
view.ui.add(print, "top-right");
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
### Print Widget Configuration (Core API)
|
|
455
|
-
|
|
456
|
-
```javascript
|
|
457
|
-
import Print from "@arcgis/core/widgets/Print.js";
|
|
458
|
-
|
|
459
|
-
const print = new Print({
|
|
460
|
-
view: view,
|
|
461
|
-
printServiceUrl: printUrl,
|
|
462
|
-
|
|
463
|
-
// Allowed formats
|
|
464
|
-
allowedFormats: ["pdf", "png32", "jpg"],
|
|
465
|
-
|
|
466
|
-
// Allowed layouts
|
|
467
|
-
allowedLayouts: ["a4-landscape", "a4-portrait", "letter-ansi-a-landscape"],
|
|
468
|
-
|
|
469
|
-
// Default template settings
|
|
470
|
-
templateOptions: {
|
|
471
|
-
title: "Default Map Title",
|
|
472
|
-
author: "Default Author",
|
|
473
|
-
copyright: "Copyright 2024",
|
|
474
|
-
scaleEnabled: true,
|
|
475
|
-
attributionEnabled: true
|
|
476
|
-
},
|
|
477
|
-
|
|
478
|
-
// Include legend
|
|
479
|
-
includeDefaultTemplates: true
|
|
480
|
-
});
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### Print Widget Events
|
|
484
|
-
|
|
485
|
-
```javascript
|
|
486
|
-
// Listen for print completion
|
|
487
|
-
print.viewModel.on("complete", (event) => {
|
|
488
|
-
console.log("Print complete:", event.url);
|
|
489
|
-
window.open(event.url, "_blank");
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
// Listen for errors
|
|
493
|
-
print.viewModel.on("error", (event) => {
|
|
494
|
-
console.error("Print error:", event.error);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// Track progress
|
|
498
|
-
print.viewModel.watch("state", (state) => {
|
|
499
|
-
console.log("Print state:", state); // ready, printing, complete, error
|
|
500
|
-
});
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
### Custom Print Workflow
|
|
504
|
-
|
|
505
|
-
```javascript
|
|
506
|
-
async function printMap(view, options = {}) {
|
|
507
|
-
const {
|
|
508
|
-
title = "Map Export",
|
|
509
|
-
format = "pdf",
|
|
510
|
-
layout = "a4-landscape",
|
|
511
|
-
dpi = 150
|
|
512
|
-
} = options;
|
|
513
|
-
|
|
514
|
-
const template = new PrintTemplate({
|
|
515
|
-
format,
|
|
516
|
-
layout,
|
|
517
|
-
exportOptions: { dpi },
|
|
518
|
-
layoutOptions: {
|
|
519
|
-
titleText: title,
|
|
520
|
-
authorText: "Generated by Web App",
|
|
521
|
-
copyrightText: `Exported: ${new Date().toLocaleDateString()}`
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const params = new PrintParameters({
|
|
526
|
-
view,
|
|
527
|
-
template
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
try {
|
|
531
|
-
const result = await print.execute(printUrl, params);
|
|
532
|
-
return result.url;
|
|
533
|
-
} catch (error) {
|
|
534
|
-
console.error("Print failed:", error);
|
|
535
|
-
throw error;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// Usage
|
|
540
|
-
const pdfUrl = await printMap(view, {
|
|
541
|
-
title: "Project Area Map",
|
|
542
|
-
format: "pdf",
|
|
543
|
-
dpi: 300
|
|
544
|
-
});
|
|
545
|
-
window.open(pdfUrl, "_blank");
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
### Print with Legend Customization
|
|
549
|
-
|
|
550
|
-
```javascript
|
|
551
|
-
const template = new PrintTemplate({
|
|
552
|
-
format: "pdf",
|
|
553
|
-
layout: "a4-landscape",
|
|
554
|
-
layoutOptions: {
|
|
555
|
-
titleText: "Map with Custom Legend",
|
|
556
|
-
// Specify which layers to include in legend
|
|
557
|
-
legendLayers: [
|
|
558
|
-
{ layerId: featureLayer.id },
|
|
559
|
-
{ layerId: anotherLayer.id, sublayerIds: [0, 2] } // Specific sublayers
|
|
560
|
-
]
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
### Screenshot as Alternative
|
|
566
|
-
|
|
567
|
-
For quick exports without a print service:
|
|
568
|
-
|
|
569
|
-
```javascript
|
|
570
|
-
// Take screenshot of current view
|
|
571
|
-
const screenshot = await view.takeScreenshot({
|
|
572
|
-
format: "png",
|
|
573
|
-
width: 1920,
|
|
574
|
-
height: 1080,
|
|
575
|
-
quality: 90
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
// Use the data URL
|
|
579
|
-
const img = document.createElement("img");
|
|
580
|
-
img.src = screenshot.dataUrl;
|
|
581
|
-
document.body.appendChild(img);
|
|
582
|
-
|
|
583
|
-
// Or download
|
|
584
|
-
const link = document.createElement("a");
|
|
585
|
-
link.download = "map-screenshot.png";
|
|
586
|
-
link.href = screenshot.dataUrl;
|
|
587
|
-
link.click();
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
## Find
|
|
591
|
-
|
|
592
|
-
### Find Service
|
|
593
|
-
```javascript
|
|
594
|
-
import find from "@arcgis/core/rest/find.js";
|
|
595
|
-
import FindParameters from "@arcgis/core/rest/support/FindParameters.js";
|
|
596
|
-
|
|
597
|
-
const findUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer";
|
|
598
|
-
|
|
599
|
-
const params = new FindParameters({
|
|
600
|
-
searchText: "California",
|
|
601
|
-
layerIds: [0, 1, 2],
|
|
602
|
-
searchFields: ["STATE_NAME", "NAME"],
|
|
603
|
-
returnGeometry: true
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
const result = await find.find(findUrl, params);
|
|
607
|
-
|
|
608
|
-
result.results.forEach(r => {
|
|
609
|
-
console.log(r.feature.attributes);
|
|
610
|
-
});
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
## Complete Example
|
|
614
|
-
|
|
615
|
-
```html
|
|
616
|
-
<!DOCTYPE html>
|
|
617
|
-
<html>
|
|
618
|
-
<head>
|
|
619
|
-
<script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"></script>
|
|
620
|
-
<script src="https://js.arcgis.com/4.34/"></script>
|
|
621
|
-
<script type="module" src="https://js.arcgis.com/4.34/map-components/"></script>
|
|
622
|
-
<style>
|
|
623
|
-
html, body { height: 100%; margin: 0; }
|
|
624
|
-
#toolbar { position: absolute; top: 10px; right: 10px; }
|
|
625
|
-
</style>
|
|
626
|
-
</head>
|
|
627
|
-
<body>
|
|
628
|
-
<arcgis-map basemap="streets-navigation-vector" center="-117.195, 34.057" zoom="13">
|
|
629
|
-
<arcgis-zoom slot="top-left"></arcgis-zoom>
|
|
630
|
-
</arcgis-map>
|
|
631
|
-
<div id="toolbar">
|
|
632
|
-
<calcite-button id="measureBtn">Measure</calcite-button>
|
|
633
|
-
<calcite-button id="clearBtn">Clear</calcite-button>
|
|
634
|
-
</div>
|
|
635
|
-
|
|
636
|
-
<script type="module">
|
|
637
|
-
import Measurement from "@arcgis/core/widgets/Measurement.js";
|
|
638
|
-
|
|
639
|
-
const viewElement = document.querySelector("arcgis-map");
|
|
640
|
-
await viewElement.viewOnReady();
|
|
641
|
-
|
|
642
|
-
const measurement = new Measurement({ view: viewElement });
|
|
643
|
-
viewElement.ui.add(measurement, "bottom-right");
|
|
644
|
-
|
|
645
|
-
document.getElementById("measureBtn").onclick = () => {
|
|
646
|
-
measurement.activeTool = "distance";
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
document.getElementById("clearBtn").onclick = () => {
|
|
650
|
-
measurement.clear();
|
|
651
|
-
};
|
|
652
|
-
</script>
|
|
653
|
-
</body>
|
|
654
|
-
</html>
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
## Common Pitfalls
|
|
658
|
-
|
|
659
|
-
1. **API Key for routing**: Route service requires valid API key or authenticated user
|
|
660
|
-
|
|
661
|
-
2. **Identify tolerance**: Set appropriate tolerance based on zoom level
|
|
662
|
-
|
|
663
|
-
3. **Swipe layer order**: Leading/trailing layers must be in the map's layers collection
|
|
664
|
-
|
|
665
|
-
4. **Measurement units**: Set appropriate units for the measurement context
|
|
666
|
-
|
|
667
|
-
5. **3D vs 2D measurement**: Use different widgets/tools for 2D and 3D views
|
|
668
|
-
|
|
1
|
+
---
|
|
2
|
+
name: arcgis-map-tools
|
|
3
|
+
description: Interactive map tools including swipe comparison, measurement, identify, and routing. Use for layer comparison, distance/area measurement, and navigation services.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ArcGIS Map Tools
|
|
7
|
+
|
|
8
|
+
Use this skill for swipe comparison, measurement tools, identify operations, and routing services.
|
|
9
|
+
|
|
10
|
+
## Swipe Widget
|
|
11
|
+
|
|
12
|
+
### Swipe Component
|
|
13
|
+
```html
|
|
14
|
+
<arcgis-map zoom="15" center="-154.88, 19.46">
|
|
15
|
+
<arcgis-zoom slot="top-left"></arcgis-zoom>
|
|
16
|
+
<arcgis-swipe swipe-position="32"></arcgis-swipe>
|
|
17
|
+
</arcgis-map>
|
|
18
|
+
|
|
19
|
+
<script type="module">
|
|
20
|
+
import Map from "@arcgis/core/Map.js";
|
|
21
|
+
import TileLayer from "@arcgis/core/layers/TileLayer.js";
|
|
22
|
+
|
|
23
|
+
const viewElement = document.querySelector("arcgis-map");
|
|
24
|
+
const arcgisSwipe = document.querySelector("arcgis-swipe");
|
|
25
|
+
|
|
26
|
+
const layer1 = new TileLayer({ url: "..." });
|
|
27
|
+
const layer2 = new TileLayer({ url: "..." });
|
|
28
|
+
|
|
29
|
+
viewElement.map = new Map({
|
|
30
|
+
basemap: "satellite",
|
|
31
|
+
layers: [layer1, layer2]
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Configure swipe when ready
|
|
35
|
+
arcgisSwipe.addEventListener("arcgisPropertyChange", (e) => {
|
|
36
|
+
if (e.detail.name === "state" && arcgisSwipe.state === "ready") {
|
|
37
|
+
arcgisSwipe.leadingLayers.add(layer1);
|
|
38
|
+
arcgisSwipe.trailingLayers.add(layer2);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Swipe Widget (Core API) - Deprecated
|
|
45
|
+
|
|
46
|
+
> **DEPRECATED since 4.32:** Use the `arcgis-swipe` component shown above instead. For information on widget deprecation, see [Esri's move to web components](https://developers.arcgis.com/javascript/latest/components-transition-plan/).
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// DEPRECATED - Use arcgis-swipe component instead
|
|
50
|
+
import Swipe from "@arcgis/core/widgets/Swipe.js";
|
|
51
|
+
|
|
52
|
+
const swipe = new Swipe({
|
|
53
|
+
view: view,
|
|
54
|
+
leadingLayers: [layer1],
|
|
55
|
+
trailingLayers: [layer2],
|
|
56
|
+
position: 50, // Percentage from left
|
|
57
|
+
direction: "horizontal" // or "vertical"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
view.ui.add(swipe);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Measurement
|
|
64
|
+
|
|
65
|
+
### Measurement Components
|
|
66
|
+
```html
|
|
67
|
+
<!-- 2D Measurement -->
|
|
68
|
+
<arcgis-map>
|
|
69
|
+
<arcgis-distance-measurement-2d slot="top-right"></arcgis-distance-measurement-2d>
|
|
70
|
+
<arcgis-area-measurement-2d slot="top-right"></arcgis-area-measurement-2d>
|
|
71
|
+
</arcgis-map>
|
|
72
|
+
|
|
73
|
+
<!-- 3D Measurement -->
|
|
74
|
+
<arcgis-scene>
|
|
75
|
+
<arcgis-direct-line-measurement-3d slot="top-right"></arcgis-direct-line-measurement-3d>
|
|
76
|
+
<arcgis-area-measurement-3d slot="top-right"></arcgis-area-measurement-3d>
|
|
77
|
+
</arcgis-scene>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Measurement Widget (Core API)
|
|
81
|
+
```javascript
|
|
82
|
+
import Measurement from "@arcgis/core/widgets/Measurement.js";
|
|
83
|
+
|
|
84
|
+
const measurement = new Measurement({
|
|
85
|
+
view: view
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
view.ui.add(measurement, "bottom-right");
|
|
89
|
+
|
|
90
|
+
// Activate distance measurement
|
|
91
|
+
// For 2D: "distance", For 3D: "direct-line"
|
|
92
|
+
measurement.activeTool = view.type === "2d" ? "distance" : "direct-line";
|
|
93
|
+
|
|
94
|
+
// Activate area measurement
|
|
95
|
+
measurement.activeTool = "area";
|
|
96
|
+
|
|
97
|
+
// Clear measurements
|
|
98
|
+
measurement.clear();
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 2D Measurement Widgets (Core API)
|
|
102
|
+
```javascript
|
|
103
|
+
import DistanceMeasurement2D from "@arcgis/core/widgets/DistanceMeasurement2D.js";
|
|
104
|
+
import AreaMeasurement2D from "@arcgis/core/widgets/AreaMeasurement2D.js";
|
|
105
|
+
|
|
106
|
+
// Distance measurement
|
|
107
|
+
const distanceWidget = new DistanceMeasurement2D({
|
|
108
|
+
view: view,
|
|
109
|
+
unit: "kilometers"
|
|
110
|
+
});
|
|
111
|
+
view.ui.add(distanceWidget, "top-right");
|
|
112
|
+
|
|
113
|
+
// Area measurement
|
|
114
|
+
const areaWidget = new AreaMeasurement2D({
|
|
115
|
+
view: view,
|
|
116
|
+
unit: "square-kilometers"
|
|
117
|
+
});
|
|
118
|
+
view.ui.add(areaWidget, "top-right");
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 3D Measurement Widgets (Core API)
|
|
122
|
+
```javascript
|
|
123
|
+
import DirectLineMeasurement3D from "@arcgis/core/widgets/DirectLineMeasurement3D.js";
|
|
124
|
+
import AreaMeasurement3D from "@arcgis/core/widgets/AreaMeasurement3D.js";
|
|
125
|
+
|
|
126
|
+
// Direct line measurement (3D)
|
|
127
|
+
const lineWidget = new DirectLineMeasurement3D({
|
|
128
|
+
view: sceneView,
|
|
129
|
+
unit: "meters"
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Area measurement (3D)
|
|
133
|
+
const areaWidget = new AreaMeasurement3D({
|
|
134
|
+
view: sceneView,
|
|
135
|
+
unit: "square-meters"
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Identify
|
|
140
|
+
|
|
141
|
+
### Identify on MapImageLayer
|
|
142
|
+
```javascript
|
|
143
|
+
import identify from "@arcgis/core/rest/identify.js";
|
|
144
|
+
import IdentifyParameters from "@arcgis/core/rest/support/IdentifyParameters.js";
|
|
145
|
+
|
|
146
|
+
const identifyURL = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/MtBaldy_BaseMap/MapServer";
|
|
147
|
+
|
|
148
|
+
// Set up parameters
|
|
149
|
+
const params = new IdentifyParameters({
|
|
150
|
+
tolerance: 3,
|
|
151
|
+
layerIds: [0, 1, 2, 3, 4],
|
|
152
|
+
layerOption: "top", // "top", "visible", "all"
|
|
153
|
+
width: view.width,
|
|
154
|
+
height: view.height
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Execute on click
|
|
158
|
+
view.on("click", async (event) => {
|
|
159
|
+
params.geometry = event.mapPoint;
|
|
160
|
+
params.mapExtent = view.extent;
|
|
161
|
+
|
|
162
|
+
const response = await identify.identify(identifyURL, params);
|
|
163
|
+
|
|
164
|
+
const features = response.results.map(result => {
|
|
165
|
+
const feature = result.feature;
|
|
166
|
+
feature.attributes.layerName = result.layerName;
|
|
167
|
+
|
|
168
|
+
// Set popup template based on layer
|
|
169
|
+
if (result.layerName === "Roads") {
|
|
170
|
+
feature.popupTemplate = {
|
|
171
|
+
title: "Road",
|
|
172
|
+
content: "<b>Length:</b> {Shape_Length}"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return feature;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (features.length > 0) {
|
|
179
|
+
view.openPopup({
|
|
180
|
+
features: features,
|
|
181
|
+
location: event.mapPoint
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Routing
|
|
188
|
+
|
|
189
|
+
### Basic Route
|
|
190
|
+
```javascript
|
|
191
|
+
import route from "@arcgis/core/rest/route.js";
|
|
192
|
+
import RouteParameters from "@arcgis/core/rest/support/RouteParameters.js";
|
|
193
|
+
import FeatureSet from "@arcgis/core/rest/support/FeatureSet.js";
|
|
194
|
+
import Graphic from "@arcgis/core/Graphic.js";
|
|
195
|
+
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer.js";
|
|
196
|
+
|
|
197
|
+
const routeUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
|
|
198
|
+
|
|
199
|
+
const routeLayer = new GraphicsLayer();
|
|
200
|
+
map.add(routeLayer);
|
|
201
|
+
|
|
202
|
+
const routeParams = new RouteParameters({
|
|
203
|
+
apiKey: "YOUR_API_KEY",
|
|
204
|
+
stops: new FeatureSet(),
|
|
205
|
+
outSpatialReference: { wkid: 3857 }
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Add stop on click
|
|
209
|
+
view.on("click", async (event) => {
|
|
210
|
+
const stop = new Graphic({
|
|
211
|
+
geometry: event.mapPoint,
|
|
212
|
+
symbol: {
|
|
213
|
+
type: "simple-marker",
|
|
214
|
+
style: "cross",
|
|
215
|
+
size: 15
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
routeLayer.add(stop);
|
|
219
|
+
routeParams.stops.features.push(stop);
|
|
220
|
+
|
|
221
|
+
// Solve route when 2+ stops
|
|
222
|
+
if (routeParams.stops.features.length >= 2) {
|
|
223
|
+
const result = await route.solve(routeUrl, routeParams);
|
|
224
|
+
const routeResult = result.routeResults[0].route;
|
|
225
|
+
routeResult.symbol = {
|
|
226
|
+
type: "simple-line",
|
|
227
|
+
color: [0, 0, 255, 0.5],
|
|
228
|
+
width: 5
|
|
229
|
+
};
|
|
230
|
+
routeLayer.add(routeResult);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Route with Options
|
|
236
|
+
```javascript
|
|
237
|
+
const routeParams = new RouteParameters({
|
|
238
|
+
apiKey: "YOUR_API_KEY",
|
|
239
|
+
stops: new FeatureSet({ features: stopGraphics }),
|
|
240
|
+
returnDirections: true,
|
|
241
|
+
directionsLanguage: "en",
|
|
242
|
+
returnRoutes: true,
|
|
243
|
+
returnStops: true,
|
|
244
|
+
impedanceAttribute: "TravelTime", // or "Miles", "Kilometers"
|
|
245
|
+
restrictionAttributes: ["Avoid Toll Roads"],
|
|
246
|
+
outSpatialReference: { wkid: 4326 }
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const result = await route.solve(routeUrl, routeParams);
|
|
250
|
+
|
|
251
|
+
// Get directions
|
|
252
|
+
const directions = result.routeResults[0].directions;
|
|
253
|
+
directions.features.forEach(feature => {
|
|
254
|
+
console.log(feature.attributes.text);
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Directions Widget
|
|
259
|
+
|
|
260
|
+
### Directions Component
|
|
261
|
+
```html
|
|
262
|
+
<arcgis-map>
|
|
263
|
+
<arcgis-directions slot="top-right"></arcgis-directions>
|
|
264
|
+
</arcgis-map>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Directions Widget (Core API)
|
|
268
|
+
```javascript
|
|
269
|
+
import Directions from "@arcgis/core/widgets/Directions.js";
|
|
270
|
+
|
|
271
|
+
const directions = new Directions({
|
|
272
|
+
view: view,
|
|
273
|
+
apiKey: "YOUR_API_KEY"
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
view.ui.add(directions, "top-right");
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Print
|
|
280
|
+
|
|
281
|
+
### Print Component
|
|
282
|
+
```html
|
|
283
|
+
<arcgis-map item-id="YOUR_WEBMAP_ID">
|
|
284
|
+
<arcgis-expand slot="top-right" expand-tooltip="Print">
|
|
285
|
+
<arcgis-print></arcgis-print>
|
|
286
|
+
</arcgis-expand>
|
|
287
|
+
</arcgis-map>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Print Service
|
|
291
|
+
```javascript
|
|
292
|
+
import print from "@arcgis/core/rest/print.js";
|
|
293
|
+
import PrintTemplate from "@arcgis/core/rest/support/PrintTemplate.js";
|
|
294
|
+
import PrintParameters from "@arcgis/core/rest/support/PrintParameters.js";
|
|
295
|
+
|
|
296
|
+
const printUrl = "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
|
|
297
|
+
|
|
298
|
+
const template = new PrintTemplate({
|
|
299
|
+
format: "pdf",
|
|
300
|
+
layout: "a4-landscape",
|
|
301
|
+
layoutOptions: {
|
|
302
|
+
titleText: "My Map",
|
|
303
|
+
authorText: "Author Name"
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const params = new PrintParameters({
|
|
308
|
+
view: view,
|
|
309
|
+
template: template
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const result = await print.execute(printUrl, params);
|
|
313
|
+
console.log("PDF URL:", result.url);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### PrintTemplate Configuration
|
|
317
|
+
|
|
318
|
+
```javascript
|
|
319
|
+
import PrintTemplate from "@arcgis/core/rest/support/PrintTemplate.js";
|
|
320
|
+
|
|
321
|
+
const template = new PrintTemplate({
|
|
322
|
+
// Output format
|
|
323
|
+
format: "pdf", // pdf, png32, png8, jpg, gif, eps, svg, svgz
|
|
324
|
+
|
|
325
|
+
// Layout template name (from print service)
|
|
326
|
+
layout: "a4-landscape", // Or custom layout name
|
|
327
|
+
|
|
328
|
+
// Export options for map-only output
|
|
329
|
+
exportOptions: {
|
|
330
|
+
width: 800,
|
|
331
|
+
height: 600,
|
|
332
|
+
dpi: 300
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
// Layout customization
|
|
336
|
+
layoutOptions: {
|
|
337
|
+
titleText: "Map Title",
|
|
338
|
+
authorText: "Created by",
|
|
339
|
+
copyrightText: "Copyright 2024",
|
|
340
|
+
scalebarUnit: "Kilometers", // Kilometers, Miles
|
|
341
|
+
legendLayers: [], // Layers to include in legend
|
|
342
|
+
customTextElements: [
|
|
343
|
+
{ customText: "Custom field value" }
|
|
344
|
+
]
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
// Preserve scale or extent
|
|
348
|
+
outScale: 50000, // Fixed scale
|
|
349
|
+
scalePreserved: true, // Maintain current scale
|
|
350
|
+
|
|
351
|
+
// Include attribution
|
|
352
|
+
attributionVisible: true
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Print Formats
|
|
357
|
+
|
|
358
|
+
| Format | Description |
|
|
359
|
+
|--------|-------------|
|
|
360
|
+
| `pdf` | Adobe PDF |
|
|
361
|
+
| `png32` | PNG with transparency (32-bit) |
|
|
362
|
+
| `png8` | PNG 8-bit |
|
|
363
|
+
| `jpg` | JPEG |
|
|
364
|
+
| `gif` | GIF |
|
|
365
|
+
| `eps` | Encapsulated PostScript |
|
|
366
|
+
| `svg` | Scalable Vector Graphics |
|
|
367
|
+
| `svgz` | Compressed SVG |
|
|
368
|
+
|
|
369
|
+
### Print Layouts
|
|
370
|
+
|
|
371
|
+
```javascript
|
|
372
|
+
// Get available layouts from print service
|
|
373
|
+
const printInfo = await print.getInfo(printUrl);
|
|
374
|
+
|
|
375
|
+
console.log("Available layouts:");
|
|
376
|
+
printInfo.layouts.forEach(layout => {
|
|
377
|
+
console.log(`- ${layout.name}`);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
console.log("Available formats:");
|
|
381
|
+
printInfo.formats.forEach(format => {
|
|
382
|
+
console.log(`- ${format}`);
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Map-Only Export (No Layout)
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
const template = new PrintTemplate({
|
|
390
|
+
format: "png32",
|
|
391
|
+
layout: "map-only", // No layout template
|
|
392
|
+
exportOptions: {
|
|
393
|
+
width: 1920,
|
|
394
|
+
height: 1080,
|
|
395
|
+
dpi: 96
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### High-Resolution Export
|
|
401
|
+
|
|
402
|
+
```javascript
|
|
403
|
+
const template = new PrintTemplate({
|
|
404
|
+
format: "pdf",
|
|
405
|
+
layout: "a3-landscape",
|
|
406
|
+
exportOptions: {
|
|
407
|
+
dpi: 300 // High DPI for print quality
|
|
408
|
+
},
|
|
409
|
+
layoutOptions: {
|
|
410
|
+
titleText: "High Resolution Map",
|
|
411
|
+
scalebarUnit: "Miles"
|
|
412
|
+
},
|
|
413
|
+
scalePreserved: true
|
|
414
|
+
});
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Print with Custom Extent
|
|
418
|
+
|
|
419
|
+
```javascript
|
|
420
|
+
const template = new PrintTemplate({
|
|
421
|
+
format: "pdf",
|
|
422
|
+
layout: "letter-ansi-a-landscape",
|
|
423
|
+
outScale: 24000 // 1:24000 scale
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
const params = new PrintParameters({
|
|
427
|
+
view: view,
|
|
428
|
+
template: template,
|
|
429
|
+
extraParameters: {
|
|
430
|
+
// Custom extent (optional)
|
|
431
|
+
extent: {
|
|
432
|
+
xmin: -117.2,
|
|
433
|
+
ymin: 34.0,
|
|
434
|
+
xmax: -117.1,
|
|
435
|
+
ymax: 34.1,
|
|
436
|
+
spatialReference: { wkid: 4326 }
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Print Widget (Core API)
|
|
443
|
+
```javascript
|
|
444
|
+
import Print from "@arcgis/core/widgets/Print.js";
|
|
445
|
+
|
|
446
|
+
const print = new Print({
|
|
447
|
+
view: view,
|
|
448
|
+
printServiceUrl: "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
view.ui.add(print, "top-right");
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Print Widget Configuration (Core API)
|
|
455
|
+
|
|
456
|
+
```javascript
|
|
457
|
+
import Print from "@arcgis/core/widgets/Print.js";
|
|
458
|
+
|
|
459
|
+
const print = new Print({
|
|
460
|
+
view: view,
|
|
461
|
+
printServiceUrl: printUrl,
|
|
462
|
+
|
|
463
|
+
// Allowed formats
|
|
464
|
+
allowedFormats: ["pdf", "png32", "jpg"],
|
|
465
|
+
|
|
466
|
+
// Allowed layouts
|
|
467
|
+
allowedLayouts: ["a4-landscape", "a4-portrait", "letter-ansi-a-landscape"],
|
|
468
|
+
|
|
469
|
+
// Default template settings
|
|
470
|
+
templateOptions: {
|
|
471
|
+
title: "Default Map Title",
|
|
472
|
+
author: "Default Author",
|
|
473
|
+
copyright: "Copyright 2024",
|
|
474
|
+
scaleEnabled: true,
|
|
475
|
+
attributionEnabled: true
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
// Include legend
|
|
479
|
+
includeDefaultTemplates: true
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Print Widget Events
|
|
484
|
+
|
|
485
|
+
```javascript
|
|
486
|
+
// Listen for print completion
|
|
487
|
+
print.viewModel.on("complete", (event) => {
|
|
488
|
+
console.log("Print complete:", event.url);
|
|
489
|
+
window.open(event.url, "_blank");
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// Listen for errors
|
|
493
|
+
print.viewModel.on("error", (event) => {
|
|
494
|
+
console.error("Print error:", event.error);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// Track progress
|
|
498
|
+
print.viewModel.watch("state", (state) => {
|
|
499
|
+
console.log("Print state:", state); // ready, printing, complete, error
|
|
500
|
+
});
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Custom Print Workflow
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
async function printMap(view, options = {}) {
|
|
507
|
+
const {
|
|
508
|
+
title = "Map Export",
|
|
509
|
+
format = "pdf",
|
|
510
|
+
layout = "a4-landscape",
|
|
511
|
+
dpi = 150
|
|
512
|
+
} = options;
|
|
513
|
+
|
|
514
|
+
const template = new PrintTemplate({
|
|
515
|
+
format,
|
|
516
|
+
layout,
|
|
517
|
+
exportOptions: { dpi },
|
|
518
|
+
layoutOptions: {
|
|
519
|
+
titleText: title,
|
|
520
|
+
authorText: "Generated by Web App",
|
|
521
|
+
copyrightText: `Exported: ${new Date().toLocaleDateString()}`
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
const params = new PrintParameters({
|
|
526
|
+
view,
|
|
527
|
+
template
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
try {
|
|
531
|
+
const result = await print.execute(printUrl, params);
|
|
532
|
+
return result.url;
|
|
533
|
+
} catch (error) {
|
|
534
|
+
console.error("Print failed:", error);
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Usage
|
|
540
|
+
const pdfUrl = await printMap(view, {
|
|
541
|
+
title: "Project Area Map",
|
|
542
|
+
format: "pdf",
|
|
543
|
+
dpi: 300
|
|
544
|
+
});
|
|
545
|
+
window.open(pdfUrl, "_blank");
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Print with Legend Customization
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
const template = new PrintTemplate({
|
|
552
|
+
format: "pdf",
|
|
553
|
+
layout: "a4-landscape",
|
|
554
|
+
layoutOptions: {
|
|
555
|
+
titleText: "Map with Custom Legend",
|
|
556
|
+
// Specify which layers to include in legend
|
|
557
|
+
legendLayers: [
|
|
558
|
+
{ layerId: featureLayer.id },
|
|
559
|
+
{ layerId: anotherLayer.id, sublayerIds: [0, 2] } // Specific sublayers
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### Screenshot as Alternative
|
|
566
|
+
|
|
567
|
+
For quick exports without a print service:
|
|
568
|
+
|
|
569
|
+
```javascript
|
|
570
|
+
// Take screenshot of current view
|
|
571
|
+
const screenshot = await view.takeScreenshot({
|
|
572
|
+
format: "png",
|
|
573
|
+
width: 1920,
|
|
574
|
+
height: 1080,
|
|
575
|
+
quality: 90
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// Use the data URL
|
|
579
|
+
const img = document.createElement("img");
|
|
580
|
+
img.src = screenshot.dataUrl;
|
|
581
|
+
document.body.appendChild(img);
|
|
582
|
+
|
|
583
|
+
// Or download
|
|
584
|
+
const link = document.createElement("a");
|
|
585
|
+
link.download = "map-screenshot.png";
|
|
586
|
+
link.href = screenshot.dataUrl;
|
|
587
|
+
link.click();
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
## Find
|
|
591
|
+
|
|
592
|
+
### Find Service
|
|
593
|
+
```javascript
|
|
594
|
+
import find from "@arcgis/core/rest/find.js";
|
|
595
|
+
import FindParameters from "@arcgis/core/rest/support/FindParameters.js";
|
|
596
|
+
|
|
597
|
+
const findUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer";
|
|
598
|
+
|
|
599
|
+
const params = new FindParameters({
|
|
600
|
+
searchText: "California",
|
|
601
|
+
layerIds: [0, 1, 2],
|
|
602
|
+
searchFields: ["STATE_NAME", "NAME"],
|
|
603
|
+
returnGeometry: true
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
const result = await find.find(findUrl, params);
|
|
607
|
+
|
|
608
|
+
result.results.forEach(r => {
|
|
609
|
+
console.log(r.feature.attributes);
|
|
610
|
+
});
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
## Complete Example
|
|
614
|
+
|
|
615
|
+
```html
|
|
616
|
+
<!DOCTYPE html>
|
|
617
|
+
<html>
|
|
618
|
+
<head>
|
|
619
|
+
<script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"></script>
|
|
620
|
+
<script src="https://js.arcgis.com/4.34/"></script>
|
|
621
|
+
<script type="module" src="https://js.arcgis.com/4.34/map-components/"></script>
|
|
622
|
+
<style>
|
|
623
|
+
html, body { height: 100%; margin: 0; }
|
|
624
|
+
#toolbar { position: absolute; top: 10px; right: 10px; }
|
|
625
|
+
</style>
|
|
626
|
+
</head>
|
|
627
|
+
<body>
|
|
628
|
+
<arcgis-map basemap="streets-navigation-vector" center="-117.195, 34.057" zoom="13">
|
|
629
|
+
<arcgis-zoom slot="top-left"></arcgis-zoom>
|
|
630
|
+
</arcgis-map>
|
|
631
|
+
<div id="toolbar">
|
|
632
|
+
<calcite-button id="measureBtn">Measure</calcite-button>
|
|
633
|
+
<calcite-button id="clearBtn">Clear</calcite-button>
|
|
634
|
+
</div>
|
|
635
|
+
|
|
636
|
+
<script type="module">
|
|
637
|
+
import Measurement from "@arcgis/core/widgets/Measurement.js";
|
|
638
|
+
|
|
639
|
+
const viewElement = document.querySelector("arcgis-map");
|
|
640
|
+
await viewElement.viewOnReady();
|
|
641
|
+
|
|
642
|
+
const measurement = new Measurement({ view: viewElement });
|
|
643
|
+
viewElement.ui.add(measurement, "bottom-right");
|
|
644
|
+
|
|
645
|
+
document.getElementById("measureBtn").onclick = () => {
|
|
646
|
+
measurement.activeTool = "distance";
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
document.getElementById("clearBtn").onclick = () => {
|
|
650
|
+
measurement.clear();
|
|
651
|
+
};
|
|
652
|
+
</script>
|
|
653
|
+
</body>
|
|
654
|
+
</html>
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
## Common Pitfalls
|
|
658
|
+
|
|
659
|
+
1. **API Key for routing**: Route service requires valid API key or authenticated user
|
|
660
|
+
|
|
661
|
+
2. **Identify tolerance**: Set appropriate tolerance based on zoom level
|
|
662
|
+
|
|
663
|
+
3. **Swipe layer order**: Leading/trailing layers must be in the map's layers collection
|
|
664
|
+
|
|
665
|
+
4. **Measurement units**: Set appropriate units for the measurement context
|
|
666
|
+
|
|
667
|
+
5. **3D vs 2D measurement**: Use different widgets/tools for 2D and 3D views
|
|
668
|
+
|