This is the code I have. I'm saving the mapView state into jimuMapView variable in line 12. But, Im running into an "Property 'createQuery/queryFeatures()' does not exist on type 'Layer'." on lines 23 and 28. Can you take a look thx
import React from 'react';
import { AllWidgetProps } from 'jimu-core';
import Setting from '../setting/setting';
import { UseDataSource } from 'jimu-core'
import { JimuMapViewComponent, type JimuMapView } from 'jimu-arcgis'
const { useState } = React
const Widget = (props: AllWidgetProps<unknown>) => {
const [jimuMapView, setJimuMapView] = useState<JimuMapView>()
const buttonStyle = {
fontSize: '',
padding: '10px 20px',
borderRadius: '5px',
}
function customExportCSV() {
const featureLayer = jimuMapView.view.map.findLayerById('layerId');
let query = featureLayer.createQuery();
query.where = '1=1'
let csv = ''
let headers = ''
featureLayer.queryFeatures(query).then((featureSet) => {
headers = Object.keys(featureSet.features[0].attributes).join(',')
for (let i = 0; i < featureSet.features.length; i++) {
const data = Object.values(featureSet.features[i].attributes).join(',')
csv += data + '\n'
}
csv = headers + '\n' + csv
downloadCSV(csv)
})
}
function downloadCSV(csv) {
const csvFile = new Blob([csv], { type: 'text/csv' });
const downloadLink = document.createElement("a");
downloadLink.download = 'search_results.csv';
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
}
return (
<div className="widget-demo jimu-widget m-2">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></link>
<div className='inside-card'>
<header>{Setting.value}</header>
<Button style={buttonStyle} onClick={customExportCSV}>Export Data</Button>
</div>
</div>
)
}
export default Widget;