Class: PolygonsCountyCache

alk.source.PolygonsCountyCache

This class provides a request cache around the PolygonsCountyService. This object is used within the alk.source.WeatherAlertsSource implementation.

new alk.source.PolygonsCountyCache(opt_options)

This constructor creates a utility object for the Weather Alerts service which caches Polygons as they are common among weather alerts.

When a WeatherAlert becomes available, the source extracts its polygon. If the WeatherAlert.Polygon property is null, then the polygons are extracted from the WeatherAlert.FipsCodes property, which contains a space delimited list of 5 digit codes that name counties.

The following procedure is implemented.

   var pgc = cache.getPolygonForCountyCode(code);
   if (pgc == null) {
      cache.queueCountyCode(code, future);
   }
Where future is a function that will be called when the polygon for that code becomes available. And after processing all weather alerts, the source will call

        cache.processQueue();
The processQueue function will call send out requests to the PolygonsCountyService to retrieve the polygons and process them when they come in.

Option Type Description
polygonsCountyService alk.service.PolygonsCountyService | undefined

This option contains the service with which to get the polygons for county codes. If this option is undefined, then one is created with the polygonsCountyServiceOptions.

polygonsCountyServiceOptions alkx.PolygonsCountyServiceOptions | undefined

This option contains the options for creating the alk.service.PolygonsCountyService with which to get the polygons for county codes.

Methods

getPolygonForCountyCode(code){alkx.PolygonCounty|undefined}

This method returns a polygon response structure for the code. It may return undefined if there is none in the cache.

Name Type Description
code string

processQueue(complete)

This method makes requests to get polygons for the codes queued up since the last call to this method. Since there is a size limit on calls made to the server, this method may make more than one request to get all the codes. If there are no codes queued, then no request is made.

When each code receives a polygon structure, its associated future is called.

Name Type Description
complete function

Function is called to notify when all codes have been loaded.

queueCountyCode(code, future)

This method queues a county code to be requested when alk.source.PolygonsCountyCache#processQueue is called. This method is called after getPolygonForCountyCode returns null or undefined;

Name Type Description
code string

The FIPS code

future function

Function to be called when code is loaded.