qwc2-lts
Version:
QGIS Web Client
41 lines (40 loc) • 1.66 kB
JavaScript
/**
* Copyright 2024 Sourcepole AG
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import ColorLayer from '@giro3d/giro3d/core/layer/ColorLayer';
import VectorSource from "@giro3d/giro3d/sources/VectorSource.js";
import ol from 'openlayers';
import FeatureStyles from '../../../utils/FeatureStyles';
import { createFeatures, featureStyleFunction, updateFeatures } from '../../map/layers/VectorLayer';
export default {
create3d: function create3d(options, projection) {
return new ColorLayer({
name: options.name,
source: new VectorSource({
data: createFeatures(options, projection),
format: new ol.format.GeoJSON(),
style: options.styleFunction || function (feature) {
var styleName = options.styleName || 'default';
var styleOptions = options.styleOptions || {};
return FeatureStyles[styleName](feature, styleOptions);
}
})
});
},
update3d: function update3d(layer, newOptions, oldOptions, projection) {
if (newOptions.styleName !== oldOptions.styleName || newOptions.styleOptions !== oldOptions.styleOptions) {
layer.source.setStyle(featureStyleFunction(newOptions));
} else if (newOptions.styleFunction !== oldOptions.styleFunction) {
layer.source.setStyle(newOptions.styleFunction);
}
if (newOptions.features !== oldOptions.features) {
updateFeatures(layer.source, newOptions, oldOptions, projection);
} else if ((oldOptions.rev || 0) !== (newOptions.rev || 0)) {
layer.source.update();
}
}
};