# refresh

return type | undefined
syntax | $( map or service selector ).geomap( "refresh" [ , Boolean force ] )

usage

    $("#map").geomap( "refresh" )

    $("#map").geomap( "refresh", true )

    $("#map .my-dynamic-service").geomap( "refresh", true )

This method refreshes one or more services and shapes in the map. Usually, changing geomap options or calling methods automatically refreshes the map appropriately. However, you can call this after you have added or removed shapes to geomap by passing false as the refresh argument to the append, remove, or empty methods. This method is also useful in the case of dynamic server data.

Without a service selector, all services on the map will be refreshed.

The force option will re-request images for tiles already in the map view. Keep in mind, though, that this does not guarantee you will get updated images. See the Dynamic Data section below for tips.

## Dynamic Data

There are three factors that can prevent jQuery Geo from getting a fresh image from a web server.

- if the user does not interact with the map and you do not call refresh, jQuery Geo will not request new images
- if the user does interact with the map, you call refresh with no arguments, or you call .geomap( "refresh", false ):
  - for tiled services: jQuery Geo will only request images for tiles that it does not already have
  - for shingeld services: a new image is always requested but the browser may supply a cached image
- if you call .geomap( "refresh", true ), jQuery Geo will:
  - for tiled services: request a new image for existing tiles but the web browser is free to supply a cached image instead of retriving one from the web server
  - for shinged services: this is also true; if the final image URL is the same as a previous image URL the browser may supply a cached image

A web browser will normally cache images that have already been loaded. On top of that, jQuery Geo will not, by default, request images for tiles that it has already placed. In the case of dynamic data, where you want to update what's on the map without requiring a pan or zoom or also update tiles that have already been placed, you have a couple options.

### use uncachable URLs

The first option is to use a function for the src property of your service object. In that function, return a different URL every time even if all of the properties of the view object are the same as a previous call. If we were to use jQuery's implementation of the cache option in $.ajax as inspiration, our src function could look similar to:

    src: function( view ) {
      return "my.dynamic.tile.service/" + view.zoom + "/" + view.tile.column + "/" + view.tile.row + ".png?_=" + $.now( );
    }

The _ input in the query string will be a different number on every request, regardless of the value of zoom, column, and row. Most services will ignore extraneous query string inputs and the web browser will not be able to cache the image.

### use the Cache-Control HTTP header

Another way to achieve the same result without modifying your image URLs is to use the HTTP header: Cache-Control. By returning this header with the no-cache value, you can tell the web browser to not cache the image. Then, when you call .geomap( "refresh", true ), the web browser will re-request images for tiles even if it has done so one already. This option is only possible if you have some control over the web server that supplies map images. How to add the header is specific to your web server and beyond the scope of these docs. It can usually be done in the web server's configuration file or in the web service itself where you generate the images.