Skip to content

Commit

Permalink
Fix for styling of draganddrop layers (origo-map#1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokd committed May 25, 2023
1 parent 1c8a05b commit dc90e68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/controls/draganddrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import GeoJSONFormat from 'ol/format/GeoJSON';
import IGCFormat from 'ol/format/IGC';
import KMLFormat from 'ol/format/KML';
import TopoJSONFormat from 'ol/format/TopoJSON';
import Style from '../style';
import { Component, InputFile, Button, Element as El } from '../ui';

const DragAndDrop = function DragAndDrop(options = {}) {
Expand Down Expand Up @@ -116,7 +115,6 @@ const DragAndDrop = function DragAndDrop(options = {}) {
}
}]
};
const vectorStyles = Style.createGeometryStyle(featureStyles);
dragAndDrop = new olDragAndDrop({
formatConstructors: [
GPXFormat,
Expand Down Expand Up @@ -161,7 +159,7 @@ const DragAndDrop = function DragAndDrop(options = {}) {
features: event.features
};
if (!styleByAttribute) {
layerOptions.style = vectorStyles[event.features[0].getGeometry().getType()];
layerOptions.styleDef = featureStyles[event.features[0].getGeometry().getType()];
}
viewer.addLayer(layerOptions);
});
Expand Down
17 changes: 11 additions & 6 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ const Viewer = function Viewer(targetOption, options = {}) {

const getStyles = () => styles;

const addStyle = function addStyle(styleName, styleProps) {
if (!(styleName in styles)) {
styles[styleName] = styleProps;
}
};

const getResolutions = () => resolutions;

const getMapUrl = () => {
Expand Down Expand Up @@ -419,6 +425,11 @@ const Viewer = function Viewer(targetOption, options = {}) {
if (thisProps.layerParam && layerParams[thisProps.layerParam]) {
layerProps = Object.assign({}, layerParams[thisProps.layerParam], thisProps);
}
if (thisProps.styleDef && !thisProps.style) {
const styleId = generateUUID();
addStyle(styleId, [thisProps.styleDef]);
layerProps.style = styleId;
}
const layer = Layer(layerProps, this);
addLayerStylePicker(layerProps);
if (insertBefore) {
Expand Down Expand Up @@ -497,12 +508,6 @@ const Viewer = function Viewer(targetOption, options = {}) {
}
};

const addStyle = function addStyle(styleName, styleProps) {
if (!(styleName in styles)) {
styles[styleName] = styleProps;
}
};

const addMarker = function addMarker(coordinates, title, content, layerProps, showPopup) {
maputils.createMarker(coordinates, title, content, this, layerProps, showPopup);
};
Expand Down

0 comments on commit dc90e68

Please sign in to comment.