Cartagen Wiki
Gss Usage (changes)

Showing changes from revision #86 to #87: Added | Removed | Changed

Background and Examples

GSS is valid JSON (http://www.json.org/), but follows the format of CSS as much as possible.

To see a fairly long GSS file, visit http://cartagen.org/static/rome/style.gss, or visit the Stylesheet Gallery

Here’s an example style from a GSS file:

footway: {
	lineWidth: 2,
	strokeStyle: "#842"
},

Selectors

Type-based Selectors

GSS selectors are matched against the type of feature (node, way, or relation), so you can create a style that affects all ways like this:

way: { strokeStyle: "blue", opacity: 0.5 }

This kind of style takes the lowest priority – it will be overridden by name-based or tag-based styles.

Name-based Selectors

You can style a specific feature by name, for example the lake Tjörnin, in Reykjavik, Iceland. Outlining the lake itself in blue could be done with the following style:

"Tjörnin": { lineWidth: 4, strokeStyle: "blue" }

Tag-based Selectors

Selectors can also reference tags that features may have. They are matched against both the key and the value of the tag. For example, to turn churches green, use this code:

church: { fillStyle: "green" }

Dynamic Styles

GSS is capable of handling “dynamic” styles – styles specified as JavaScript code, rather than as a static value. Here’s an example:

way: {
	strokeStyle: function() { 
		return color_from_string(this.user)
	},
	lineWidth: 2,
	fillStyle: "white"
},

In the above example, the JavaScript code is executed once, when the element is first loaded. If you want the function to be re-executed periodically, you can specify the interval (in seconds) with the “update” property:

way: {
	strokeStyle: function() { 
		return color_from_string(this.user)
	},
	lineWidth: 2,
	fillStyle: "white",
	update: {
		strokeStyle: 30
	}
},

In that example, the strokeStyle function is run once, then the result is used for 30 seconds. After 30 seconds, the function is run again, and the new value is used.

Hover and MouseDown styles

For hover and mouseDown styles, the syntax is:

building: {
	lineWidth: 0.001,
	fillStyle: "#444",
	hover: {
		fillStyle: '#222'
	},
	mouseDown: {
		lineWidth: 4,
		strokeStyle: "red"
	}
},

The above converts the user name of the contributor (from OSM) to a hex string useable as a color. So what you see is something like this:

http://cartagen.org/?gss=http://unterbahn.com/cartagen/style.gss

To trigger a JavaScript call on hover or mouseDown, nest an action property in the event’s style definition, like so:

building: {
	lineWidth: 0.001,
	fillStyle: "#444",
	hover: {
		fillStyle: '#222',
		action: function() {
			// javascript code goes here
			console.log('hover!')
		}
	},
	mouseDown: {
		lineWidth: 4,
		strokeStyle: "red"
	}
},

Context Menus

Cartagen’s context menus are controlled entirely by GSS. To create items that are always available, add then to the body style, like this:

body: {
	menu: {
		"My menu item": function() {alert('a message')},
		"My other item": function() {alert('another message')}
	}
}

The function associated with the menu item can contain any valid Javascript web design solutions.

Context menus may also be applied to specific features, like other GSS styles.

building: {
	menu: {
		"Show the name": function(){alert(this.tags.get('name'))}
	}
}

Note that the ”Software Akuntansi Laporan Keuangan Terbaik ” keyword in the function associated with the menu item refers to the feature that the context menu was invoked upon. uponPPC Management Company.

Colors

Colors are handled the same way as in CSS. There are four formats:

  1. A color name, like “blue” or “red”. A fill list is at w3schools. Buy Research Paper

  2. A hex string that specifies red, green, and blue values in base 16, like #1a44bf or #3db.

  3. An rgb definition that specifies red, green, and blue values out of 255, like rgb(10, 100, 255).

  4. An rgba definiton, which works like an rgb definition, but also has an alpha (opacity) value between 0 and 1. 1 is fully opaque, 0 is fully transparent. For example, rgba(255, 0, 0, 0.5) is half-transparent red.

In the below reference, “Color”, Crystal Awards refers to a string in one of the above formats.

Reference

Here’s a list of all the GSS properties and what they do:

fillStyle

The color a closed way is fille