Select to view content in your preferred language

Querying one feature layer to use to query another layer (problem grabbing result of first layer)

2264
12
Jump to solution
07-06-2021 01:36 PM
Jackson_CountyMissouri
New Contributor III

I have a web map with a search widget. I have two different layers I use for the search widget - an address points layer and a parcels layer. The user will pull down the search widget to select searching either an address from the address points layer, or a parcel number from the parcels layer. However, all parcels need to be selected/highlighted with the parcel number because it is that parcel that needs to be highlighted/selected, and not the address point. So I need to "convert" the addresses from the address points layer to its corresponding parcel number. The parcels layer has an incomplete set of addresses, so I can't use that layer for address-searching.

This is OK because the address points layer also has the parcel number, but in the search widget I only want to show the address. So I can't "directly" grab the parcel number from the address points layer in the search widget, and instead need to get its parcel number via a query on that address point layer. I then need to do another query of the parcels layer to highlight the parcel with the parcel number gotten from the address points layer.

My problem is that I'm having a hard time figuring out how to grab the results of the first (address points) layer query in order to do the 2nd query on the parcels layer. Here is what I have. The following function is called from my search widget handler:

 

	function selectParcel()
	{
        // portion to query address points layer to get parcel # from address points
		var ptsQuery = addressPtsLayerSearch.createQuery();
        var parcelnum;
		ptsQuery.where = "FULLADDR = '" + searchWidget.searchTerm + "'";
		ptsQuery.outFields = ["PARCELNUM"];
		addressPtsLayerSearch.queryFeatures(ptsQuery).then(function(response)
		{
			var feat = response.features[0].attributes;
			parcelnum = feat;
		});

        // portion to select/highlight parcels layer
		var parcelsQuery = parcelsLayer.createQuery();
		parcelsQuery.where = "Name = '" + parcelnum + "'";
		parcelsLayer.queryFeatures(parcelsQuery).then(function(response)
		{
			theView.whenLayerView(parcelsLayer).then(function(layerView)
			{
				var feature = response.features[0];
				layerView.highlight(feature.attributes["OBJECTID"]);
			});

		});
	}

 

The ptsQuery.where works fine - it correctly grabs the address.

PARCELNUM is the name of the field in the address points layer that contains the parcel #.

addressPtsLayerSearch is the name of the address points layer used in the search widget.

My problem is that I've been unable to grab the PARCELNUM from the first query. I've tried every iteration I could find online for the correct syntax to grab the result of my first query, but nothing has worked. The version I'm showing above looks like the most "correct" version according to the ESRI API for FeatureLayer.queryFeatures(), but it still doesn't work. I've also tried the new esri/rest/support/Query library (which is basically the same thing, it looks like) but it doesn't work. (that is, I do: var ptsQuery = new Query() ).

 I also know that the parcelsQuery.where part works below that because if I hard-code a parcel number in place of the parcelnum variable, it correctly highlights the parcel. So I just need to grab the result of the first query correctly.

0 Kudos
12 Replies
Jackson_CountyMissouri
New Contributor III

Absolutely that ptsQuery.where works correctly.

0 Kudos
KenBuja
MVP Esteemed Contributor

If it's working perfectly, it should return results in the query. That's why I suggest you use the query page of the service to make sure it returns a result.

Here's an example: https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2/query?where=STATE_NAM...

0 Kudos
Jackson_CountyMissouri
New Contributor III

Actually, I take that back. I need to strip out the city and zip from my search term! Unfortunately that creates other problems, since I want the city and zip i the search term.

0 Kudos