Esri / offline-editor-js

ArcGIS JavaScript library for handling offline editing and tiling.
http://esri.github.io/offline-editor-js/demo/
Apache License 2.0
159 stars 142 forks source link

mode_selection with offline functionality #166

Closed jrgittyup closed 10 years ago

jrgittyup commented 10 years ago

Hello. Is there a dependency with the offline sdk requiring you to use MODE_SNAPSHOT for feature services? I can get my app to work offline with mode_snapshot but with a feature service that has a lot of points, it takes quite a long time to load. Sometimes the browser times out. If I set it to MODE_SELECTION, implement an attribute inspector, whenever I go offline (including disconnecting network cable), it fails to make the update when editing any features. Looking at the console it appears to still be attempting to try to reach my feature service. I am combining the provided military-offline.html and tiles-indexed-db.html in an attempt to make offline map work with zooming/panning and editing a feature service. I wonder... 1) Is there a way to limit the extent at which MODE_SNAPSHOT queries for, in order to make performance reasonable? or 2) Can MODE_SELECTION be used with a feature service and work? I have found varying results between clicking the "Go Offline" button and actually unplugging my network connection, so I need it to work when there truly is no network signal.

I created an incident and worked with ESRI support but she feels that she has tried all that she can to make mode_selection work and at this point suggested I submit an issue on Github.

Thanks.

andygup commented 10 years ago

Is there a dependency with the offline sdk requiring you to use MODE_SNAPSHOT for feature services? Is there a way to limit the extent at which MODE_SNAPSHOT queries for, in order to make performance reasonable?

Have you tried using MODE_ONDEMAND? That mode will use the map's spatial extent automatically in the Query and it will only pull down only the points that are contained within the extent.

MODE_SELECTION is typically used for a different use case where features are retrieved one-at-a-time from the server as they are individually selected by a user. For example, if someone clicks on a graphic then MODE_SELECTION can be used to retrieve the attributes for only that specific graphic. By using something like MODE_ONDEMAND you can pull down all points within a certain extent and have all the points locally in the app ready for editing.

Note, you can also control how much data is retrieved for each feature by setting the outFields property. Depending on how many attributes each feature has, tweaking this setting can greatly reduce the response size. Example:

            var layer = new FeatureLayer("someURL", {
                mode: FeatureLayer.MODE_ONDEMAND,
                outFields: ['lat','lon','name','description']
            });

Last, you didn't mention what type of geometries you are using. If you are using lines or polygons make sure they are generalized. Very dense geometries can greatly increase the time it takes for features to download. Here is a good write up with additional information on that topic: https://developers.arcgis.com/javascript/jshelp/best_practices_feature_layers.html

jabadia commented 10 years ago

Hi,

The problem with MODE_ONDEMAND is that it tries to access the network every time you change the extent of the map. If you want to work offline it is best to stick to MODE_SNAPSHOT.

Is it possible to limit the extent of MODE_SNAPSHOT queries? Unfortunately not. However, you can set definitionExpressions and the queries will respect them... so, if your features have some kind of region identifier you could use this attribute to filter only the features you are interested in.

If you want to edit attributes and geometries, then I don't think Andy's suggestions can help, because you will probably want all attributes (or at least all attributes that the user will want to edit) and the full detail of the geometry.

It is possible -although not advisable- to patch the way the queries are made in Snapshot Mode. You can patch the _sendRequest() method as I have done in this code snippet. This code should be inserted in the military-offline.html sample. It shows how you can set a "restrictedExtent" attribute in the layer, and then patch the layer._mode object to use this extent when sending the layer queries. Beware that patching the ArcGIS JS API code in this way has a high probability of breaking in the future.

If you can, I would use attribute definitionExpressions in the layer to limit the scope of the query.

Hope it helps

jabadia commented 10 years ago

I forgot to comment on this:

"I am combining the provided military-offline.html and tiles-indexed-db.html in an attempt to make offline map work with zooming/panning and editing a feature service."

Notice that the tiles that you cache in one application are available for any other application that comes from the same internet domain. The military-offline.html example already takes advantage of this, so that if you go to the tiles-indexed-db.html sample and download the tiles of the World Imagery service in the area of the military features, and then you go to the military-offline sample and go offline, the tiles will already be there.

You can use the tiles-indexed-db.html sample as a tile cache manager for other applications in the same domain.

jrgittyup commented 10 years ago

Thanks for the comments. To answer some of the follow up questions... -Yes I originally tried MODE_ONDEMAND. As jabadia mentioned, it always appeared to access the network every time the extent of the map was changed. This happened even if I had set the offlineFeaturesManager to offline. So that wasn't an option. At first I did not realize it was doing this in the background, until I physically unplugged the network cable from my computer. -This particular feature service only contains points across the US. I do not know what attributes the clients will want to be able to edit. Probably most.

Using a definitionExpression with MODE_SNAPSHOT seems to work. This particular layer that I am testing with has a region indicator in the attributes, so that is good. Thank you for that recommendation. Other feature services we use may not be so lucky. We will have to deal with those I suppose as we encounter them and know this is a limitation. I might experiment with the restrictedExtent but I am quite hesitant, due to it possibly breaking something else.

After all this troubleshooting, and learning a few things, these would be my enhancement requests to put on what I am sure is a long list, as you evolve this set of libraries. Thanks again for the replies. 1) When using MODE_ONDEMAND and the user extends a feature service with the offline libraries, and when the application is set to offline mode, prevent the application from attempting to access the network for that feature service and have it find the features solely out of what has been downloaded. Going back online would resume normal MODE_ONDEMAND functionality. 2) Add some sort of property that can be set to define/limit the extent downloaded when using MODE_SNAPSHOT.

jabadia commented 10 years ago

Happy to hear it works. Thanks for your suggestions!

2014-04-28 15:50 GMT+02:00 jrgittyup notifications@github.com:

Thanks for the comments. To answer some of the follow up questions... -Yes I originally tried MODE_ONDEMAND. As jabadia mentioned, it always appeared to access the network every time the extent of the map was changed. This happened even if I had set the offlineFeaturesManager to offline. So that wasn't an option. At first I did not realize it was doing this in the background, until I physically unplugged the network cable from my computer. -This particular feature service only contains points across the US. I do not know what attributes the clients will want to be able to edit. Probably most.

Using a definitionExpression with MODE_SNAPSHOT seems to work. This particular layer that I am testing with has a region indicator in the attributes, so that is good. Thank you for that recommendation. Other feature services we use may not be so lucky. We will have to deal with those I suppose as we encounter them and know this is a limitation. I might experiment with the restrictedExtent but I am quite hesitant, due to it possibly breaking something else.

After all this troubleshooting, and learning a few things, these would be my enhancement requests to put on what I am sure is a long list, as you evolve this set of libraries. Thanks again for the replies. 1) When using MODE_ONDEMAND and the user extends a feature service with the offline libraries, and when the application is set to offline mode, prevent the application from attempting to access the network for that feature service and have it find the features solely out of what has been downloaded. Going back online would resume normal MODE_ONDEMAND functionality. 2) Add some sort of property that can be set to define/limit the extent downloaded when using MODE_SNAPSHOT.

— Reply to this email directly or view it on GitHubhttps://github.com/Esri/offline-editor-js/issues/166#issuecomment-41559960 .

Javier Abadía