-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add queryFeatures() to send query requests to feature services #126
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf1108e
add queryFeatures() to send query requests to feature services
tomwayson 62c99a7
forgot to manually bump arcgis-rest-feature-service's version
tomwayson c961602
add demo for arcgis-rest-feature-service
tomwayson 36693ca
Merge branch 'master' into feat/query-features
tomwayson a8577d7
feature service demo depends on arcgis-rest-request
tomwayson aed38aa
query features example lets users set record count and query field
tomwayson ad61b0a
final demo code clean up reorg
tomwayson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Running this demo | ||
|
||
1. Make sure you run `npm run bootstrap` in the root folder to setup the dependencies | ||
1. `npm start` | ||
1. Visit http://localhost:8080 | ||
1. Enter a search term and click "Search" to see results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
|
||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="jumbotron" > | ||
<h1>search features!</h1> | ||
<form id="searchFrom" class="form-inline"> | ||
<div class="form-group"> | ||
<input type="text" class="form-control" id="search" placeholder="Search by tree type or condition" style="width: 400px" tabindex="0"> | ||
</div> | ||
<button type="submit" class="btn btn-default">Search</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Tree ID</th> | ||
<th>Type</th> | ||
<th>Condition</th> | ||
</tr> | ||
</thead> | ||
<tbody id="tableBody"> | ||
</tbody> | ||
</table> | ||
<p id="additionalRowsMessage" style="display: none" class="alert alert-warning">There are additional rows that meet your search criteria.</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- TODO: I would not expect this to work w/o first adding @esri/arcgis-rest-request, but it does --> | ||
<script src="node_modules/@esri/arcgis-rest-feature-service/dist/umd/arcgis-rest-feature-service.umd.js"></script> | ||
|
||
<script> | ||
// respond when s user fills out he search text and hits enter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typos here |
||
// or clicks on the Search button | ||
const searchFrom = document.getElementById('searchFrom'); | ||
searchFrom.addEventListener('submit', function (e) { | ||
var searchTerm = e.target.search.value; | ||
searchTrees(searchTerm); | ||
e.preventDefault(); | ||
}); | ||
|
||
function searchTrees(searchTerm) { | ||
arcgisRest.queryFeatures({ | ||
url: 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0', | ||
// see: https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm | ||
// for all possible query parameters | ||
params: { | ||
// NOTE: returnGeometry is set to false by default | ||
where: 'Cmn_Name LIKE \'%' + searchTerm + '%\' OR Condition LIKE \'%' + searchTerm + '%\'', | ||
outFields: ['FID','Tree_ID','Cmn_Name','Condition'], | ||
// limit to number of records that will show on the page | ||
resultRecordCount: 15 | ||
} | ||
}).then(function(response) { | ||
refreshTable(response.features); | ||
// show/hide additional rows message | ||
var additionalRowsMessageDisplay = response.exceededTransferLimit ? 'block' : 'none'; | ||
document.getElementById('additionalRowsMessage').style.display = additionalRowsMessageDisplay; | ||
}); | ||
} | ||
|
||
function refreshTable(features) { | ||
// clear table | ||
var tableBody = document.getElementById('tableBody'); | ||
tableBody.innerHTML = ''; | ||
// show returned features (if any) | ||
var rows = features.map(function (feature) { | ||
return '<tr><td>' + feature.attributes.Tree_ID + '<td>' + feature.attributes.Cmn_Name + '</td><td>' + feature.attributes.Condition + '</td></tr>'; | ||
}); | ||
tableBody.innerHTML = rows.join(''); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "feature-service-browser", | ||
"version": "1.0.3", | ||
"private": true, | ||
"description": "Vanilla JavaScript demo of @esri/arcgis-rest-feature-service", | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@esri/arcgis-rest-feature-service": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"http-server": "*" | ||
}, | ||
"scripts": { | ||
"start": "http-server ." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
searchForm
?