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 #998 - ol layer vectorImage is not rendered #1005

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions examples/vectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
onclick="javascript:toggleStyle()" /></div>
<div><input type="button" value="Add/remove one vector layer"
onclick="javascript:addOrRemoveOneVectorLayer()" /></div>
<div><input type="button" value="Add/remove one vector image layer"
onclick="javascript:addOrRemoveOneVectorImageLayer()" /></div>
<div><input type="button" value="Add/remove one feature"
onclick="javascript:addOrRemoveOneFeature()" /></div>
<div><input type="button" value="Toggle clampToGround mode"
Expand Down
17 changes: 17 additions & 0 deletions examples/vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import olGeomPolygon from 'ol/geom/Polygon.js';
import olInteractionDragAndDrop from 'ol/interaction/DragAndDrop.js';
import olGeomMultiPolygon from 'ol/geom/MultiPolygon.js';
import olLayerVector from 'ol/layer/Vector.js';
import olLayerVectorImage from 'ol/layer/VectorImage.js';
import {transform} from 'ol/proj.js';
import olcsCore from 'olcs/core.js';
import {OLCS_ION_TOKEN} from './_common.js';
Expand Down Expand Up @@ -278,6 +279,11 @@ const vectorLayer = new olLayerVector({
source: vectorSource
});

const vectorImageLayer = new olLayerVectorImage({
style: styleFunction,
source: vectorSource
});

const vectorSource2 = new olSourceVector({
features: [iconFeature, textFeature, cervinFeature, ...modelFeatures, cartographicRectangle,
cartographicRectangle2]
Expand Down Expand Up @@ -358,6 +364,17 @@ window['addOrRemoveOneVectorLayer'] = function() {
hasTheVectorLayer = !hasTheVectorLayer;
};

let hasTheVectorImageLayer = false;
window['addOrRemoveOneVectorImageLayer'] = function() {

if (hasTheVectorImageLayer) {
map.getLayers().remove(vectorImageLayer);
} else {
map.getLayers().insertAt(2, vectorImageLayer);
}
hasTheVectorImageLayer = !hasTheVectorImageLayer;
};

window['addOrRemoveOneFeature'] = function() {
const found = vectorSource2.getFeatures().indexOf(iconFeature);
if (found === -1) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ol-cesium",
"version": "2.13.1",
"name": "@inveni/ol-cesium",
"version": "0.00.1",
Comment on lines +2 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this.

"description": "OpenLayers Cesium integration library",
"scripts": {
"build-examples": "cross-env NODE_ENV=production TARGET=examples webpack --progress --bail",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@mapbox/geojsonhint": "^3.0.1",
"@types/webpack": "^5.28.0",
"babel-loader": "8.2.2",
"cesium": "^1.81.0",
"cesium": ">=1.81.0 <=1.97.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, see #1004.

"copy-webpack-plugin": "^9.0.0",
"cross-env": "7.0.3",
"eslint": "^7.26.0",
Expand Down
13 changes: 11 additions & 2 deletions src/olcs/VectorSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import olLayerVector from 'ol/layer/Vector.js';
import olLayerVectorTile from 'ol/layer/VectorTile.js';
import olcsAbstractSynchronizer from './AbstractSynchronizer.js';
import olcsFeatureConverter from './FeatureConverter.js';
import olLayerVectorImage from 'ol/layer/VectorImage.js';

class VectorSynchronizer extends olcsAbstractSynchronizer {
/**
Expand Down Expand Up @@ -99,8 +100,16 @@ class VectorSynchronizer extends olcsAbstractSynchronizer {
* @inheritDoc
*/
createSingleLayerCounterparts(olLayerWithParents) {
const olLayer = olLayerWithParents.layer;
if (!(olLayer instanceof olLayerVector) || olLayer instanceof olLayerVectorTile) {
let olLayer = olLayerWithParents.layer;

if(olLayerWithParents.layer instanceof olLayerVectorImage){
let convertedVectorLayer = new olLayerVector({source: null});
convertedVectorLayer.setStyle(olLayerWithParents.layer.getStyle())
convertedVectorLayer.setSource(olLayerWithParents.layer.getSource())
olLayer = convertedVectorLayer;
Comment on lines +106 to +109
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please directly pass source and style as constructor parameter.
Notably, see https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix it next week

}

if (!(olLayer instanceof olLayerVector) || olLayer instanceof olLayerVectorTile || olLayer instanceof olLayerVectorImage) {
return null;
}
console.assert(olLayer instanceof olLayerLayer);
Expand Down