Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: styling of draganddrop layers #1770

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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