Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Sep 20, 2019
2 parents 420dc5b + 1444e75 commit 9e30045
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
23 changes: 11 additions & 12 deletions api/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ class Map {
getFeaturesFromCoordinates(layer, event.coordinate, resolution).then((feature) => {
if (feature) {
this.vectorSource_.addFeature(feature);
const featureId = feature.getId();
if (featureId === undefined) {
throw new Error('Missing feature ID');
}
this.selectObject(featureId, true);
this.selectObject(feature.getId(), event.coordinate, true);
}
});
}
Expand Down Expand Up @@ -392,23 +388,26 @@ class Map {

/**
* @param {string|number} id Identifier.
* @param {import("ol/coordinate.js").Coordinate} position
* @param {boolean} table Display all properties in a table
*/
selectObject(id, table = false) {
selectObject(id, position = null, table = false) {
const feature = this.vectorSource_.getFeatureById(id);
if (feature) {
const point = feature.getGeometry();
if (!(point instanceof Point)) {
throw new Error('Wrong geometry type');
if (!position) {
const point = feature.getGeometry();
if (!(point instanceof Point)) {
throw new Error('Wrong geometry type');
}
position = point.getCoordinates();
}
const coordinates = point.getCoordinates();
const geometryName = feature.getGeometryName();
const properties = feature.getProperties();
let contentHTML = '';
if (table) {
contentHTML += '<table><tbody>';
for (const key in properties) {
if (!EXCLUDE_PROPERTIES.includes(key) && key !== geometryName) {
if (!EXCLUDE_PROPERTIES.includes(key) && key !== geometryName && properties[key] !== undefined) {
contentHTML += '<tr>';
contentHTML += `<th>${key}</th>`;
contentHTML += `<td>${properties[key]}</td>`;
Expand All @@ -429,7 +428,7 @@ class Map {
throw new Error('Missing content');
}
content.innerHTML = contentHTML;
this.overlay_.setPosition(coordinates);
this.overlay_.setPosition(position);
}
}

Expand Down
3 changes: 2 additions & 1 deletion api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import EPSG2056 from '@geoblocks/proj/src/EPSG_2056.js';
export default /** @type {APIConfig} */({
// The URL to the themes service.
themesUrl: 'https://www.example.com',
localeUrl: undefined,

// The projection of the map
projection: EPSG2056,
Expand All @@ -32,5 +33,5 @@ export default /** @type {APIConfig} */({
backgroundLayer: 'orthophoto',

// The list of layers (names) that can be queried on mouse click
queryableLayers: ['osm_open', 'many_attributes']
queryableLayers: ['osm_open', 'many_attributes', 'polygon']
});
2 changes: 1 addition & 1 deletion buildtools/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ new webpack.LoaderOptionsPlugin({
module.exports = function() {
return {
mode: 'development',
// devtool: 'eval',
devtool: 'inline-cheap-source-map', // 'cheap-eval-source-map',
output: {
filename: '[name].js'
},
Expand Down
19 changes: 12 additions & 7 deletions contribs/gmf/src/backgroundlayerselector/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ Controller.prototype.handleThemesChange_ = function() {
const opacityLayer = layers.find(layer => layer.get('label') === this.opacityOptions);
if (opacityLayer !== undefined) {
this.setOpacityBgLayer(opacityLayer);
this.opacityLayer = opacityLayer;

// Reorder for the UI the bgArray copy with the opacity layer at the end
this.bgLayers = this.bgLayers.slice();
Expand All @@ -216,6 +215,7 @@ Controller.prototype.getSetBgLayerOpacity = function(val) {
if (val !== undefined) {
this.opacityLayer.setOpacity(val);
this.opacityLayer.setVisible(val !== 0);
this.bgLayer.setVisible(val !== 1);
}
return this.opacityLayer.getOpacity();
};
Expand All @@ -225,11 +225,14 @@ Controller.prototype.getSetBgLayerOpacity = function(val) {
* @param {boolean=} opt_silent Do not notify listeners.
*/
Controller.prototype.setLayer = function(layer, opt_silent) {
if (!this.map) {
throw new Error('Missing map');
}
const opacity = this.opacityLayer ? this.opacityLayer.getOpacity() : 0;
this.bgLayer = layer;
this.backgroundLayerMgr_.set(this.map, layer);
layer.setVisible(opacity !== 1);
if (this.opacityLayer) {
this.opacityLayer.setVisible(opacity !== 0);
this.opacityLayer.setOpacity(opacity);
}
if (!opt_silent && this.select) {
this.select();
}
Expand All @@ -240,9 +243,11 @@ Controller.prototype.setLayer = function(layer, opt_silent) {
* @param {import("ol/layer/Base.js").default} layer The opacity background layer.
*/
Controller.prototype.setOpacityBgLayer = function(layer) {
if (!this.map) {
throw new Error('Missing map');
}
const opacity = this.opacityLayer ? this.opacityLayer.getOpacity() : layer.getOpacity();
layer.setOpacity(opacity);
this.opacityLayer = layer;
this.opacityLayer.setVisible(opacity !== 0);
this.bgLayer.setVisible(opacity !== 1);
this.backgroundLayerMgr_.setOpacityBgLayer(this.map, layer);
};

Expand Down
5 changes: 2 additions & 3 deletions src/map/BackgroundLayerMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ export class MapBackgroundLayerManager extends olObservable {
const opacityBackgroundLayer = this.getOpacityBgLayer(map);
if (opacityBackgroundLayer) {
const previous = bgGroup.getLayers().remove(opacityBackgroundLayer);
const opacity = previous ? previous.getOpacity() : 0;
layer.setOpacity(opacity);
layer.setVisible(opacity !== 0);
layer.setOpacity(previous ? previous.getOpacity() : 0);
layer.setVisible(previous ? previous.getVisible() : true);
}
const ZIndex = -100;
layer.setZIndex(ZIndex);
Expand Down

0 comments on commit 9e30045

Please sign in to comment.