Skip to content

Commit bf9df45

Browse files
authored
Merge pull request #186 from gtt-project/ftr/custom-icons
Support custom icons
2 parents 41701e3 + a33d473 commit bf9df45

File tree

6 files changed

+116
-22
lines changed

6 files changed

+116
-22
lines changed

src/components/gtt-setting.ts

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ export const gtt_setting = ():void => {
1111
const wrapper = $('<div>', {
1212
text: ''
1313
})
14-
$('<i>', {
15-
class: "ui-icons material-icons",
16-
title: item.label,
17-
text: item.value
18-
}).prependTo(wrapper)
14+
const style = item.optgroup.toLowerCase().split(' ').join('-')
15+
switch (style) {
16+
case 'material-icons':
17+
$('<i>', {
18+
class: 'ui-icons ' + style,
19+
title: item.label,
20+
text: item.value
21+
}).prependTo(wrapper)
22+
break;
23+
24+
default:
25+
$('<i>', {
26+
class: 'ui-icons ' + style + ' icon-' + item.value,
27+
title: item.label,
28+
text: ''
29+
}).prependTo(wrapper)
30+
break;
31+
}
1932
return li.append(wrapper).appendTo(ul)
2033
}
2134
});
@@ -25,44 +38,58 @@ export const gtt_setting = ():void => {
2538
const selectedValue = element.value
2639
if (element.length === 1 && selectedValue !== "") {
2740
element.remove(0)
28-
element.append(new Option("", "", false, false))
41+
// element.append(new Option("", "", false, false))
2942
}
3043
for (let font in FontSymbol.prototype.defs.fonts) {
44+
const optgroup = document.createElement('optgroup')
45+
optgroup.label = FontSymbol.prototype.defs.fonts[font].name
3146
for (let i in glyph) {
3247
if (glyph[i].font == font) {
3348
const selected = selectedValue === i
3449
const words = i.split('_')
3550
const text = words.map((word) => {
3651
return word[0].toUpperCase() + word.substring(1)
37-
}).join(" ")
38-
element.append(new Option(text, i, selected, selected))
52+
}).join(' ')
53+
optgroup.appendChild(new Option(text, i, selected, selected))
3954
if (selected) {
40-
element.nextElementSibling.className = "material-icons"
41-
element.nextElementSibling.textContent = i
55+
const style = font.toLowerCase().split(' ').join('-')
56+
switch (style) {
57+
case 'material-icons':
58+
element.nextElementSibling.className = style
59+
element.nextElementSibling.textContent = i
60+
break;
61+
62+
default:
63+
element.nextElementSibling.className = style + ' icon-' + i
64+
element.nextElementSibling.textContent = ''
65+
break;
66+
}
4267
}
4368
}
4469
}
70+
element.append(optgroup)
4571
}
4672

4773
// Apply better Selector styling with jQuery UI (available in Redmine)
4874
$(element)
4975
.selectmenu({
5076
change: function(event: any, data: any) {
51-
console.log(data.item.value)
52-
document.querySelector(`#icon_${element.id}`).textContent = data.item.value
77+
const style = data.item.optgroup.toLowerCase().split(' ').join('-')
78+
switch (style) {
79+
case 'material-icons':
80+
document.querySelector(`#icon_${element.id}`).className = style
81+
document.querySelector(`#icon_${element.id}`).textContent = data.item.value
82+
break;
83+
84+
default:
85+
document.querySelector(`#icon_${element.id}`).className = style + ' icon-' + data.item.value
86+
document.querySelector(`#icon_${element.id}`).textContent = ''
87+
break;
88+
}
5389
}
5490
})
5591
.selectmenu('menuWidget')
5692
.addClass('select-overflow')
5793
.addClass('ui-menu-icons customicons')
5894
})
59-
60-
// document.querySelectorAll("[id^='settings_tracker_']").forEach((element: HTMLSelectElement) => {
61-
// element.addEventListener('change', (ev) => {
62-
// const currentTarget = ev.currentTarget as HTMLSelectElement
63-
// const trackerId = currentTarget.id
64-
// document.querySelector(`#icon_${trackerId}`).className = "material-icons"
65-
// document.querySelector(`#icon_${trackerId}`).textContent = currentTarget.value
66-
// })
67-
// })
6895
}

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import 'ol/ol.css'
22
import 'ol-ext/dist/ol-ext.min.css'
33
import './stylesheets/app.scss'
44

5+
// Custom Icons
6+
import './stylesheets/custom-icons.css'
7+
import './stylesheets/CustomIconsDef.js'
8+
59
// Material Design Icons
610
// https://github.com/marella/material-design-icons/tree/main/font#readme
711
import '@material-design-icons/font/filled.css'
8-
import './fonts/MaterialDesignDef.js'
12+
import './stylesheets/MaterialDesignDef.js'
913

1014
import { GttClient } from './components/gtt-client'
1115
import { gtt_setting } from './components/gtt-setting'

src/stylesheets/CustomIconsDef.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ol_style_FontSymbol from 'ol-ext/style/FontSymbol'
2+
3+
ol_style_FontSymbol.addDefs(
4+
{ "font":"custom-icons",
5+
"name":"Custom Icons",
6+
"copyright":"Apache-2.0",
7+
"prefix": "gtt"
8+
},
9+
{ "lobsta": "\uf101",
10+
"park_bench": "\uf102",
11+
"road": "\uf103",
12+
"waste": "\uf104"
13+
});
14+
15+
export default ol_style_FontSymbol
File renamed without changes.

src/stylesheets/custom-icons.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@font-face {
2+
font-family: "custom-icons";
3+
font-style: normal;
4+
font-weight: 400;
5+
font-display: block;
6+
src: url("./custom-icons.woff2") format("woff2");
7+
}
8+
9+
.custom-icons {
10+
font-weight: normal;
11+
font-style: normal;
12+
font-size: 24px;
13+
line-height: 1;
14+
letter-spacing: normal;
15+
text-transform: none;
16+
display: inline-block;
17+
white-space: nowrap;
18+
word-wrap: normal;
19+
direction: ltr;
20+
-webkit-font-smoothing: antialiased;
21+
-moz-osx-font-smoothing: grayscale;
22+
text-rendering: optimizeLegibility;
23+
font-feature-settings: "liga";
24+
}
25+
26+
i[class^="icon-"]:before, i[class*=" icon-"]:before {
27+
font-family: custom-icons !important;
28+
font-style: normal;
29+
font-weight: normal !important;
30+
font-variant: normal;
31+
text-transform: none;
32+
line-height: 1;
33+
-webkit-font-smoothing: antialiased;
34+
-moz-osx-font-smoothing: grayscale;
35+
}
36+
37+
.icon-lobsta:before {
38+
content: "\f101";
39+
}
40+
.icon-park_bench:before {
41+
content: "\f102";
42+
}
43+
.icon-road:before {
44+
content: "\f103";
45+
}
46+
.icon-waste:before {
47+
content: "\f104";
48+
}

src/stylesheets/custom-icons.woff2

1.21 KB
Binary file not shown.

0 commit comments

Comments
 (0)