Skip to content

Commit

Permalink
Merge pull request #1025 from openlayers/eblondel-core-util-namedexports
Browse files Browse the repository at this point in the history
Eblondel core util namedexports
  • Loading branch information
gberaudo authored Apr 25, 2023
2 parents c62c152 + 85f845a commit d7a4795
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 168 deletions.
5 changes: 2 additions & 3 deletions examples/icon-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import olStyleFill from 'ol/style/Fill.js';
import olMap from 'ol/Map.js';
import olSourceVector from 'ol/source/Vector.js';
import olLayerVector from 'ol/layer/Vector.js';
import olcsCore from 'olcs/core.js';
import {rotateAroundAxis, pickBottomPoint} from 'olcs/core.js';
import {OLCS_ION_TOKEN} from './_common.js';


Expand Down Expand Up @@ -116,11 +116,10 @@ ol3d.enableAutoRenderLoop();

// Tilt camera
const camera = scene.camera;
const pivot = olcsCore.pickBottomPoint(scene);
const pivot = pickBottomPoint(scene);
if (pivot) {
const options = {};
const transform = Cesium.Matrix4.fromTranslation(pivot);
const axis = camera.right;
const rotateAroundAxis = olcsCore.rotateAroundAxis;
rotateAroundAxis(camera, -Math.PI / 4, axis, transform, options);
}
19 changes: 9 additions & 10 deletions examples/rotate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module examples.rotate
*/
import olcsCore from 'olcs/core.js';
import {computeSignedTiltAngleOnGlobe, pickBottomPoint, computeAngleToZenith, setHeadingUsingBottomCenter, rotateAroundAxis} from 'olcs/core.js';
import OLCesium from 'olcs/OLCesium.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
Expand Down Expand Up @@ -96,7 +96,7 @@ OlcsControl.prototype.getHeading = function() {
*/
OlcsControl.prototype.getTiltOnGlobe = function() {
const scene = this.ol3d_.getCesiumScene();
const tiltOnGlobe = olcsCore.computeSignedTiltAngleOnGlobe(scene);
const tiltOnGlobe = computeSignedTiltAngleOnGlobe(scene);
return -tiltOnGlobe;
};

Expand All @@ -107,24 +107,24 @@ OlcsControl.prototype.getTiltOnGlobe = function() {
OlcsControl.prototype.resetToNorthZenith = function(callback) {
const scene = this.ol3d_.getCesiumScene();
const camera = scene.camera;
const pivot = olcsCore.pickBottomPoint(scene);
const pivot = pickBottomPoint(scene);

if (!pivot) {
callback();
return;
}

const currentHeading = this.getHeading();
const angle = olcsCore.computeAngleToZenith(scene, pivot);
const angle = computeAngleToZenith(scene, pivot);

// Point to North
olcsCore.setHeadingUsingBottomCenter(scene, currentHeading, pivot);
setHeadingUsingBottomCenter(scene, currentHeading, pivot);

// Go to zenith
const transform = Cesium.Matrix4.fromTranslation(pivot);
const axis = camera.right;
const options = {callback};
olcsCore.rotateAroundAxis(camera, -angle, axis, transform, options);
rotateAroundAxis(camera, -angle, axis, transform, options);
};


Expand All @@ -143,9 +143,9 @@ OlcsControl.prototype.rotate = function(angle) {
*/
OlcsControl.prototype.setHeading = function(angle) {
const scene = this.ol3d_.getCesiumScene();
const bottom = olcsCore.pickBottomPoint(scene);
const bottom = pickBottomPoint(scene);
if (bottom) {
olcsCore.setHeadingUsingBottomCenter(scene, angle, bottom);
setHeadingUsingBottomCenter(scene, angle, bottom);
}
};

Expand All @@ -156,7 +156,7 @@ OlcsControl.prototype.setHeading = function(angle) {
OlcsControl.prototype.tiltOnGlobe = function(angle) {
const scene = this.ol3d_.getCesiumScene();
const camera = scene.camera;
const pivot = olcsCore.pickBottomPoint(scene);
const pivot = pickBottomPoint(scene);
if (!pivot) {
// Could not find the bottom point
return;
Expand All @@ -165,7 +165,6 @@ OlcsControl.prototype.tiltOnGlobe = function(angle) {
const options = {};
const transform = Cesium.Matrix4.fromTranslation(pivot);
const axis = camera.right;
const rotateAroundAxis = olcsCore.rotateAroundAxis;
rotateAroundAxis(camera, -angle, axis, transform, options);
};

Expand Down
4 changes: 2 additions & 2 deletions examples/vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import olInteractionDragAndDrop from 'ol/interaction/DragAndDrop.js';
import olGeomMultiPolygon from 'ol/geom/MultiPolygon.js';
import olLayerVector from 'ol/layer/Vector.js';
import {transform} from 'ol/proj.js';
import olcsCore from 'olcs/core.js';
import {createMatrixAtCoordinates} from 'olcs/core.js';
import {OLCS_ION_TOKEN} from './_common.js';


Expand Down Expand Up @@ -124,7 +124,7 @@ modelFeatures.forEach((feature) => {
return {
cesiumOptions: {
url: 'data/Box.gltf',
modelMatrix: olcsCore.createMatrixAtCoordinates(center, rotation),
modelMatrix: createMatrixAtCoordinates(center, rotation),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
minimumPixelSize: 64
}
Expand Down
4 changes: 2 additions & 2 deletions src/olcs/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {unByKey as olObservableUnByKey} from 'ol/Observable.js';
import {toRadians, toDegrees} from './math.js';
import {getTransform} from 'ol/proj.js';
import olcsCore, {calcDistanceForResolution, calcResolutionForDistance} from './core.js';
import {pickCenterPoint, calcDistanceForResolution, calcResolutionForDistance} from './core.js';

class Camera {
/**
Expand Down Expand Up @@ -370,7 +370,7 @@ class Camera {
// target & distance
const ellipsoid = Cesium.Ellipsoid.WGS84;
const scene = this.scene_;
const target = olcsCore.pickCenterPoint(scene);
const target = pickCenterPoint(scene);

let bestTarget = target;
if (!bestTarget) {
Expand Down
38 changes: 19 additions & 19 deletions src/olcs/FeatureConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import olSourceCluster from 'ol/source/Cluster.js';
import {circular as olCreateCircularPolygon} from 'ol/geom/Polygon.js';
import {boundingExtent, getCenter} from 'ol/extent.js';
import olGeomSimpleGeometry from 'ol/geom/SimpleGeometry.js';
import olcsCore from './core.js';
import {convertColorToCesium, olGeometryCloneTo4326, ol4326CoordinateToCesiumCartesian, ol4326CoordinateArrayToCsCartesians} from './core.js';
import olcsCoreVectorLayerCounterpart from './core/VectorLayerCounterpart.js';
import olcsUtil, {getUid, isGroundPolylinePrimitiveSupported} from './util.js';
import {obj, getUid, isGroundPolylinePrimitiveSupported} from './util.js';


/**
Expand Down Expand Up @@ -59,7 +59,7 @@ class FeatureConverter {
const source = evt.target;
console.assert(source instanceof olSourceVector);

const cancellers = olcsUtil.obj(source)['olcs_cancellers'];
const cancellers = obj(source)['olcs_cancellers'];
if (cancellers) {
const feature = evt.feature;
if (feature) {
Expand All @@ -77,7 +77,7 @@ class FeatureConverter {
cancellers[key]();
}
}
olcsUtil.obj(source)['olcs_cancellers'] = {};
obj(source)['olcs_cancellers'] = {};
}
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ class FeatureConverter {
olColor = fillColor;
}

return olcsCore.convertColorToCesium(olColor);
return convertColorToCesium(olColor);
}

/**
Expand Down Expand Up @@ -321,7 +321,7 @@ class FeatureConverter {
*/
olCircleGeometryToCesium(layer, feature, olGeometry, projection, olStyle) {

olGeometry = olcsCore.olGeometryCloneTo4326(olGeometry, projection);
olGeometry = olGeometryCloneTo4326(olGeometry, projection);
console.assert(olGeometry.getType() == 'Circle');

// ol.Coordinate
Expand All @@ -331,8 +331,8 @@ class FeatureConverter {
point[0] += olGeometry.getRadius();

// Cesium
center = olcsCore.ol4326CoordinateToCesiumCartesian(center);
point = olcsCore.ol4326CoordinateToCesiumCartesian(point);
center = ol4326CoordinateToCesiumCartesian(center);
point = ol4326CoordinateToCesiumCartesian(point);

// Accurate computation of straight distance
const radius = Cesium.Cartesian3.distance(center, point);
Expand All @@ -349,7 +349,7 @@ class FeatureConverter {
const width = this.extractLineWidthFromOlStyle(olStyle);
if (width) {
const circlePolygon = olCreateCircularPolygon(olGeometry.getCenter(), radius);
const positions = olcsCore.ol4326CoordinateArrayToCsCartesians(circlePolygon.getLinearRing(0).getCoordinates());
const positions = ol4326CoordinateArrayToCsCartesians(circlePolygon.getLinearRing(0).getCoordinates());
if (!isGroundPolylinePrimitiveSupported(this.scene)) {
const color = this.extractColorFromOlStyle(olStyle, true);
outlinePrimitive = this.createStackedGroundCorridors(layer, feature, width, color, positions);
Expand Down Expand Up @@ -444,10 +444,10 @@ class FeatureConverter {
*/
olLineStringGeometryToCesium(layer, feature, olGeometry, projection, olStyle) {

olGeometry = olcsCore.olGeometryCloneTo4326(olGeometry, projection);
olGeometry = olGeometryCloneTo4326(olGeometry, projection);
console.assert(olGeometry.getType() == 'LineString');

const positions = olcsCore.ol4326CoordinateArrayToCsCartesians(olGeometry.getCoordinates());
const positions = ol4326CoordinateArrayToCsCartesians(olGeometry.getCoordinates());
const width = this.extractLineWidthFromOlStyle(olStyle);

let outlinePrimitive;
Expand Down Expand Up @@ -506,7 +506,7 @@ class FeatureConverter {
*/
olPolygonGeometryToCesium(layer, feature, olGeometry, projection, olStyle) {

olGeometry = olcsCore.olGeometryCloneTo4326(olGeometry, projection);
olGeometry = olGeometryCloneTo4326(olGeometry, projection);
console.assert(olGeometry.getType() == 'Polygon');

const heightReference = this.getHeightReference(layer, feature, olGeometry);
Expand Down Expand Up @@ -550,7 +550,7 @@ class FeatureConverter {

for (let i = 0; i < rings.length; ++i) {
const olPos = rings[i].getCoordinates();
const positions = olcsCore.ol4326CoordinateArrayToCsCartesians(olPos);
const positions = ol4326CoordinateArrayToCsCartesians(olPos);
console.assert(positions && positions.length > 0);
if (i == 0) {
hierarchy.positions = positions;
Expand Down Expand Up @@ -707,7 +707,7 @@ class FeatureConverter {
return;
}
const center = olGeometry.getCoordinates();
const position = olcsCore.ol4326CoordinateToCesiumCartesian(center);
const position = ol4326CoordinateToCesiumCartesian(center);
let color;
const opacity = imageStyle.getOpacity();
if (opacity !== undefined) {
Expand Down Expand Up @@ -751,9 +751,9 @@ class FeatureConverter {
};
source.on(['removefeature', 'clear'],
this.boundOnRemoveOrClearFeatureListener_);
let cancellers = olcsUtil.obj(source)['olcs_cancellers'];
let cancellers = obj(source)['olcs_cancellers'];
if (!cancellers) {
cancellers = olcsUtil.obj(source)['olcs_cancellers'] = {};
cancellers = obj(source)['olcs_cancellers'] = {};
}

const fuid = getUid(feature);
Expand Down Expand Up @@ -801,7 +801,7 @@ class FeatureConverter {
opt_newBillboardCallback
) {
console.assert(olGeometry.getType() == 'Point');
olGeometry = olcsCore.olGeometryCloneTo4326(olGeometry, projection);
olGeometry = olGeometryCloneTo4326(olGeometry, projection);

let modelPrimitive = null;
const imageStyle = style.getImage();
Expand Down Expand Up @@ -926,7 +926,7 @@ class FeatureConverter {
}
const options = /** @type {Cesium.optionsLabelCollection} */ ({});

options.position = olcsCore.ol4326CoordinateToCesiumCartesian(extentCenter);
options.position = ol4326CoordinateToCesiumCartesian(extentCenter);

options.text = text;

Expand Down Expand Up @@ -1016,7 +1016,7 @@ class FeatureConverter {
}

let color = outline ? stroke.getColor() : fill.getColor();
color = olcsCore.convertColorToCesium(color);
color = convertColorToCesium(color);

if (outline && stroke.getLineDash()) {
return Cesium.Material.fromType('Stripe', {
Expand Down
12 changes: 6 additions & 6 deletions src/olcs/OLCesium.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import olGeomPoint from 'ol/geom/Point.js';
import {getTransform} from 'ol/proj.js';
import olcsUtil from './util.js';
import olcsCore from './core.js';
import {supportsImageRenderingPixelated, imageRenderingValue} from './util.js';
import {ol4326CoordinateToCesiumCartesian} from './core.js';
import olcsAutoRenderLoop from './AutoRenderLoop.js';
import olcsCamera from './Camera.js';
import olcsRasterSynchronizer from './RasterSynchronizer.js';
Expand Down Expand Up @@ -130,9 +130,9 @@ class OLCesium {
canvasAttribute.value = fillArea;
this.canvas_.setAttributeNode(canvasAttribute);

if (olcsUtil.supportsImageRenderingPixelated()) {
if (supportsImageRenderingPixelated()) {
// non standard CSS4
this.canvas_.style['imageRendering'] = olcsUtil.imageRenderingValue();
this.canvas_.style['imageRendering'] = imageRenderingValue();
}

this.canvas_.oncontextmenu = function() { return false; };
Expand Down Expand Up @@ -409,7 +409,7 @@ class OLCesium {
}

let resolutionScale = this.resolutionScale_;
if (!olcsUtil.supportsImageRenderingPixelated()) {
if (!supportsImageRenderingPixelated()) {
resolutionScale *= window.devicePixelRatio || 1.0;
}
this.resolutionScaleChanged_ = false;
Expand Down Expand Up @@ -706,7 +706,7 @@ class OLCesium {
console.assert(geometry instanceof olGeomPoint);
const coo = geometry.getCoordinates();
const coo4326 = to4326Transform(coo, undefined, coo.length);
return olcsCore.ol4326CoordinateToCesiumCartesian(coo4326);
return ol4326CoordinateToCesiumCartesian(coo4326);
};

// Create an invisible point entity for tracking.
Expand Down
8 changes: 4 additions & 4 deletions src/olcs/RasterSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import olLayerGroup from 'ol/layer/Group.js';
import {getUid, stableSort} from './util.js';
import olcsAbstractSynchronizer from './AbstractSynchronizer.js';
import olcsCore from './core.js';
import {tileLayerToImageryLayer, updateCesiumLayerProperties} from './core.js';

class RasterSynchronizer extends olcsAbstractSynchronizer {
/**
Expand Down Expand Up @@ -77,7 +77,7 @@ class RasterSynchronizer extends olcsAbstractSynchronizer {
* @protected
*/
convertLayerToCesiumImageries(olLayer, viewProj) {
const result = olcsCore.tileLayerToImageryLayer(this.map, olLayer, viewProj);
const result = tileLayerToImageryLayer(this.map, olLayer, viewProj);
return result ? [result] : null;
}

Expand All @@ -97,7 +97,7 @@ class RasterSynchronizer extends olcsAbstractSynchronizer {
// the compiler does not seem to be able to infer this
console.assert(cesiumObjects);
for (let i = 0; i < cesiumObjects.length; ++i) {
olcsCore.updateCesiumLayerProperties(olLayerWithParents, cesiumObjects[i]);
updateCesiumLayerProperties(olLayerWithParents, cesiumObjects[i]);
}
}));
});
Expand Down Expand Up @@ -125,7 +125,7 @@ class RasterSynchronizer extends olcsAbstractSynchronizer {
}

for (let i = 0; i < cesiumObjects.length; ++i) {
olcsCore.updateCesiumLayerProperties(olLayerWithParents, cesiumObjects[i]);
updateCesiumLayerProperties(olLayerWithParents, cesiumObjects[i]);
}

// there is no way to modify Cesium layer extent,
Expand Down
Loading

0 comments on commit d7a4795

Please sign in to comment.