Difference between revisions of "UCamGeoJSON"

From University Map Wiki
Jump to navigationJump to search
Line 165: Line 165:
  
 
==Adapters==
 
==Adapters==
 +
 +
TBA
  
 
==URL referencing considerations==
 
==URL referencing considerations==

Revision as of 15:26, 13 December 2012

This is work in progress. Do not rely on this document just yet.
We expect to finalize this by the end of January 2013.

Introduction

In early 2013 we will be introducing a facility to annotate the University Map with your own information. Typically this will be done using a user interface, but for those who want to derive overlays programmatically from existing data or otherwise roll their own, this describes how.

GeoJSON

Overlays are specified using UCamGeoJSON, a file format based on GeoJSON (see specification). UcamGeoJSON differs in three respects from GeoJSON:

  • GeoJSON only provides geometry. UCamGeoJSON defines the recognized content of the properties element of Feature objects, used to define what the shapes are for: things like colour of shapes, what text and icons are to appear at points, and so on.
  • Additional members of the top level JSON object z, pos and expand can be given, to set the initial view of the map (how far it is zoomed in, where it is centred, and whether it fills the browser window respectively). See Initial map view below.

Using UCamGeoJSON

The map is told to overlay custom annotation by giving it some UCamGeoJSON data in the URL. This is done in the fragment part of the URL (that is, the bit after a '#'), like this:

 http://map.cam.ac.uk/...#data

One can still include other parts of the URL as normal, for example to search for a particular institution. The whole of such URLs can be shortened using any shortening service, such as [bit.ly].

The data can be included in one of three ways:

  • Directly including UCamGeoJSON in the URL. This is only appropriate for small amounts, as length of URLs that browsers and other software can handle is limited. In practice, restrict the total length of URLs to under 2,000 characters. In this case the first character after the hash will always be '{'. In general, do not (percent) escape this part of the URL: see escaping.
  • Referencing the UCamGeoJSON via a URL. The content provided by the URL is the UCamGeoJSON data, and the response to the request will use content-type 'application/json'. The URL will usually be absolute, that is start with 'http://', but in a few cases it may be relative to the map itself, and therefore start with a '/' (see especially Adapters below). For example:
 http://map.cam.ac.uk/#http://www.example.com/my-ucamgeojson.json
 http://map.cam.ac.uk/#/annotate/adapters/osm.json?src=http://www.example.com/my-osmfile.osm

Do escape these embedded URLs properly, but don't double escape them.

  • Giving one, two or three numbers after the '#'. These are abbreviations for default zoom level, default map centre, or both, respectively (see below), thus:
 http://map.cam.ac.uk/#z
 http://map.cam.ac.uk/#lat,lon
 http://map.cam.ac.uk/#lat,lon,z

These are exactly equivalent to the following (respectively):

 http://map.cam.ac.uk/#{"z":z}
 http://map.cam.ac.uk/#{"pos":{"type":"Point","coordinates":[lat,lon]}}
 http://map.cam.ac.uk/#{"pos":{"type":"Point","coordinates":[lat,lon]},"z":z}

escaping

Normally, unusual characters in URLs are "percent escaped". However, whatever the right or wrong answer with the fragment part, in practice every browser handles this differently, and they also behave differently between pasting or typing a link into the address bar and following a link in a web page. Furthermore most pattern recognition for URLs will stop when they see a '{' in the fragment, so in emails, for example, verbatim JOSM will probably not link correctly (but you could do this via a bit.ly link).

The most reliable answer is

  • Don't escape the hash part at all.
  • Do escape URLs within the hash part as normal (but don't double escape them).

When you quote or follow such a link, some browsers escape some, but not all, unusual characters - but then present them to the code without un-escaping them; others un-escape some escaped characters! For this reason, in order to get consistent results, the map will treat %NN where N is a digit as a sequence to be un-escaped, but otherwise treat % as a true percent sign, except within URLs.

Initial map view

The top level GeoJSON object may additionally contain the members z, pos and expand to control the initial map view. Indeed, any or all of these may be the entire content of the object if all you want to do is override the default view the determined by the map automatically.

  • z is the initial zoom level. For the University Map, the lowest zoom level (smallest scale, most zoomed out, when the scale on the map shows "2km") is 13 and the highest (largest scale, most zoomed in, when the scale shows "25m") is 19.
  • pos is the point on which the map is initial centred. The value of pos is a GeoJSON Point object, that is it provides a latitude and lobngitude on which the map is to be centred.
  • expand is a boolean value which (except for mobile devices with small screens) can be used to display the map with (false) the border content like the search box and search results list, or without (true) to fill the whole window.

For example:

 { "pos": {"type":"Point", "coordinates":[52.2036,0.1202]},
   "z": 19,
   "type": "FeatureCollection",
   "features": [...] }

Properties

The content of the properties member of the GoeJSON Feature object is not defined by GeoJSON other than as a set of key/value pairs. The intention is that these specify the appearance of the objects specified by the GeoJSON geometry.

UCamGeoJSON does define properties, as follows. In general the properties are a subset of CSS, so the detailed formats of each need not be defined here, only any special interpretation of them. Refer to CSS for the details.

In broad terms, the geometry provides filled areas, lines and points.

Areas and lines are drawn by applying a few styling properties, such as color (note US spelling, as in CSS).

Points are represented by icons (images) and/or text drawn at the position indicated according to the style indicated by the properties. You can have both an icon and text at a single point. These are grouped into an HTML div, which allows for flexible and controllable using CSS.

property name filled shaped lines text and icons notes
color colour with which the shape is filled colour in which the line is drawn colour of the text, if any any CSS colour specification is allowed, e.g. a name like 'green', hash and six hex digits, or 'rgb(...)' etc.
border, border-color, border-width the border styling

Adapters

TBA

URL referencing considerations

Login protected sources

TBA

Cross-site scripting

TBA