|
POST
|
Is it possible to update or add to and already declared definition expression? For instance, in your format above I can declare multiple in the initial definationExpression with id, but as soon as I try to update or add to it, it never reads. I am able to hardcode the values in now initially, or pass initial variables in with multiple taking effect now - but as soon as I try to update or change my initial i.e. my 'layer.definitionExpression = "id IN ('"+ selectedID + "','us6000a4yi')";' - it does not update, only seemingly executing the first instance of definitionExpression with the id. It appears now I'm struggling with how to update a definitionExpression (add to, remove, or replace) - I have tried layer.refresh(); in attempt for it to read my latest definition, but still didn't seem to work, I have also tried nesting them in variables and functions. This appears to be similar to what I'm trying to do: How to setDefinitionExpression on FeatureLayer in web map? (v3.30) -except in 3.30 version, I also tried this and wont take the syntax in 4.xx. let selectedID; let datA; layer.definitionExpression = "id IN ('')"; function filterByID(event) { console.log('filter hit'); selectedID = event.target.getAttribute("data-id"); console.log(selectedID); layer.refresh(); layer.definitionExpression = "id IN ('"+ selectedID +"')"; }
... View more
06-22-2020
04:40 PM
|
0
|
15
|
2204
|
|
POST
|
Thanks so much Robert, was pursuing this until noticed this service is now gone since today? https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/USGS_Seismic_Data_v1/FeatureServer/1/ (no layers found) - It was working yesterday, is this just maintenance or it being marked as depreciated as well?
... View more
06-22-2020
07:21 AM
|
0
|
2
|
2204
|
|
POST
|
I have successfully been able to filter, for instance shakemaps, by attribute id - I have successfully achieved this multiple ways - but all ending with the same problem. 1.) with the where filter 2.) definition expression 3.) iterating through all attribute ids and bringing them back. The problem: All exists for only allowing/displaying one per attribute id at a time.. my goal is to feed the attribute ids into a checkbox list (which I have done), but allowing for items via attribute id to be added to the map as they are checked, collectively, one at a time - currently I can not seem to get this to work with the aspect of having multiple or more then one appear at a time on the map - each filter or attempt results in the next item being added while at the same time the previous is replaced (only showing one at a time). 1.) i.e. the below filter (attempted logic 1) - & also here is CodePen of: ..... function filterByID(event) { const selectedID = event.target.getAttribute("data-id"); eqLayerView.filter = { where: "id = '" + selectedID + "'" }; } view.whenLayerView(fl) .then(function(layerView) { eqLayerView = layerView; eqLayerView.filter = { where: "id = ''" };............. 2.) i.e. another attempted logic (adding multiple at a time here, line by line, or via array): layer.definitionExpression = "id = 'us70008jr5'",layer.definitionExpression = "id = 'cgi988jr52'", 3.) i.e. 3rd attempt with a suggestion here on GIS exchange: Loop through attribute ids of FeatureLayer layer .load() .then(() => { // create a query from the layer const query = layer.createQuery(); query.returnDistinctValues = true; query.where = "grid_value > 2"; // or 1=1 if you need them all // the field you want distinct values for query.outFields = ["id"]; return layer.queryFeatures(query); }) .then(({ features }) => { // extract the ids to a list const ids = features.map(({ attributes }) => attributes.id); return ids; }) .then((ids) => { // You can store them how you want, in this case, // I put them in a dropdown select menu const fragment = document.createDocumentFragment(); ids.forEach((id) => { const option = document.createElement('option'); option.value = id; option.innerText = id; fragment.appendChild(option); }); list.appendChild(fragment); map.add(layer);}); All attempted logic above result in the toggling of a shakemap by attribute id to be displayed only one at a time — by toggling a new on, the previous turns off, I need the ability to have multiple being able to exist on the map at once.
... View more
06-20-2020
05:50 PM
|
0
|
20
|
4900
|
|
POST
|
Thanks Robert, is it possible to 'toggle by attribute id' on or off showing multiple at a time... The goal would be push the attributes ids in a checkbox list, and check or unchecked to toggle the display of each shakemap by attribute id. The current problem is I've only been able to get it work as follows: start with nothing display -> checked checkbox would only show one at a time (and hide previous checked). In other words I'm trying to create the ability to show or hide specific quakes by id, not just showing one a time as such with the definition expression technique and filter above, but rather the ability to check and show multiple at a time, is this possible? i.e. with the below how could I retain multiple if needed (if checked)? It seems to only operate with one at a time. eqLayerView.filter = {
where: "id = '" + selectedID + "'"
};
... View more
06-20-2020
05:39 PM
|
0
|
0
|
2069
|
|
POST
|
Thank you for the response, Robert, however I don't think it's that. I have tried running it with that line commented out, and also just tried your change in any case and the console error still persists..
... View more
06-15-2020
06:43 AM
|
0
|
2
|
1474
|
|
POST
|
I have the following code to filter shake intensity maps by ID. It works fine with this URL --> https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/USGS_Seismic_Data_v1/FeatureServer/1/ but as soon as I plugin my production mapserver URL of --> https://livefeeds.arcgis.com/arcgis/rest/services/LiveFeeds/USGS_Seismic_Data/MapServer/12/ I immediately get a console error 400 query failing, i.e. below, and the map no longer displays. error: full code: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> <title>Filter features by attribute - 4.15</title> <link rel="stylesheet" href="https://js.arcgis.com/4.15/esri/themes/light/main.css" /> <script src="https://js.arcgis.com/4.15/"></script> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } .id-item:focus { background-color: dimgrey; } .id-item:hover { background-color: dimgrey; } #titleDiv { padding: 10px; } #titleText { font-size: 20pt; font-weight: 60; padding-bottom: 10px; } </style> <script> require([ "esri/views/MapView", "esri/Map", "esri/layers/FeatureLayer", "esri/widgets/Expand" ], function(MapView, Map, FeatureLayer, Expand) { let floodLayerView; const layer = new FeatureLayer({ url: "https://livefeeds.arcgis.com/arcgis/rest/services/LiveFeeds/USGS_Seismic_Data/MapServer/12", outFields: ["*"] }); const map = new Map({ basemap: "gray-vector", //layers: [layer] }); const view = new MapView({ map: map, container: "viewDiv", center: [-98, 40], zoom: 4 }); layer.definitionExpression = "eventTime >= CURRENT_TIMESTAMP - 30 AND grid_value > 2", map.add(layer); const idNodes = document.querySelectorAll(`.id-item`); const idElement = document.getElementById("id-filter"); idElement.addEventListener("click", filterByID); function filterByID(event) { const selectedID = event.target.getAttribute("data-id"); eqLayerView.filter = { where: "id = '" + selectedID + "'" }; } view.whenLayerView(layer).then(function(layerView) { eqLayerView = layerView; eqLayerView.filter = { where: "id = ''" }; idElement.style.visibility = "visible"; var query = layer.createQuery(); query.outFields = ["id"]; query.returnDistinctValues = true; query.returnGeometry = false; layer.queryFeatures(query).then(function(results){ results.features.map(function(feat){ let id = feat.attributes.id; let opt = document.createElement("input"); opt.type = "checkbox"; let label = document.createElement('label') label.innerHTML = id; opt.className = "id-item visible-id"; opt.setAttribute("data-id", id); idElement.appendChild(opt); idElement.appendChild(label); }); }); }); }); </script> </head> <body> <div id="id-filter" class="esri-widget"> </div> <div id="viewDiv"></div> <div id="titleDiv" class="esri-widget"> <div id="titleText">Earthquakes</div> <div>Shake Intensity</div> </div> </body> </html>
... View more
06-15-2020
06:24 AM
|
0
|
4
|
1606
|
|
POST
|
Thanks so much, Robert! Small question - is it necessary to add the layer (all) first, or initially, before being able to accomplish the filter? For instance, in my CodePen I've added all the layers by the id as checkboxes, the goal would be to add each when clicked one at a time, starting with no layers. It works after I click one checkbox initally which seems to clear all, then I select a layer. But I'd like to start with no shake maps, and add just the ones that are checked via checkbox one at a time.
... View more
06-11-2020
09:37 AM
|
0
|
3
|
2069
|
|
POST
|
Ultimately I suppose how could I loop through and get all the shakemap ids returned from my rest URL call?
... View more
06-10-2020
05:03 PM
|
0
|
5
|
2069
|
|
POST
|
Thanks, I'm seeming to get a better handle with this approach... except, would there be a way to loop through the definitionExpression ids without having to manually specify? I have tried to console log SeismicData , but for some reason I am not finding a collection of ids but only one.. I would like to loop through and store these ids in variables as I will later add a time range parameter... const SeismicData = new FeatureLayer({ title: "MMI - Shake Intensity", url: "https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/USGS_Seismic_Data_v1/FeatureServer/1/", outFields: ["id","mag","eventTime","url"], popupTemplate: popupUSGS }); SeismicData.definitionExpression = "grid_value > 2", SeismicData.definitionExpression = "id = 'us70008jr5'", <------------ i.e. here map.add(SeismicData);
... View more
06-10-2020
03:19 PM
|
0
|
6
|
2069
|
|
POST
|
My goal is to be able to toggle shake intensities on / or off (display or hide) individually via either an ID or name ... I see options of id and object id available in the data field options in the rest doc.. however, I am unsure how to implement... In my below codepen, you can see I am doing a rest call and returning all the shake map data at once... I am trying to return them one at a time per earthquake name or ID... so, I can filter them later "on" or "off"... CodePen.. Full Code: <html><head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> <title>ArcGIS JavaScript Tutorials: Add layers to a map</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> <link rel="stylesheet" href="https://js.arcgis.com/4.15/esri/themes/light/main.css"> <script src="https://js.arcgis.com/4.15/"></script> <script> require([ "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/widgets/Legend" ], function(Map, MapView, FeatureLayer, Legend) { var map = new Map({ basemap: "gray" }); var view = new MapView({ container: "viewDiv", map: map, center: [-122, 37], zoom: 5 }); view.ui.add( new Legend({ view: view }), "bottom-left" ); // Define a popup for USGS_Seismic_Data_v1 var popupUSGS = { title: "Shake Intensity", content: [ { type: "fields", fieldInfos: [ { fieldName: "grid_value", label: "Grid Value" }, { fieldName: "mag", label: "Magnitude" }, { fieldName: "eventTime", label: "Event Time", format: { dateFormat: "short-date-short-time" } }, { fieldName: "updated", label: "Updated", format: { dateFormat: "short-date-short-time" } }, { fieldName: "url", label: "Url" } ] } ] } // USGS_Seismic_Data_v1 feature layer (polygons) var SeismicData = new FeatureLayer({ title: "MMI - Shake Intensity", url: "https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/USGS_Seismic_Data_v1/FeatureServer/1/", outFields: ["mag","eventTime","url"], popupTemplate: popupUSGS }); map.add(SeismicData); }); </script></head><body> <div id="viewDiv"></div></body></html>
... View more
06-10-2020
07:19 AM
|
0
|
8
|
2268
|
|
POST
|
Revised attempt at my previous question: I am successfully adding a class to my graphic layer.... previously I was using an ID.. I console.log(myNewGraphicLayer) and it's found, the added class below: vvv attributionDataUrl: (...) attributionVisible: (...) className: "someThing" <----------------------------------- elevationInfo: (...) fullExtent: (...) graphics: (...) hasAttributionData: (...) id: (...) legendEnabled: (...) listMode: (...) load: ƒ (e) loadError: (...) I added it this way: vvvv let graphicsLayer = new GraphicsLayer({ //id: "someThing", <------- works, but I am adding many need to use class className: "someThing" }); I am perplexed, because this will work when ID is added... const polyDrawline = map.findLayerById('someThing'); but this will not work when className is added... const polyDrawlineS = map.findLayerByClassName('someThing'); how do I access my className?
... View more
04-30-2020
09:30 AM
|
0
|
1
|
1079
|
|
POST
|
Yes, I just used short hand variables. It is a draggable div element directly over the full screened map. const view = myAPP.mapview;
... View more
04-20-2020
09:41 AM
|
0
|
1
|
853
|
|
POST
|
Thanks for looking. Below is my 4.x attempt.. It is returning 'point.getLatitude()....' is not a function. let ktop = $('elem1').offset().top; let ktlft = $('elem2').offset().left; let point = view.toMap(ktop,ktlft); console.log("Lat: " + point.getLatitude() + ", Lon: " + point.getLongitude());
... View more
04-20-2020
09:37 AM
|
0
|
3
|
853
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 04-17-2020 03:59 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|