Skip to content

Commit

Permalink
Merge branch 'master' into fix-remove-state-attrib
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Forsgren committed Oct 11, 2023
2 parents cfd7d96 + 4802902 commit e115138
Show file tree
Hide file tree
Showing 38 changed files with 1,710 additions and 1,189 deletions.
1 change: 0 additions & 1 deletion examples/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
"style": "polygon-blue",
"type": "WFS",
"visible": true,
"offline": true,
"attributes": [
{
"name": "name",
Expand Down
853 changes: 332 additions & 521 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"drag-drop-touch": "^1.3.1",
"elm-pep": "^1.0.6",
"html2canvas": "^1.4.1",
"ol-mapbox-style": "10.1.0",
"ol-mapbox-style": "11.0.3",
"jspdf": "^2.5.0",
"ol": "^7.3.0",
"ol": "^8.1.0",
"pepjs": "^0.5.3",
"proj4": "^2.7.5"
},
Expand All @@ -55,7 +55,7 @@
"eslint-webpack-plugin": "^3.1.1",
"exports-loader": "^3.1.0",
"imports-loader": "^3.1.1",
"node-sass": "^7.0.3",
"node-sass": "^9.0.0",
"npm-run-all": "^4.1.5",
"run-sequence": "^2.2.1",
"source-map-loader": "^3.0.0",
Expand Down
13 changes: 4 additions & 9 deletions scss/_infowindow.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
top: 6em;
width: 320px;
z-index: 1;
overflow-x: hidden;
overflow: visible;
&.expandable_list {
cursor: move;
}
Expand Down Expand Up @@ -42,6 +42,7 @@
font-weight: bold;
padding: 1em 1em 1em 2em;
z-index: 10;
border-radius: inherit;
}

.expandable_list {
Expand Down Expand Up @@ -208,8 +209,8 @@

.expandable_list {
.export-buttons-container {
padding: 0.5em 0;
margin: 0;
padding: 0.5em 1.8em;
margin-left: 0;
}
}

Expand All @@ -218,12 +219,6 @@
margin-left: 1.8em;
}

.expandable_list {
.export-buttons-container {
padding: 0.5em 0;
}
}

.export-button {
background-color: $whitesmoke;
border: 1px solid #ccc;
Expand Down
44 changes: 41 additions & 3 deletions scss/_popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 6px;
bottom: 12px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
max-height: 70vh;
padding: 1px;
position: absolute;
text-align: left;
white-space: normal;
Expand All @@ -36,14 +34,54 @@
width: 0;
}

