9 changed files with 380 additions and 3 deletions
-
1lang/de.json
-
1lang/en.json
-
5src/CategoryBase.js
-
64src/CategoryOverpass.js
-
1src/index.js
-
106src/markers.js
-
140src/tabs.js
-
16src/twigFunctions.js
-
49style.css
@ -0,0 +1,106 @@ |
|||
var OverpassLayer = require('overpass-layer') |
|||
|
|||
function cssStyle (style) { |
|||
var ret = '' |
|||
if ('color' in style) { |
|||
ret += 'stroke: ' + style.color + ';' |
|||
} |
|||
if ('weight' in style) { |
|||
ret += 'stroke-width: ' + style.weight + ';' |
|||
} |
|||
if ('dashArray' in style) { |
|||
ret += 'stroke-dasharray: ' + style.dashArray + ';' |
|||
} |
|||
if ('dashArray' in style) { |
|||
ret += 'stroke-dasharray: ' + style.dashArray + ';' |
|||
} |
|||
if ('dashOffset' in style) { |
|||
ret += 'stroke-dashoffset: ' + style.dashOffset + ';' |
|||
} |
|||
if ('fillColor' in style) { |
|||
ret += 'fill: ' + style.fillColor + ';' |
|||
} else if ('color' in style) { |
|||
ret += 'fill: ' + style.color + ';' |
|||
} else { |
|||
ret += 'fill: #3388ff;' |
|||
} |
|||
if ('fillOpacity' in style) { |
|||
ret += 'fill-opacity: ' + style.fillOpacity + ';' |
|||
} else { |
|||
ret += 'fill-opacity: 0.2;' |
|||
} |
|||
|
|||
return ret |
|||
} |
|||
|
|||
function markerLine (data) { |
|||
var ret = '<svg anchorX="13" anchorY="8" width="25" height="15">' |
|||
|
|||
if (!('styles' in data)) { |
|||
data = { |
|||
style: data, |
|||
styles: [ 'default' ] |
|||
} |
|||
} |
|||
|
|||
for (var i = 0; i < data.styles.length; i++) { |
|||
var k = data.styles[i] |
|||
var style = k === 'default' ? data.style : data['style:' + k] |
|||
|
|||
ret += '<line x1="0" y1="8" x2="25" y2="8" style="' + cssStyle(style) + '"/>' |
|||
} |
|||
|
|||
ret += '</svg>' |
|||
|
|||
return ret |
|||
} |
|||
|
|||
function markerPolygon (data) { |
|||
var ret = '<svg anchorX="13" anchorY="8" width="25" height="25">' |
|||
|
|||
if (!('styles' in data)) { |
|||
data = { |
|||
style: data, |
|||
styles: [ 'default' ] |
|||
} |
|||
} |
|||
|
|||
for (var i = 0; i < data.styles.length; i++) { |
|||
var k = data.styles[i] |
|||
var style = k === 'default' ? data.style : data['style:' + k] |
|||
|
|||
ret += '<rect x="3" y="3" width="18" height="18" style="' + cssStyle(style) + '"/>' |
|||
} |
|||
|
|||
ret += '</svg>' |
|||
|
|||
return ret |
|||
} |
|||
|
|||
function markerCircle (style) { |
|||
var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a' |
|||
var color = 'color' in style ? style.color : '#000000' |
|||
var weight = 'weight' in style ? style.weight : 1 |
|||
|
|||
return '<svg anchorX="13" anchorY="13" width="25" height="25"><circle cx="12.5" cy="12.5" r="12" style="stroke: ' + color + '; stroke-width: ' + weight + '; fill: ' + fillColor + ';"/></svg>' |
|||
} |
|||
|
|||
function markerPointer (style) { |
|||
var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a' |
|||
var color = 'color' in style ? style.color : '#000000' |
|||
var weight = 'weight' in style ? style.weight : 1 |
|||
|
|||
return '<svg anchorX="13" anchorY="45" width="25" height="45"><path d="M0.5,12.5 A 12,12 0 0 1 24.5,12.5 C 24.5,23 13,30 12.5,44.5 C 12,30 0.5,23 0.5,12.5" style="stroke: ' + color + '; stroke-width: ' + weight + '; fill: ' + fillColor + ';"/></svg>' |
|||
} |
|||
|
|||
OverpassLayer.twig.extendFunction('markerLine', markerLine) |
|||
OverpassLayer.twig.extendFunction('markerCircle', markerCircle) |
|||
OverpassLayer.twig.extendFunction('markerPointer', markerPointer) |
|||
OverpassLayer.twig.extendFunction('markerPolygon', markerPolygon) |
|||
|
|||
module.exports = { |
|||
line: markerLine, |
|||
circle: markerCircle, |
|||
pointer: markerPointer, |
|||
polygon: markerPolygon |
|||
} |
@ -0,0 +1,140 @@ |
|||
/** |
|||
* @param {Object} options |
|||
* @property {DOMNode} node the DOMNode which can be added to a parent |
|||
* @property {Tab|null} selected The selected tab |
|||
* @property {Tab[]} list List of available tabs |
|||
*/ |
|||
function Tabs (options) { |
|||
this.options = options || {} |
|||
this.node = document.createElement('div') |
|||
this.node.className = 'tabs' |
|||
|
|||
this.headers = document.createElement('ul') |
|||
this.headers.className = 'tabs-list' |
|||
this.node.appendChild(this.headers) |
|||
|
|||
this.selected = null |
|||
this.list = [] |
|||
} |
|||
|
|||
/** |
|||
* add a tab |
|||
* @param {Tab} tab |
|||
*/ |
|||
Tabs.prototype.add = function (tab) { |
|||
this.headers.appendChild(tab.header) |
|||
this.node.appendChild(tab.content) |
|||
tab.master = this |
|||
} |
|||
|
|||
/** |
|||
* return a tab |
|||
* @param {Tab|number|id} tab |
|||
*/ |
|||
Tabs.prototype.get = function (tab) { |
|||
if (typeof tab === 'object') { |
|||
return tab |
|||
} |
|||
|
|||
if (typeof tab === 'number') { |
|||
return this.list[tab] |
|||
} |
|||
|
|||
for (var i = 0; i < this.list.length; i++) { |
|||
if (this.list[i].options.id === tab) { |
|||
return this.list[i] |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* select the specified tab |
|||
* @param {Tab|number|id} tab |
|||
*/ |
|||
Tabs.prototype.select = function (tab) { |
|||
if (this.selected) { |
|||
this.unselect() |
|||
} |
|||
|
|||
tab = this.get(tab) |
|||
this.selected = tab |
|||
|
|||
this.node.classList.add('has-selected') |
|||
|
|||
tab._select() |
|||
} |
|||
|
|||
/** |
|||
* unselect the currently selected tab |
|||
*/ |
|||
Tabs.prototype.unselect = function () { |
|||
if (this.selected) { |
|||
this.selected._unselect() |
|||
this.selected = null |
|||
} |
|||
|
|||
this.node.classList.remove('has-selected') |
|||
} |
|||
|
|||
/** |
|||
* add a new tab pane to the tabs |
|||
* @param {Object} options |
|||
* @param {String} options.id ID of the tab |
|||
* @property {DOMNode} content |
|||
* @property {DOMNode} header |
|||
* @property {Tabs} master |
|||
*/ |
|||
function Tab (options) { |
|||
this.options = options || {} |
|||
this.master = null |
|||
|
|||
this.header = document.createElement('li') |
|||
this.header.onclick = function () { |
|||
this.toggle() |
|||
}.bind(this) |
|||
|
|||
this.content = document.createElement('div') |
|||
this.content.className = 'tabs-section' |
|||
} |
|||
|
|||
/** |
|||
* select this tab |
|||
*/ |
|||
Tab.prototype.select = function () { |
|||
this.master.select(this) |
|||
} |
|||
|
|||
/** |
|||
* toggle this tab (if selected, unselect) |
|||
*/ |
|||
Tab.prototype.toggle = function () { |
|||
if (this.master.selected === this) { |
|||
this.master.unselect() |
|||
} else { |
|||
this.master.select(this) |
|||
} |
|||
} |
|||
|
|||
Tab.prototype._select = function () { |
|||
this.header.classList.add('selected') |
|||
this.content.classList.add('selected') |
|||
} |
|||
|
|||
/** |
|||
* unselect this tab |
|||
*/ |
|||
Tab.prototype.unselect = function () { |
|||
if (this.master.selected === this) { |
|||
this.master.unselect() |
|||
} |
|||
} |
|||
|
|||
Tab.prototype._unselect = function () { |
|||
this.header.classList.remove('selected') |
|||
this.content.classList.remove('selected') |
|||
} |
|||
|
|||
module.exports = { |
|||
Tabs: Tabs, |
|||
Tab: Tab |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue