Overview Examples Documentation Download

geoJson

Extends layer, dispatch.
url

po.geoJson([f])

Constructs a new GeoJSON layer with default settings.

An optional fetch function f may be specified, which defaults to po.queue.json. The fetch function takes two arguments: the URL to fetch as a string, and a callback function. The fetch function must return a request object with an abort method. The callback function should be invoked with the GeoJSON data when available.

The fetch function may be substituted to support GeoJSON transcoding. For example, a KML layer might be implemented by loading XML, and then converting it into a simplified GeoJSON representation.

geoJson.url([x])

Sets or gets the URL template associated with this GeoJSON layer. If the argument x is specified, this method sets the URL template and returns this. If no arguments are specified, this method returns the current URL template. The default URL template is “about:blank”.

The URL template may be specified either as a string or as a function:

If a string, and the string contains placeholders of the form “{A}”, where A is any character, then the string is converted into a URL template function using po.url. If the string does not contain placeholders, then it is left as a string, and tiling and clipping are disabled.

If a function, then the given function is invoked, passing in the tile coordinate of the GeoJSON file to load. The tile coordinate is represented as an object with row, column and zoom attributes. The function must return a string representing the URL to load. See po.url for an example implementation.

Note that if the GeoJSON file is not on the same domain, the server must specify a suitable Access-Control-Allow-Origin header for the data to be accessible.

geoJson.features([x])

Sets or gets the “hard-coded” features for this GeoJSON layer. If the argument x is specified, this method sets the features to the given array of GeoJSON feature objects and returns this. If no arguments are specified, this method returns the current features array, which defaults to null.

The purpose of this method is to support non-tiled GeoJSON layers that are loaded through external means, such as via JSONP or directly embedded in the HTML. Specifying the features array has the additional side-effect of disabling tiling and clipping.

geoJson.clip([x])

Sets or gets whether tiles are clipped. If the boolean argument x is specified, the method enables or disables clipping accordingly, and returns this. If no arguments are specified, the method returns true if and only if tiles are clipped.

Tiles are clipped by default. Disabling clipping is useful for GeoJSON features that may extend beyond the tile boundary, such as points.

Events

GeoJSON layers use the dispatch mechanism to notify interested parties of events. In addition to the standard load event, GeoJSON layers support the “show” event that is triggered for each tile as it becomes visible. The show event allows tiles to be styled dynamically through JavaScript. The stylist convenience class may be used to simplify implementation of load and show event handlers.

geoJson.reshow()
Dispatches a show event for each visible tile. If tiles are styled dynamically through a show event listener, this allows styling to be re-evaluated for all visible tiles.
Polymaps is a project from SimpleGeo and Stamen.