POST
|
Here's an example from Esri on how to setup a Popup Template: https://developers.arcgis.com/javascript/latest/sample-code/popuptemplate-function/ I opened the Code Pen and changed the populationChange function to: function populationChange(feature) {
const ogId = feature.graphic.attributes.STATE_NAME // Added
const div = document.createElement("div");
const upArrow =
'<svg width="16" height="16" ><polygon points="14.14 7.07 7.07 0 0 7.07 4.07 7.07 4.07 16 10.07 16 10.07 7.07 14.14 7.07" style="fill:green"/></svg>';
const downArrow =
'<svg width="16" height="16"><polygon points="0 8.93 7.07 16 14.14 8.93 10.07 8.93 10.07 0 4.07 0 4.07 8.93 0 8.93" style="fill:red"/></svg>';
// Calculate the population percent change from 2010 to 2013.
const diff = feature.graphic.attributes.POP2013 - feature.graphic.attributes.POP2010;
const pctChange = (diff * 100) / feature.graphic.attributes.POP2010;
const arrow = diff > 0 ? upArrow : downArrow;
// Add green arrow if the percent change is positive and a red arrow for negative percent change.
div.innerHTML =
"As of 2010, the total population in this area was <b>"+feature.graphic.attributes.POP2010+"</b> and the density was <b>"+feature.graphic.attributes.POP10_SQMI+"</b> sq mi. As of 2013, the total population was <b>"+feature.graphic.attributes.POP2013+"</b> and the density was <b>"+feature.graphic.attributes.POP13_SQMI+"</b> sq mi. <br/> <br/>" +
"Percent change is " +
arrow +
"<span style='color: " +
(pctChange < 0 ? "red" : "green") +
";'>" +
pctChange.toFixed(3) +
"%</span>" +
"<br /><a href='https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/US_Counties/FeatureServer/0/query?where=State_Name%3D%27" + ogId + "%27&outFields=*&f=html' target='_blank'>Test Me</a>"; // Added
return div;
}; So I set 'ogId' to be an attribute that is not part of the popup, and you can see all of the attributes here: https://www.arcgis.com/home/item.html?id=e8f85b4982a24210b9c8aa20ba4e1bf7#overview But you can get access to a field for the selected graphic that is not part of the popup, which is what I think you are after.
... View more
03-11-2024
12:39 PM
|
0
|
1
|
116
|
POST
|
I'm not sure I'm following. If you want to not have things in the popup, then just leave them out, you control that, as in: const popupCase = {
"title": "Address: {Property_Address}",
"content": [{
type: "text",
text: "<ul><li><b>Description:</b> {CaseDesc}<br></li>"+
"<li><b>Status:</b> {CaseStatus}<br></li>"+
"<li><b>Date of Infraction:</b> {DateOfInfraction}<br></li>"+
"<li><b>Inspector:</b> {InspectorFullName}<br></li>"+
"<li><b>Owner Name:</b> {Property_OwnerName}<br></li>"+
"<li><b>Legal Description</b> {Property_LegalDescription}<br></li>"+
"<li><b>Narrative</b> {Narrative}<br></li>"
}],
actions: [openSphinxAction,openPaAction]
}; Or, if you want to keep them in the popup I think you can just modify the display style to 'none', as in: const popupCase = {
"title": "Address: {Property_Address}",
"content": [{
type: "text",
text: "<ul><li><b>Description:</b> {CaseDesc}<br></li>"+
"<li><b>Status:</b> {CaseStatus}<br></li>"+
"<li><b>Date of Infraction:</b> {DateOfInfraction}<br></li>"+
"<li><b>Inspector:</b> {InspectorFullName}<br></li>"+
"<li><b>Owner Name:</b> {Property_OwnerName}<br></li>"+
"<li><b>Legal Description</b> {Property_LegalDescription}<br></li>"+
"<li><b>Narrative</b> {Narrative}<br></li>"+
"<li style="display:none;"><b>OriginalID:</b> {OriginalId}<br></li>"+
"<li style="display:none;"><b>Property Id:<\b> {Property_PropertyId}</li></ul>"
}],
actions: [openSphinxAction,openPaAction]
}; I recently did this just to test some popup output, without losing what was there. Not sure why else you would use it. Or you can modify the REST call to query out the feature information. I think this last one is not what you are looking for as you want the ID info, you just don't want to display it.
... View more
03-11-2024
10:11 AM
|
0
|
3
|
142
|
POST
|
Oh, and look at the Console for the results. I just used the Esri sample for promises, but I cleaned most of it out and never got the textArea to work well. But the data's viewable in the console.
... View more
02-28-2024
01:45 PM
|
0
|
0
|
363
|
POST
|
I went back and looked what I had done for 4.24, and it relied on Dojo promises. Esri just talks about the .then/.catch method of working with promises, but in a script I had developed I as passing the promise (deferred) among multiple functions and only after successfully completing the last one did I resolve (or reject) the promise. Then, the program waited for all function calls to finish for all records, which as accomplished using the Dojo 'All' function. Looks like this is not available anymore as 4.29 now seems devoid of all Dojo, and after looking at possibly adding it to the libraries, I thought the better of it and decided I should figure out how to do this with native Javascript promises. This may not be the correct way, but it works. You just have to parse through all of the resulting features for each call to get (in this case) the value for 'Hispanic': <html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Request data from a remote server | Sample | ArcGIS Maps SDK for JavaScript 4.29</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.29/"></script>
<script type="module" src="https://js.arcgis.com/calcite-components/2.5.1/calcite.esm.js"></script>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/2.5.1/calcite.css" />
</head>
<body>
<calcite-shell>
<calcite-panel heading="Using esri/request">
<calcite-block
heading="Enter a URL:"
description='Enter a server URL to the input box below, then click the "Make Request" button to send a request.'
open
>
<calcite-input-text
id="input-url"
placeholder="https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer"
value="https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer"
required
></calcite-input-text>
<calcite-button id="request-button" style="padding-top: 5px">Make Request</calcite-button>
<calcite-label style="padding-top: 10px" scale="l"
>Server response from the request:
<calcite-text-area
id="results-text-area"
placeholder="Request response will show here.."
read-only
rows="25"
></calcite-text-area>
</calcite-label>
</calcite-block>
</calcite-panel>
</calcite-shell>
<calcite-alert id="alert" kind="danger" icon label="Danger alert" auto-close>
<div slot="title">Enter a valid URL.</div>
</calcite-alert>
<script>
require(["esri/request"], (esriRequest) => {
const requestButton = document.getElementById("request-button");
const urlInput = document.getElementById("input-url");
const textArea = document.getElementById("results-text-area");
const alert = document.getElementById("alert");
let url;
let sStates = ['Arizona', 'California', 'Nevada']
let promiseStates = [];
let sResults = '';
requestButton.addEventListener("click", () => {
//var variable = null;
for (let j = 0; j < sStates.length; j++) {
let thestate = sStates[j];
const aDef = new Promise((resolve, reject) => {
get_results(thestate, resolve, reject);
});
promiseStates.push(aDef);
}
Promise.all(promiseStates).then((values) => {
console.log("in Promise.all");
console.log(values);
textArea.value += sResults;
});
});
async function get_results(state, pRes, pRej) {
console.log(state);
let getinfo =
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2/query?f=json&Where=STATE_NAME='";
params = state;
params += "'&outFields=NAME,HISPANIC";
getinfo = getinfo + encodeURI(params);
var options = {
query: {
f: "json",
},
responseType: "json",
};
console.log(getinfo);
console.log()
await esriRequest(getinfo, options).then((response) => {
console.log("in esriRequest");
console.log(response.data);
sResults += response.data.fields["Name"];
return pRes(response);
})
.catch(function (error) {
console.error("esriRequest Error: " + error);
textArea.value = error;
return pRej(error);
});
}
});
</script>
</body>
</html> (oh, and it uses your original function for calling the REST service).
... View more
02-28-2024
01:40 PM
|
1
|
0
|
363
|
POST
|
I'm not sure what you need to set an await for, just handling the Esri Request response should be sufficient, as in: function get_results(state) {
let getinfo =
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2/query?f=json&Where=STATE_NAME='";
params = state;
params += "'&outFields=NAME,HISPANIC";
getinfo = getinfo + encodeURI(params);
esriRequest(getinfo, {
responseType: "json"options
}).then(function (response) {
// Do something like
let thisVal = response.data.fields[0].domain.codedValues;
optionsSelector.push({value: thisVal, label thisVal.name});
console.log(response);
}).catch(function (error) {
console.error("esriRequest Error: " + error);
});
});
} But if you need to wait for something you can always push that into a promise, like: function get_results(state) {
let defStateQuery = new Deferred();
let promiseQueries = []
promiseQueries.push(defStateQuery)
setTimeout(function (inState) {
let getinfo = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2/query?f=json&Where=STATE_NAME='";
params = inState;
params += "'&outFields=NAME,HISPANIC";
getinfo = getinfo + encodeURI(params);
//var options = { query: {f: "json",}, responseType: "json"};
esriRequest(getinfo, {
responseType: "json"options
}).then(function (response) {
// Do something like
let thisVal = response.data.fields[0].domain.codedValues;
optionsSelector.push({value: thisVal, label thisVal.name});
console.log(response);
deferred.resolve(response);
return deferred.promise
}).catch(function (error) {
console.error("esriRequest Error: " + error);
deferred.reject(error);
return deferred.promise;
});
});
}, 0);
return deferred.promise;
}
all(promiseQueries).then(function (results) {
console.log(results);
}); This sample allows you to enter a URL and see the results, but the REST service seems to not be working (maybe there's too many of us trying to write a response, LOL). https://developers.arcgis.com/javascript/latest/sample-code/request/
... View more
02-28-2024
11:12 AM
|
0
|
1
|
389
|
POST
|
I think that's what you'd have to do if you utilized the Search Widget, and I don't know about the performance of 60+ layers but it'd probably work at least. If you have only one (or a small number of ) field to search in each layer maybe you could mimic the Search Widget by using the where clause directly on the REST web service, then you could compile the possible features selected in whatever way you wanted from the resulting JSON, as in this REST call: https://services2.arcgis.com/2t1927381mhTgWNC/arcgis/rest/services/BusStopsWAmenities/FeatureServer/0/query?where=stopID+%3D+5655&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&relationParam=&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&defaultSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=html&token=
... View more
02-27-2024
01:13 PM
|
2
|
1
|
192
|
POST
|
Per this page (https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm ) which is for ArcGIS Online, I wonder if the 'button' tag is no longer accepted as an HTML Element. I was able to get an IMG tag to work by dropping it into some sample code, but not the 'onclick' action yet: <html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>
Intro to PopupTemplate | Sample | ArcGIS Maps SDK for JavaScript 4.27
</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.27/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.27/"></script>
<script>
require([
"esri/Map",
"esri/layers/FeatureLayer",
"esri/views/MapView",
"esri/widgets/Legend"
], (Map, FeatureLayer, MapView, Legend) => {
// Create the map
const map = new Map({
basemap: "gray-vector"
});
// Create the MapView
const view = new MapView({
container: "viewDiv",
map: map,
center: [-73.95, 40.702],
zoom: 10
});
view.ui.add(new Legend({ view: view }), "bottom-left");
/*************************************************************
* The PopupTemplate content is the text that appears inside the
* popup. {fieldName} can be used to reference the value of an
* attribute of the selected feature. HTML elements can be used
* to provide structure and styles within the content. The
* fieldInfos property is an array of objects (each object representing
* a field) that is use to format number fields and customize field
* aliases in the popup and legend.
**************************************************************/
const template = {
// autocasts as new PopupTemplate()
title: "{NAME} in {COUNTY}",
content: "<img src='https://images.freeimages.com/fic/images/icons/694/longhorn_r2/256/forward_button.png' height='50px;' onlick='javascript:countyAssessor(''{COUNTY}'')>Click for {COUNTY} County Assessor web page'>"
};
// Reference the popupTemplate instance in the
// popupTemplate property of FeatureLayer
const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/ACS_Marital_Status_Boundaries/FeatureServer/2",
popupTemplate: template
});
map.add(featureLayer);
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html> I wonder if you can just use the Popup 'Actions' and change the icon to be what you want it to be: https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#actions
... View more
06-23-2023
09:13 AM
|
1
|
1
|
2288
|
POST
|
Right off the bat I'm just going to say that 200 layers is waaayyyy too many layers to be loading. Even if you used ArcGIS Pro and had the data stored locally, the time it took to display that many would seem slow. There's also a difference in having 200 simple layers, like just a couple of points/lines, versus 200 layers with a few hundred (more?) records each, but both scenarious will run slow in performance, especially when exacerbated by being online. Some things to think about in trying to speed things up: 1. Make sure all of the data is in Web Mercator projection. That's what Online uses and even if you are using an internal Portal, if you use any online basemaps they will still be using Web Mecator. 2. Reduce the fields to only what is necessary. Having a large number of fields will not help anything. 3. Make sure the spatial indexes are there and up to date. You can update them for Online featureclasses by going into the Layer's settings. 4. Use scale dependency settings to make sure each layer is only showing at the scale(s) it is relevant to view at. In the past, I had developed an application that needed some large layers, and we only showed 1 or 2 layers upon open, and slowly added them to the map (not too slow) while the user started moving around. This was long before the current ArcGIS Online usage, but if you load an ArcGIS Online map with the data already loaded it might already have some of the performance fine tuned. Still, my recommendation is to figure out how to combine data layers, put your data on different maps, or re-evaluate why you need 200 layers. Maybe you could create one map with a few layers, then another map with some other layers, and then move between the maps when selected. Just a thought.
... View more
06-19-2023
09:05 AM
|
2
|
1
|
437
|
POST
|
Not sure, maybe you need to add your HTML to Content instead of Description? I added a green button to this sample popup code from Esri: <html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Popup actions | Sample | ArcGIS Maps SDK for JavaScript 4.27</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.27/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.27/"></script>
<script>
require([
"esri/Map",
"esri/layers/FeatureLayer",
"esri/views/MapView",
"esri/geometry/geometryEngine",
"esri/core/reactiveUtils"
], (Map, FeatureLayer, MapView, geometryEngine, reactiveUtils) => {
// Create the Map
const map = new Map({
basemap: "gray-vector"
});
// Create the MapView
const view = new MapView({
container: "viewDiv",
map: map,
center: [-117.08, 34.1],
zoom: 11
});
/*************************************************************
* The PopupTemplate content is the text that appears inside the
* popup. Bracketed {fieldName} can be used to reference the value
* of an attribute of the selected feature. HTML elements can be
* used to provide structure and styles within the content.
**************************************************************/
// Add this action to the popup so it is always available in this view
const measureThisAction = {
title: "Measure Length",
id: "measure-this",
image: "https://developers.arcgis.com/javascript/latest//sample-code/popup-actions/live/Measure_Distance16.png"
};
const template = {
// autocasts as new PopupTemplate()
title: "Trail run",
content: "<div>{name}</div><div class='popup-content'><img src='https://w7.pngwing.com/pngs/714/342/png-transparent-computer-icons-button-green-green-3d-computer-graphics-grass-color-thumbnail.png' height='20px' alt='image description'></div>",
actions: [measureThisAction]
};
const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/TrailRuns/FeatureServer/0",
popupTemplate: template
});
map.add(featureLayer);
// Execute each time the "Measure Length" is clicked
function measureThis() {
const geom = view.popup.selectedFeature.geometry;
const initDistance = geometryEngine.geodesicLength(geom, "miles");
const distance = parseFloat(Math.round(initDistance * 100) / 100).toFixed(2);
view.popup.content =
view.popup.selectedFeature.attributes.name +
"<div style='background-color:DarkGray;color:white'>" +
distance +
" miles.</div>";
}
// Event handler that fires each time an action is clicked.
reactiveUtils.on(
() => view.popup,
"trigger-action",
(event) => {
// Execute the measureThis() function if the measure-this action is clicked
if (event.action.id === "measure-this") {
measureThis();
}
}
);
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
... View more
06-19-2023
08:45 AM
|
0
|
0
|
187
|
POST
|
Just checked in ArcMap 10.8.2 and the functionality was the same. Added an Excel table using 'Excel to Table'. Righ clicked on the table in the TOC and ran 'Display X Y Data', using the right lat/long fields and making sure to set the projection to Geographic/World/WGS84 (WKID:4326). Then you can export it to a shapfile (if desired) by righ clicking the new point featurclass, selecting 'Data' and then 'Export Data...'. It'll try to export the featurclass to a file geodatabse, but if you select the file (browse) icon you can specify the output is a shapefile.
... View more
05-03-2023
09:02 AM
|
0
|
0
|
1009
|
POST
|
Whew, it's seems like forever since I've opened ArcMap, but here's how I'd handle what you are talking about using ArcGIS Pro, and I would look for the similar functions in ArcMap. 1. Add CSV to the map, right click on it and select 'Display X Y Data', and select the easting (X) and northing (Y) fields. A new featureclass (FC) layer is added to your map and you can export this to a shapefile or file GDB if you want. 2. To 'display' this new point FC with a polygon FC, you just add them both to a map. If you are trying to get the values from one to the other then yes, it's the Spatial Join command. You are basically joining them based on their XY, so if you want the values from the polygon into the points, you set the point as your tartget FC and the polygons as your join FC and decide how to handle the fields.
... View more
05-03-2023
08:51 AM
|
0
|
1
|
1010
|
POST
|
If by 'login', you mean get access to the REST data on the server, then yes. If you can generate a token for a service then you can use it in the URL to access the data. For services that aren't protected, you don't need to pass the Token. Most servers are configured to not allow you to browse the REST services, so you pretty much need to know what you are looking for, but if you know the URL, and if it's protected and you have the credentials to generate a token, then you can just add the token to the URL request to the REST endpoint. For most Javascript applications that need to access protected data, setting up a proxy class to handle the token (if needed) helps.
... View more
04-18-2023
07:53 AM
|
0
|
0
|
151
|
POST
|
This works for me because I have a JSON service I'm trying to access. Everytime I do an new JSON service it comes in with MIME typ 'text/json, application/json', and if I just limit it to 'application/json' it works fine.
... View more
03-24-2023
08:53 AM
|
0
|
0
|
766
|
POST
|
I don't think there's a way to do this directly out of an ArcGIS REST web service. I utilized a separate libraries to support doing this, namely: <!--Libraries for importing and exporting Excel data-->
<script type="text/javascript" src="//unpkg.com/xlsx/dist/shim.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.6/xlsx.full.min.js"></script>
<script type="text/javascript" src="//unpkg.com/blob.js@1.0.1/Blob.js"></script>
<script type="text/javascript" src="//unpkg.com/file-saver@1.3.3/FileSaver.js"></script> Following the logic of this page from 'Ferry Ren' https://www.cnblogs.com/zhenggaowei/p/11732170.html, I built a procedure to pull the data from the REST endpoint into a JSON string, and then exported it into an Excel file. The main thing to keep in mind is that if you have more than 2000 records to be exported, you need to keep pulling them until you get them all. I 'borrowed' the concept of using a recursive function from Gavin Rehkemper (https://gavinr.com/arcgis-javascript-query-all-features/ ). It looks something like this: // Recursive function - Handles calling the service multiple times if necessary.
const _getAllRecsRecursive = (layerURL, featuresSoFar, sWhere, relID) => {
// Have to use queryTask instead of queryFeatures as the related tables can't be turned into feature layers.
if (relID < 0) {
let aQuery = new Query();
aQuery.start = featuresSoFar.length;
aQuery.num = 2000;
aQuery.where = sWhere;
aQuery.outFields = ["*"];
return query.executeQueryJSON(layerURL, aQuery).then(function (results) {
// If "exceededTransferLimit" is true, then make another request (call this same function) with a new "start" position.
// If not, we're at the end and we should just concatenate the results and return what we have.
if (
results.exceededTransferLimit &&
results.exceededTransferLimit === true
) {
return _getAllRecsRecursive(
layerURL,
[...featuresSoFar, ...results.features],
sWhere,
-1
);
} else {
return Promise.resolve([...featuresSoFar, ...results.features]);
}
});
}
else {
let aRelQuery = new Query(); //RelationshipQuery();
aRelQuery.start = featuresSoFar.length;
aRelQuery.num = 2000;
aRelQuery.where = sWhere;
aRelQuery.outFields = ['*'];
aRelQuery.relationshipId = relID;
return query.executeRelationshipQuery(layerURL, aRelQuery).then(function (results) {
// If "exceededTransferLimit" is true, then make another request (call this same function) with a new "start" position.
// If not, we're at the end and we should just concatenate the results and return what we have.
let curFeatures = [];
for (let aRecIdx of Object.keys(results)) {
let aRelSet = results[aRecIdx];
for (let aFeature of aRelSet.features) {
curFeatures.push(aFeature);
}
}
if (results.exceededTransferLimit &&
results.exceededTransferLimit === true) {
return _getAllRecsRecursive(
layerURL,
[...featuresSoFar, ...curFeatures],
sWhere,
relID
);
} else {
return Promise.resolve([...featuresSoFar, ...curFeatures]);
}
});
}
};
function getAllRecs(layerURL, sWhere, relId) {
return _getAllRecsRecursive(layerURL, [], sWhere, relId);
}
// Export to excel
let btnExport = document.getElementById("btnExport");
let dateNow = Date.now();
btnExport.onclick = function () {
// Create a new Excel Workbook
var workBook = {
SheetNames: ["Testing"],
Sheets: {},
Props: {
Title: "Title for Testing",
Subject: "Testing",
Author: "Your name, leave blank, or ?",
CreatedDate: dateNow
}
// Pull data until there is no more, storing data until needed later
let outResults = [];
let outWhere = "1=1"; // modify this to support subset of total recs
getAllRecs(restURL, outWhere, -1).then((results) => {
for (let aRec of results) {
let curAtts = aRec.attributes;
// Make any necessary attribute modifications here...
// I have routines here to fix dates from Epoch dates, remove edit fields, etc.
// Push results to results list
outResults.push(curAtts);
//console.log(curStopAtts)
stopObjectIds.push(curStopAtts[fldBusStopOID]); //"OBJECTID"]);
}
})
// Set up Excel workbook
var wopts = {
bookType: 'ods',
bookSST: false,
type: 'binary'
};
// Pull in workbook sheet.
try {
workBook.Sheets["Testing"] = XLSX.utils.json_to_sheet(outResults, { dateNF: 'mm/dd/yyyy;@', cellDates: true });
// Export spreadsheet using unique name built from current date/time.
let today = new Date(Date.now());
let cDate = (today.getMonth() + 1) + '_' + today.getDate() + '_' + today.getFullYear();
let cTime = today.getHours() + "_" + today.getMinutes() + "_" + today.getSeconds();
let sToday = cDate + '_' + cTime;
let exportFileName = 'BSR_' + sToday + '.xls'; //'BSR_' + sToday + '.xls'; //'BSR_' + sToday + '.ods'; //'BSR_' + sToday + '.xlsx';
let wbOut = XLSX.write(workBook, wopts);
saveAs(new Blob([changeData(wbOut)], { type: "" }), exportFileName);
} catch (error) {
console.log(error);
}
};
Hopefully that all makes sense. I took out a lot that I have in there as I'm cleaning data as it gets pulled, and I use it to export out related data as well (hence the 'relID' variable in the getAllRecs and _getAllRecsRecursive procedures). Also, it pushes out an ODS file (Open Document Spreadsheet). I was able to push it out to a CSV file, but then Excel always complained that it wasn't in the correct format, so I changed it to ODS, which is obviously not the 'correct' format, but when it is opened in Excel (no problems there) the user understands why the error pops up that it's not in the correct format. Would love to know if there's an easier way to do this, but this has been operational for over a year now.
... View more
03-14-2023
09:49 AM
|
1
|
0
|
1012
|
POST
|
Sample code links exist in that Search Widget help page link I provided already. And here's another one from the Code Samples. You might also gain some help by typing 'search widget' into the Esri Community search widget.
... View more
12-02-2022
11:00 AM
|
0
|
0
|
636
|
Title | Kudos | Posted |
---|---|---|
1 | 02-28-2024 01:40 PM | |
2 | 02-27-2024 01:13 PM | |
1 | 10-18-2022 11:31 AM | |
1 | 06-23-2023 09:13 AM | |
2 | 06-19-2023 09:05 AM |
Online Status |
Offline
|
Date Last Visited |
03-11-2024
10:48 PM
|