Skip to content

Commit

Permalink
refactor(FeatureToolTip): update with new gestion of Style
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Dec 13, 2023
1 parent 55849f6 commit 356e695
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/css/example.css
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ h3 {

.tooltip {
display: none;
background-image: linear-gradient(rgba(80, 80, 80,0.95), rgba(60, 60, 60,0.95));
background-image: linear-gradient(rgba(167, 164, 164, 0.95), rgba(60, 60, 60,0.95));
box-shadow: -1px 2px 5px 1px rgba(0, 0, 0, 0.5);
margin-top: 20px;
margin-left: 20px;
Expand Down
36 changes: 16 additions & 20 deletions examples/js/plugins/FeatureToolTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,38 @@ const FeatureToolTip = (function _() {
}
}

function getGeometryProperties(geometry) {
return function properties() { return geometry.properties; };
}

function fillToolTip(features, layer, options) {
let content = '';
let feature;
let geometry;
let style;
const style = layer.style;
let fill;
let stroke;
let symb = '';
let prop;

const context = style.context;

for (let p = 0; p < features.length; p++) {
feature = features[p];
geometry = feature.geometry;
style = (geometry.properties && geometry.properties.style) || feature.style || layer.style;
const context = { globals: {}, properties: getGeometryProperties(geometry) };
style = style.applyContext(context);

context.setFeature(feature);
context.setGeometry(geometry);

if (feature.type === itowns.FEATURE_TYPES.POLYGON) {
symb = '&#9724';
if (style) {
fill = style.fill && style.fill.color;
stroke = style.stroke && ('1.25px ' + style.stroke.color);
}
fill = style.fill && style.fill.color;
stroke = style.stroke && ('1.25px ' + style.stroke.color);
} else if (feature.type === itowns.FEATURE_TYPES.LINE) {
symb = '&#9473';
fill = style && style.stroke && style.stroke.color;
fill = style.stroke && style.stroke.color;
stroke = '0px';
} else if (feature.type === itowns.FEATURE_TYPES.POINT) {
symb = '&#9679';
if (style && style.point) { // Style and style.point can be undefined if no style options were passed
fill = style.point.color;
stroke = '1.25px ' + style.point.line;
if (style.point || style.icon) { // Style and style.point can be undefined if no style options were passed
fill = (style.point && style.point.color) || (style.icon && style.icon.color);
stroke = '1.25px ' + ((style.point && style.point.line) || 'black');
}
}

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

if (geometry.properties) {
content += (geometry.properties.description || geometry.properties.name || geometry.properties.nom || layer.name || '');
content += (geometry.properties.description || geometry.properties.name || geometry.properties.nom || geometry.properties.title || layer.name || '');
}

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

const opts = options || { filterAllProperties: true };
opts.filterProperties = opts.filterProperties == undefined ? [] : opts.filterProperties;
opts.filterProperties.concat(['name', 'nom', 'style', 'description']);
opts.filterProperties = opts.filterProperties === undefined ? [] : opts.filterProperties;
opts.writeLatLong = opts.writeLatLong || false;

layers.push({ layer: layer, options: opts });
layersId.push(layer.id);
Expand Down

0 comments on commit 356e695

Please sign in to comment.