.o-popup::after {
.popup-top-center .o-popup {
bottom: 0;
}

.popup-bottom-center .o-popup {
bottom: 12px;
}

.popup-center-left .o-popup {
left: 10px;
}

.popup-center-right .o-popup {
right: 10px;
}

.popup-top-center .o-popup::after {
border-bottom-color: $white;
border-width: 10px;
top: -20px;
left: 50%;
margin-left: -10px;
}

.popup-bottom-center .o-popup::after {
border-top-color: $white;
border-width: 10px;
bottom: -20px;
left: 50%;
margin-left: -10px;
}

.popup-center-left .o-popup::after {
border-right-color: $white;
border-width: 10px;
left: -10px;
top: calc(50% - 6px);
margin-left: -10px;
}

.popup-center-right .o-popup::after {
border-left-color: $white;
border-width: 10px;
right: -20px;
top: calc(50% - 6px);
margin-left: -10px;
}

.o-popup::before {
border-top-color: #999;
border-width: 11px;
Expand Down
117 changes: 117 additions & 0 deletions src/components/infowindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Component, Button, Element as El, dom } from '../ui';
import utils from '../utils';

const Infowindow = function Infowindow(options = {}) {
const {
closeIcon = '#ic_close_24px',
title = 'Inforuta',
viewer,
type = 'floating',
contentComponent = El({
tagName: 'div',
cls: 'padding-y-small overflow-auto text-small'
})
} = options;
let {
isActive = false
} = options;
let headerComponent;
let titleComponent;
let infowindow;
let iwEl;
let closeButton;

const toggle = function toggle() {
iwEl.classList.toggle('faded');
isActive = !isActive;
};

const close = function close() {
if (isActive) {
toggle();
}
};

const changeContent = function changeContent(component, objTitle) {
document.getElementById(titleComponent.getId()).innerHTML = objTitle || title;
const contentEl = document.getElementById(contentComponent.getId());
while (contentEl.hasChildNodes()) {
contentEl.removeChild(contentEl.firstChild);
}
contentComponent.clearComponents();
contentComponent.addComponent(component);
if (!isActive) {
toggle();
}
const el = dom.html(`<div id="${component.getId()}">${component.render()}</div>`);
contentEl.appendChild(el);
component.dispatch('render');
};

return Component({
name: 'infowindow',
close,
changeContent,
onAdd() {
this.on('render', this.onRender);
this.render();
},
onInit() {
let iwElCls = isActive ? '' : ' faded';
let iwElStyle = '';
let hcElCls = '';

switch (type) {
case 'floating':
hcElCls = ' draggable move';
iwElStyle = 'top: 4rem; left: 4rem; max-height: calc(100% - (6rem))';
break;
case 'left':
iwElCls += ' top-left no-margin height-full';
break;
default:
hcElCls = ' draggable move';
iwElStyle = 'top: 4rem; left: 4rem; max-height: calc(100% - (6rem))';
}

closeButton = Button({
cls: 'small round margin-top-small margin-right-small icon-smaller grey-lightest o-tooltip',
ariaLabel: 'Stäng',
icon: closeIcon,
click() {
toggle();
}
});

titleComponent = El({
cls: 'flex row justify-start margin-top-small margin-left text-weight-bold padding-right',
style: { width: '100%' },
innerHTML: title
});

headerComponent = El({
cls: `flex row justify-end grey-lightest${hcElCls}`,
style: { width: '100%' },
components: [titleComponent, closeButton]
});

infowindow = El({
cls: `absolute flex column control bg-white overflow-hidden z-index-top no-select${iwElCls}`,
style: iwElStyle,
collapseX: true,
components: [headerComponent, contentComponent]
});

this.addComponent(infowindow);
},
render() {
const newEl = dom.html(infowindow.render());
document.getElementById(viewer.getMain().getId()).appendChild(newEl);
iwEl = document.getElementById(infowindow.getId());
utils.makeElementDraggable(iwEl);
this.dispatch('render');
}
});
};

export default Infowindow;
14 changes: 13 additions & 1 deletion src/controls/draganddrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const DragAndDrop = function DragAndDrop(options = {}) {
const draggable = options.draggable || true;
const promptlessRemoval = options.promptlessRemoval !== false;
const styleByAttribute = options.styleByAttribute || false;
const zoomToExtent = options.zoomToExtent !== false;
const zoomToExtentOnLoad = options.zoomToExtentOnLoad !== false;
const featureStyles = options.featureStyles || {
Point: [{
circle: {
Expand Down Expand Up @@ -153,6 +155,7 @@ const DragAndDrop = function DragAndDrop(options = {}) {
queryable: true,
removable: true,
promptlessRemoval,
zoomToExtent,
visible: true,
source: 'none',
type: 'GEOJSON',
Expand All @@ -161,7 +164,16 @@ const DragAndDrop = function DragAndDrop(options = {}) {
if (!styleByAttribute) {
layerOptions.styleDef = featureStyles[event.features[0].getGeometry().getType()];
}
viewer.addLayer(layerOptions);
const layer = viewer.addLayer(layerOptions);
if (zoomToExtentOnLoad) {
const extent = typeof layer.getSource !== 'undefined' && typeof layer.getSource().getExtent !== 'undefined' ? layer.getSource().getExtent() : layer.getExtent();
if (layer.getVisible()) {
viewer.getMap().getView().fit(extent, {
padding: [50, 50, 50, 50],
duration: 1000
});
}
}
});
this.render();
},
Expand Down
4 changes: 2 additions & 2 deletions src/controls/draw/drawhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ const DrawHandler = function DrawHandler(options = {}) {
});
newLayer.getSource().on('addfeature', (e) => {
e.feature.on('change:origostyle', () => {
onUpdate(e, newLayer.get('name'));
onUpdate(e.feature, newLayer.get('name'));
});
e.feature.on('change:popuptext', () => {
onUpdate(e, newLayer.get('name'));
onUpdate(e.feature, newLayer.get('name'));
});
});
return newLayer;
Expand Down
50 changes: 47 additions & 3 deletions src/controls/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ const Editor = function Editor(options = {}) {
const {
autoForm = false,
autoSave = true,
isActive = true
isActive = true,
featureList = true
} = options;
let editorButton;
let target;
let viewer;
let isVisible = isActive;
let toolbarVisible = false;
/** Keeps track of the last selected item in featureinfo. We need to use our own variable for this
* in order to determine if editor got activated directly from featureinfo or some other tool has been active between. */
let lastSelectedItem;

/** The handler were all state is kept */
let editHandler;
Expand All @@ -25,6 +29,16 @@ const Editor = function Editor(options = {}) {
// There are some serious event dependencies between viewer, editor, edithandler, editortoolbar, editorlayers, dropdown and editorbutton,
// which makes it almost impossible to do things in correct order.
isVisible = detail.active;
// Actually, if we're going visible
if (isVisible) {
if (lastSelectedItem && lastSelectedItem.getLayer().get('editable') && !lastSelectedItem.getLayer().get('isTable')) {
// Set a preselected feature. No use to set layer in handler as toolbar keeps state that will override a change of layer in handler anyway
// when editor toolbar becomes visible.
editHandler.preselectFeature(lastSelectedItem.getFeature());
// Have to set layer in toolbar instead of handler.
editorToolbar.changeActiveLayer(lastSelectedItem.getLayer().get('name'));
}
}
viewer.dispatch('toggleClickInteraction', detail);
};

Expand Down Expand Up @@ -70,14 +84,44 @@ const Editor = function Editor(options = {}) {
autoSave,
currentLayer,
editableLayers,
isActive
isActive,
featureList
});
editHandler = EditHandler(handlerOptions, viewer);

// Set up eventhandler for when featureinfo selects (or highlights) a feature
const featureInfo = viewer.getFeatureinfo();
featureInfo.on('changeselection', detail => {
if (isVisible) {
// This can only happen if featureInfo.ShowFeatureInfo, featureInfo.showInfow or featureInfo.render is called
// from api, as featureInfo component can not be active when editor is so the user can not click in the map to select anything.
if (detail && detail.getLayer().get('editable') && !detail.getLayer().get('isTable')) {
// Set a preselected feature.
editHandler.preselectFeature(detail.getFeature());
// Actually change active layer.
editHandler.setActiveLayer(detail.getLayer().get('name'));
// Have to update state in toolbar as well.
editorToolbar.changeActiveLayer(detail.getLayer().get('name'));
// Clear featureinfo to close the popup which otherwise would just be annoying
featureInfo.clear();
}
} else {
lastSelectedItem = detail;
}
});

// Set up eventhandler for when featureinfo clears selection
// Event is sent from featureinfo when popup etc is closed or cleared, but not when tool changes
featureInfo.on('clearselection', () => {
lastSelectedItem = null;
});

viewer.on('toggleClickInteraction', (detail) => {
if (detail.name === 'editor' && detail.active) {
editorButton.dispatch('change', { state: 'active' });
} else {
// Someone else got active. Ditch the last selected item as we don't go directly from featureinfo to edit
lastSelectedItem = null;
editorButton.dispatch('change', { state: 'initial' });
}
});
Expand Down Expand Up @@ -129,7 +173,7 @@ const Editor = function Editor(options = {}) {
editFeatureAttributes,
deleteFeature,
changeActiveLayer: (layerName) => {
// Only need to actually cahne layer if editor is active. Otherwise state is just set in toolbar and will
// Only need to actually change layer if editor is active. Otherwise state is just set in toolbar and will
// activate set layer when toggled visible
if (isVisible) {
editHandler.setActiveLayer(layerName);
Expand Down
Loading

0 comments on commit e115138

Please sign in to comment.