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

vectorlayer created in another class can't be seen in cesium but can be seen in openlayers #1068

Open
Irresistiblea opened this issue Jul 4, 2023 · 1 comment
Labels

Comments

@Irresistiblea
Copy link

In my project all vectorlayers should be created by a factory class and then added to olcesium, it is confusing to see that layers defined in the same class then added to map at once can be seen both in openlayers and cesium, but if the layers were created elsewhere(like factory class), they can't be loaded in cesium, like the example below:

layer doesn't show in cesium, but can be seen in openlayers:

// use factory class to create vectorlayer
export default class FactoryClass{
  public static getLayer(){
    let _layer: any = new VectorLayer({
      source: new VectorSource({
        format: new GeoJSON(),
        url: 'some url'
      })
    });
    return _layer;
  }
}

//  a class initialize openlayers and olcesium
export class A {
  this.map = new Map({
    target: "map",
    layers: [],
    view: new View({
      center: fromLonLat([0, 0]),
      zoom: 12,
    }),
    controls: [],
  })
  
  this.integratedMap = new OLCesium({map: this.map});
  this.map2d = this.integratedMap.getOlMap();
 
  let layer = FactoryClass.getLayer();
  this.map2d.addLayer(layer); // doesn't show in cesium 
}

however this works both in openlayers and cesium:

export class A {
  this.map = new Map({
    target: "map",
    layers: [],
    view: new View({
      center: fromLonLat([0,0]),
      zoom: 12,
    }),
    controls: [],
  })

  this.integratedMap = new OLCesium({map: this.map});
  this.map2d = this.integratedMap.getOlMap();

  let _layer: any = new VectorLayer({
    source: new VectorSource({
      format: new GeoJSON(),
      url: 'some url'
    })
  });

  this.map2d.addLayer(_layer); // show correctly in openlayers and cesium
}

why does this happen? how can i fix this so that i can use factory class to create vectorlayers and make them both shown in openlayers and cesium?

@gberaudo
Copy link
Member

Hi @Irresistiblea , OL-Cesium detects and then transform the type of layer by using instanceof. Your application must be duplicating some OpenLayers classes so the layers are not recognized.

It looks like a packaging problem on your side, which is not caused by OL-Cesium.

I will keep your issue opened so that we add some section to the documentation that explains how one gets in that situation.

@gberaudo gberaudo added the doc label Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants