As described in Section 4.4, ads are fetched from the servers based on their position within the tile array at each zoom level. The Lat49.AdHelper class provides high level access to ads based on geographic coordinates, automatically converting latitude/longitude/zoom level to tile indices prior to fetching the ad. This class also caches ads internally, so that multiple requests for the same ad are handled efficiently. As such, the publisher can request ads without needing to know any details about how they are laid out geographically.
Functions in class Lat49.AdHelper:
| Lat49.AdHelper(publisherID); | ||
The constructor for the Lat49.AdHelper class. publisherID is the publisher account ID, and will be used for keeping track of which site generated each ad serve and click-through. If the parameter is left empty, then the Idelix account ID will be used by default. | ||
| updateAdByLatLon(divId, lat, lon, zoomlevel); | ||
Updates the DIV with ID divID with the ad for the given location and zoom level. The geographic coordinates lat and lon are given in degrees. If the given zoom level doesn't offer ads, then an ad from a different zoom level will be returned (see Section 2.1 for more details). | ||
The following functions make it convenient to fetch ads for a map image if it is difficult to compute the zoom level or the latitude/longitude of points within the map. By defining the bounding geographic coordinates and the pixel size of an image, ads can then be fetched based on pixel coordinates within the image. Translation to lat/lon coordinates and computation of the zoom level is handled within the fetching method. It should be noted that currently only Mercator and unprojected map images are supported. Fortunately, most map image providers like Google Maps, Virtual Earth and Yahoo Maps produce Mercator maps.
Functions in class Lat49.AdHelper:
| setScreenSpace(width, height); | ||
Defines the size of the image. | ||
| setLatLonSpace(latmin, lonmin, latmax, lonmax, projection); | ||
Defines the geographic bounds and projection type of the map image. The coordinates must be given in degrees. Currently, projection should be either Lat49.projMercator or Lat49.projUnprojected. If nothing is passed for projection, then Lat49.projMercator is assumed. | ||
| updateAdByPixel(divId, x, y); | ||
Updates the DIV with ID divId with the appropriate ad for pixel location (x,y). | ||
If the lat-lon/screen spaces have been defined using the above methods, then the following method can be used to automatically cycle over available ads. This may be useful for those applications that don't really provide any events for selecting particular image locations.
Functions in class Lat49.AdHelper:
| cycleAdsForScreen(divId, interval); | ||
Updates the DIV with ID divID with a new ad every interval seconds. The ads are selected from the geographic region and zoom level defined using the setLatLonSpace and setScreenSpace methods. This method does not have to be called again if the geographic bounds are changed; the cycling will continue within the new bounds. Afterwards, the cycling can be stopped by calling this method again with a 0 or negative value for interval. The cycling also stops if the display DIV is removed from the DOM. | ||
The following methods will not generally be used by a publisher, but are described here for the sake of completeness.
Functions in class Lat49.AdHelper:
| updateAdByTile(divId, x, y, zoomlevel); | ||
Updates the DIV with ID divID with the ad for the given location and zoom level. x and y are the indices of the ad within the tile array. This method does not automatically choose another zoom level if no ads are being offered for the given one. Thus, the updateAdByLatLon() method should be used instead of this one. | ||
| setMaxCacheSize(max); | ||
Sets the maximum number of ads stored in the cache to max. The default is 100. | ||