OpenStreetBugs layer

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — OpenStreetBugs layer
Afrikaans Alemannisch aragonés asturianu azərbaycanca Bahasa Indonesia Bahasa Melayu Bân-lâm-gú Basa Jawa Baso Minangkabau bosanski brezhoneg català čeština dansk Deutsch eesti English español Esperanto estremeñu euskara français Frysk Gaeilge Gàidhlig galego Hausa hrvatski Igbo interlingua Interlingue isiXhosa isiZulu íslenska italiano Kiswahili Kreyòl ayisyen kréyòl gwadloupéyen Kurdî latviešu Lëtzebuergesch lietuvių magyar Malagasy Malti Nederlands Nedersaksies norsk bokmål norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português português do Brasil română shqip slovenčina slovenščina Soomaaliga suomi svenska Tiếng Việt Türkçe Vahcuengh vèneto Wolof Yorùbá Zazaki српски / srpski беларуская български қазақша македонски монгол русский тоҷикӣ українська Ελληνικά Հայերեն ქართული नेपाली मराठी हिन्दी অসমীয়া বাংলা ਪੰਜਾਬੀ ગુજરાતી ଓଡ଼ିଆ தமிழ் తెలుగు ಕನ್ನಡ മലയാളം සිංහල ไทย မြန်မာဘာသာ ລາວ ភាសាខ្មែរ ⵜⴰⵎⴰⵣⵉⵖⵜ አማርኛ 한국어 日本語 中文(简体)‎ 吴语 粵語 中文(繁體)‎ ייִדיש עברית اردو العربية پښتو سنڌي فارسی ދިވެހިބަސް

The OpenStreetBugs layer is a new version of the old JavaScript client that embeds OpenStreetBugs into an OpenLayers map. It has the following advantages over the old client:

  • It extends the OpenLayers.Layer.Markers class, so it is embeddable into an OpenLayers map using a simple addLayer() call. Other OpenLayers functionalities can thus be easily used and the class can be extended. The old client used a whole bunch of global functions that called each other, the adding of a layer to the map was done somewhere in the code, not using object-orientated programming.
  • It is addable to multiple maps on one page. Although the OpenStreetBugs API is not designed for this and calls one global JavaScript function for each bug, the new OpenStreetBugs layer distributes the data from this global function to all existing OpenStreetBugs layers.
  • It can be put into read-only mode. Then users cannot submit comments, open new bugs or close bugs. This might be useful for maps that only want to display map data and want to complete that data by giving information about what’s wrong with it (by displaying OpenStreetBugs).

The source code is available under AGPL 3 or higher ([1]).

The JavaScript API

The path of the required JavaScript file is If you want to include OpenStreetBugs into your map, include this file using the following code in your HTML <head> part:

<script type="text/javascript" src=""></script>

The OpenStreetBugs layer provides two main classes that will be described in the following.


The OpenLayers.Layer.OpenStreetBugs class is added as a Layer to an OpenLayers map, contacts the OpenStreetBugs API and displays the existing bugs on the map providing the funcionality to comment and to close them. For adding comments, see the Control class below.

To add the layer to your map, use the following code.

var osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs");
map.addLayer(osbLayer); // map is your instance of OpenLayers.Map

The “OpenStreetBugs” in the quotation marks is the title of your layer that will be displayed in the LayerSwitcher. If you want, you can pass some options to the OpenStreetBugs layer in order to customise its behaviour:

var osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
  serverURL : "", // Specify the OpenStreetBugs API server
  iconOpen : new OpenLayers.Icon("", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)), // Specify the icon to use for open bugs [1]
  iconClosed : new OpenLayers.Icon("", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)), // Specify the icon to use for closed bugs [1]
  readonly : true, // Set the layer to “readonly” mode (no adding, commenting, closing)
  setCookie : false, // Don’t save the OpenStreetBugs username in a cookie
  cookieLifetime : 1000, // Specify the lifetime of the username cookies in days
  cookiePath : "/my/map/", // Specify the path on your server where the cookie shall be available,
  permalinkURL : "" // Link to a slippy map, Permalinks to bugs will be created with this URL

[1] To specify an icon you need to pass the icon size and the coordinates of the icon’s centre. See the documentation on [2].


The OpenLayers.Control.OpenStreetBugs class provides your map with the functionality to add a bug where you click on the map.

To add it to your map, use the following code:

var osbControl = new OpenLayers.Control.OpenStreetBugs(osbLayer); // osbLayer is an instance of OpenLayers.Layer.OpenStreetBugs, see above
map.addControl(osbControl); // map is your instance of OpenLayers.Map

These options are available to customise the behaviour of the Control:

var osbControl = new OpenLayers.Control.OpenStreetBugs(osbLayer, {
  icon : new OpenLayers.Icon("", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)) // This icon [1] will be displayed temporarily on the map when you add a bug and will be connected to the “create bug” popup

[1] To specify an icon you need to pass the icon size and the coordinates of the icon’s centre. See the documentation on [3].

Please note that by activating the Control, the Layer will be shown automatically. The first reason for this is that else there wouldn’t be a marker on the map that the “Create bug” formular would be connected to. The second reason is that you would not add a bug somewhere before looking if a bug reporting the same thing is already present.

If you are using an OpenLayers.Control.Panel ([4]) providing your user with several map tools (like FacilMap does for example, see the toolbox on the top right), you can add the OpenStreetBugs control to it:

var osbControl = new OpenLayers.Control.OpenStreetBugs(osbLayer);
toolbar.addControls(osbControl); // toolbar is your instance of OpenLayers.Control.Panel

Example map

An example map using the layer is available on


The source code is hosted on GitHub. Bugs are managed on


Feel free to add your language to /Translation.

If you want proper internationalisation in OpenLayers, call the static JavaScript function OpenLayers.Lang.setCode(String) manually with a language code from the user’s Accept-Language header, as there is no way in JavaScript to detect the user’s preferred language (only their browser language). OpenLayers does not support a language priority list, OpenLayers.Lang.getCode() is set to the value of OpenLayers.Lang.defaultCode when no translation is available for the code passed to OpenLayers.Lang.setCode(String). If you want to build your own priority list based on Accept-Language, be aware of the fact that the existance of an OpenLayers translation does not indicate its completeness, a Romanian translation for example is only available for OpenStreetBugs, not for OpenLayers (nevertheless exists), it might be the other way round for other languages.