Skip to content

Commit 860fb6e

Browse files
ftoromanoffa-dutremble
authored andcommitted
refactor(FeatureToolTip): update with new gestion of Style
1 parent 3dd0937 commit 860fb6e

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

examples/css/example.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ h3 {
253253

254254
.tooltip {
255255
display: none;
256-
background-image: linear-gradient(rgba(80, 80, 80,0.95), rgba(60, 60, 60,0.95));
256+
background-image: linear-gradient(rgba(167, 164, 164, 0.95), rgba(60, 60, 60,0.95));
257257
box-shadow: -1px 2px 5px 1px rgba(0, 0, 0, 0.5);
258258
margin-top: 20px;
259259
margin-left: 20px;

examples/js/plugins/FeatureToolTip.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,42 +64,38 @@ const FeatureToolTip = (function _() {
6464
}
6565
}
6666

67-
function getGeometryProperties(geometry) {
68-
return function properties() { return geometry.properties; };
69-
}
70-
7167
function fillToolTip(features, layer, options) {
7268
let content = '';
7369
let feature;
7470
let geometry;
75-
let style;
71+
const style = layer.style;
7672
let fill;
7773
let stroke;
7874
let symb = '';
7975
let prop;
8076

77+
const context = style.context;
78+
8179
for (let p = 0; p < features.length; p++) {
8280
feature = features[p];
8381
geometry = feature.geometry;
84-
style = (geometry.properties && geometry.properties.style) || feature.style || layer.style;
85-
const context = { globals: {}, properties: getGeometryProperties(geometry) };
86-
style = style.applyContext(context);
82+
83+
context.setFeature(feature);
84+
context.setGeometry(geometry);
8785

8886
if (feature.type === itowns.FEATURE_TYPES.POLYGON) {
8987
symb = '&#9724';
90-
if (style) {
91-
fill = style.fill && style.fill.color;
92-
stroke = style.stroke && ('1.25px ' + style.stroke.color);
93-
}
88+
fill = style.fill && style.fill.color;
89+
stroke = style.stroke && ('1.25px ' + style.stroke.color);
9490
} else if (feature.type === itowns.FEATURE_TYPES.LINE) {
9591
symb = '&#9473';
96-
fill = style && style.stroke && style.stroke.color;
92+
fill = style.stroke && style.stroke.color;
9793
stroke = '0px';
9894
} else if (feature.type === itowns.FEATURE_TYPES.POINT) {
9995
symb = '&#9679';
100-
if (style && style.point) { // Style and style.point can be undefined if no style options were passed
101-
fill = style.point.color;
102-
stroke = '1.25px ' + style.point.line;
96+
if (style.point || style.icon) { // Style and style.point can be undefined if no style options were passed
97+
fill = (style.point && style.point.color) || (style.icon && style.icon.color);
98+
stroke = '1.25px ' + ((style.point && style.point.line) || 'black');
10399
}
104100
}
105101

@@ -109,10 +105,10 @@ const FeatureToolTip = (function _() {
109105
content += '</span>';
110106

111107
if (geometry.properties) {
112-
content += (geometry.properties.description || geometry.properties.name || geometry.properties.nom || layer.name || '');
108+
content += (geometry.properties.description || geometry.properties.name || geometry.properties.nom || geometry.properties.title || layer.name || '');
113109
}
114110

115-
if (feature.type === itowns.FEATURE_TYPES.POINT) {
111+
if (feature.type === itowns.FEATURE_TYPES.POINT && options.writeLatLong) {
116112
content += '<br/><span class="coord">long ' + feature.coordinates[0].toFixed(4) + '</span>';
117113
content += '<br/><span class="coord">lat ' + feature.coordinates[1].toFixed(4) + '</span>';
118114
}
@@ -231,8 +227,8 @@ const FeatureToolTip = (function _() {
231227
}
232228

233229
const opts = options || { filterAllProperties: true };
234-
opts.filterProperties = opts.filterProperties == undefined ? [] : opts.filterProperties;
235-
opts.filterProperties.concat(['name', 'nom', 'style', 'description']);
230+
opts.filterProperties = opts.filterProperties === undefined ? [] : opts.filterProperties;
231+
opts.writeLatLong = opts.writeLatLong || false;
236232

237233
layers.push({ layer: layer, options: opts });
238234
layersId.push(layer.id);

0 commit comments

Comments
 (0)