1

I am using GeoServer, GeoExt, PostGIS, etc (all the standard stuff).

I have a map displayed in my browser and performing a box select adds relevant items to my selection vector layer. In addition to this a popup box appears with a summary of selected items and against each layer summary is a hyperlink which when clicked causes a server round trip (this round trip is necessary as it displays the main detail of each selected item). The server round trip results in the map being re-displayed but now my selected items are no longer selected.

Can I maintain the list of selected items and keep them highlighted after the map re-draw?

I could probably cobble something together using cookies but was wondering if there is an easier solution!

2 Answers 2

3

Use HTML5 Web Storage, it is perfect for this purpose.

Web Storage is a method of storing data to a permanent store in the browser and does away with any need for Cookies.

There are two types of Storage

localStorage - stores data with no expiration date
sessionStorage - stores data for one session

This means that you could actually store you list across browser sessions if you wanted to by using the localStorage, or just for that web Session.

It is as easy as setting variables in JScript:

localStorage.mylist_1="ListContent"

then to retrieve use

var a = localStorage.mylist_1

Some excellent information and examples can be seen Here!

4
  • Thanks Marc, this is probably the easiest solution but if I use HTML5 am I not then limited to browsers that's support HTML5...
    – ScottFree
    Commented Nov 18, 2013 at 15:01
  • Correct, All the main browsers do. I have not run into any issues, however if you are on a corporate site you may run into issues if they still use older browsers. Most users browsers tend to update automatically anyway. Commented Nov 18, 2013 at 15:41
  • Thanks, my first bit of html5 in the bag, a nice solution so long as the support is out there - not expecing it to work on IE - sheesh it worked great!!! Thanks
    – ScottFree
    Commented Nov 20, 2013 at 10:02
  • 1
    Yes, we are doing all our stuff in HTML5 now, lots of cool features and not THAT different from earlier versions. Bye Bye Cookies is all I can say ... We use the localStorage to persist all the user preferences, then have a worker process that is triggered on a change and it iterates through the stored items and uploads to the users account on the server. We also use it to Cache tiles locally, but there are space limitations, so the usefulness of that caching concept is still debatable. Commented Nov 20, 2013 at 11:05
0

To complete Mark C answer and to give you an alternative to HTML5 option, I would say you can just use global javascript var to store your selected values.

It's not clear whether you currently refresh the full webpage or just the map. Anyway, just the map has to be refreshed. So you could just refresh the map container div using ajax and transmit your selected values with the ajax request using data options (from ajax jQuery method).

Here, you will find a small example on how to update the container : http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_ajax

And here, an example on how data options works.

2
  • Hi, "a server round trip" indicates a full refresh of the webpage, also with me using GeoEXT which is based on ExtJS the jQuery tutorial is not relevant either. Thanks for your reply tho appreciated!
    – ScottFree
    Commented Nov 20, 2013 at 10:26
  • Ok, sorry I did not see the geoExt tag! By the way, the same logic could be applied doing it with extJS.
    – simo
    Commented Nov 20, 2013 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.