Skip to content
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

Query bounds Mapserver #879

Closed
mepdr opened this issue Nov 2, 2016 · 14 comments · Fixed by #885
Closed

Query bounds Mapserver #879

mepdr opened this issue Nov 2, 2016 · 14 comments · Fixed by #885

Comments

@mepdr
Copy link

mepdr commented Nov 2, 2016

Quering a Mapserver layer service for bounds like:

query.where("1=2").bounds(function(error, latLngBounds, response){
    map.fitBounds(latLngBounds);
});

I got

Uncaught Error: Invalid LatLng object: (NaN, NaN)(…)L.LatLng 
@ LatLng.js:24L.latLng 
@ LatLng.js:128T 
@ Util.js:32(anonymous function) 
@ Query.js:139(anonymous function) 
@ Service.js:96s.onreadystatechange 
@ Request.js:75

The server response is: {"extent":{"xmin":"NaN","ymin":"NaN","xmax":"NaN","ymax":"NaN"}}
The same against a featureServer, (i,e, https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/stops/FeatureServer/0/query?returnGeometry=true&where=1=2&outSr=4326&outFields=*&returnExtentOnly=true&f=json) returns
{"extent":null}

Running arcgis 10.4
Live example http://jsbin.com/tatadejiya/1/edit?html,console,output

@rowanwins
Copy link
Contributor

Hi @mepdr

Why would you run a query where("1=2") , it seems to me that that would never return any features? If you'd like to return all features you should adjust your query to where("1=1").

You can see that that returns a legitimate result
https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/stops/FeatureServer/0/query?returnGeometry=true&where=1=1&outSr=4326&outFields=*&returnExtentOnly=true&f=json

Does that help?

@mepdr
Copy link
Author

mepdr commented Nov 3, 2016

@rowanwins "1=2" is just an example for common situations in which the where clause doesn't return any feature. Beside the where clause used, .bounds() should not fail

@rowanwins
Copy link
Contributor

Hi @mepdr

From what I can see from your description I would say this is expected behaviour, how could you have a valid latLngBounds if you aren't returning any features?

If it we're me I'd probably be doing something like

query.where("1=2").bounds(function(error, latLngBounds, response){
    if (error) {
         return;
     }
    map.fitBounds(latLngBounds);
});

It might help to see a jsfiddle

@mepdr
Copy link
Author

mepdr commented Nov 3, 2016

Unfortunately the issue is exactly that .bound() fails without calling the function. As a result, any code you place in the function to handle the error is not executed at all.
I'd create a jsfiddle but I haven't got any public service available. The one I founds exposing a Mapserver service doesn't support query.

@rowanwins
Copy link
Contributor

@mepdr
Copy link
Author

mepdr commented Nov 3, 2016

@rowanwins
Copy link
Contributor

http://jsbin.com/jevonemuju/1/edit?html,console,output

I've adjusted your snippet and move the setWhere() to before the query method and it now works

@mepdr
Copy link
Author

mepdr commented Nov 3, 2016

@rowanwins .query() doesn't work in that way. In your example .bounds() returns the bounds containing all features, which is not the requested behavior because the where clause is not considered at all.
If you replace .bounds() with .ids() you'll get all features, see http://jsbin.com/liqufekeva/1/edit?html,console,output

@rowanwins
Copy link
Contributor

ah I'm finally with you sorry @mepdr

So it looks like we just need to add an extra check here to make sure that response.extent is actually checked a bit more thoroughly

@jgravois
Copy link
Contributor

jgravois commented Nov 9, 2016

@mepdr what behavior would you prefer to see?

  • an error in the callback?
  • a valid bounds object? ex: L.latLngBounds([0,0],[0,0])?

the codebase is open source and @rowanwins has pinpointed the correct location to pin a fix, so it doesn't need to be me doing the patching.

@mepdr
Copy link
Author

mepdr commented Nov 10, 2016

IMHO the behavior should be the same there is for a featureServer service.

@jgravois
Copy link
Contributor

makes sense to me.

turns out this isn't a MapServer vs. FeatureServer thing. its a hosted feature service query vs. ArcGIS Server feature service query thing.

https://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Building_Footprints_pdx/FeatureServer/0/query?where=1=2&returnExtentOnly=true&f=json

{"extent":null}

http://sampleserver6.arcgisonline.com/arcgis/rest/services/CommercialDamageAssessment/FeatureServer/0/query?where=1=2&returnExtentOnly=true&f=json

{"extent":{"xmin":"NaN","ymin":"NaN","xmax":"NaN","ymax":"NaN"}}

i've proposed a patch in #885 and asked our devs to consider making sure the ArcGIS Server response matches the hosted feature service response in the future.

thanks for the report.

@rowanwins
Copy link
Contributor

Nice work @jgravois finding that difference between the AGO and the ArcGIS Server responses, nice little quirk that had the potential to cause a few headaches!

@jgravois
Copy link
Contributor

going forward we will pass both the null LatLngBounds and an error indicating that the geometry is invalid, no matter which form of the geometry we encounter in the service itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants