mapmeld / iD

Developing GeoServices tool for OSM iD Editor
http://mapmeld.com/iD
ISC License
7 stars 1 forks source link

Improve error messages for import URL and GeoJSON-Response #68

Open tordans opened 6 years ago

tordans commented 6 years ago

I am still trying to use the importer with https://github.com/mapmeld/iD/issues/66.

ATM my problem is either the url format or the json format. Unfortunatelly the importer is not very helpful in understanding and solving the error.

Ideally, the importer would talk to me about:

URL

JSON

Testcases

Use properties or attributes?

The example URL from https://github.com/mapmeld/iD/issues/66#issuecomment-377297076 @jgravois uses a properties. The http://geoservices.github.io/ example, that was referenced before, uses attributes.

Other usability improvements

Use case: I input an url -> see an error message -> change the URL -> see the same error message. ATM it is not clear if the "second" error message is still the same as before or if the new URL still creates an (new) error.

jgravois commented 6 years ago

i agree. there is serious room for improvement in our current validation.

right now we:

  1. check to make sure the string that's entered is a url by making sure it includes http:// or https://. if not, we abort and display nothing.
  2. if its indeed a url, we check to see that it contains either /MapServer/ or /FeatureServer/ to make sure its a geoservice.

https://github.com/mapmeld/iD/blob/2656b4d3c9ff0187c729eb9a8aeaa494f2d61b56/modules/ui/map_data.js#L524

we aren't validating the feature JSON at all. To make things a little more complicated, the query operation of modern geoservices is capable of emitting native GeoJSON (which include properties), while older geoservices only emit Esri flavored feature JSON (which include attributes).

side by side comparison: https://gist.github.com/jgravois/eab035258f8157d54618

currently we first fetch only metadata from the service to see whether it supports asking for native GeoJSON. If it doesn't we ask for Esri/Geoservice feature JSON and convert it into GeoJSON for iD client-side.

https://github.com/mapmeld/iD/blob/2656b4d3c9ff0187c729eb9a8aeaa494f2d61b56/modules/ui/map_data.js#L393

what you're trying to do is just store valid GeoJSON in a flat file on a server. a bit of refactoring of our code would necessary to short circuit the series of API calls we currently make once we are convinced the user has supplied a geoservice url.

right now we: a) ask for metadata to determine whether or not support for f=geojson is present

http://maps.bouldercounty.org/arcgis/rest/services/PARCELS/BUILDINGS_STRUCTURE_FOOTPRINT/MapServer/0?f=json

b) first, fetch only a count of the features within the supplied bounding box

http://maps.bouldercounty.org/arcgis/rest/services/PARCELS/BUILDINGS_STRUCTURE_FOOTPRINT/MapServer/0/query?where=1=1&returnCountOnly=true&f=json&geometry={"xmin":-105.306621,"ymin":40.018343,"xmax":-105.269586,"ymax":40.028042,"spatialReference":{"wkid":4326}}&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&inSR=4326

c) then fetch a count of the total number of features stored behind the entire service

http://maps.bouldercounty.org/arcgis/rest/services/PARCELS/BUILDINGS_STRUCTURE_FOOTPRINT/MapServer/0/query?where=1%3D1&returnCountOnly=true&f=json

d) lastly, fetch only the features within the supplied bounding box (using f=json only if support for f=geojson isn't present).

http://maps.bouldercounty.org/arcgis/rest/services/PARCELS/BUILDINGS_STRUCTURE_FOOTPRINT/MapServer/0/query?&outSR=4326&f=json&maxAllowableOffset=0.000005&outFields=StructureID&geometry={"xmin":-105.306621,"ymin":40.018343,"xmax":-105.269586,"ymax":40.028042,"spatialReference":{"wkid":4326}}&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&inSR=4326