Function on of openlayers in Typescript

Asked

Viewed 19 times

0

I’m learning to use openlayers along with Angular 6, but one of the OL event functions. on is not recognized by TS, has some other way to do it than in the conventional way?

this.imagery.on('postcompose', function(event: ol.render.Event){
  console.log("postcompose");
  var ctx = event.context;
  ctx.restore();
});

He points out the error

Type '(event: Event) => void' is not assignable to type '(evt: Event) => boolean'.
Types of parameters 'event' and 'evt' are incompatible.
Type 'ol.events.Event' is not assignable to type 'ol.render.Event'.

If I use Event normally it does not have the context property I need...

  • Tries npm install --save @types/openlayers

  • I’m already using this version :/ , the map is being loaded normally, I was able to draw Features among other things, only this function does not work and n find a solution for this...

  • So... but I told you to install @types/openlayers and not openlayers... Actually you should install both.

  • But your mistake is another in fact

1 answer

0

Try the following

this.imagery.on('postcompose', function(event: ol.events.Event){
  console.log("postcompose");
  var ctx = event.context;
  ctx.restore();
  return true;
});
  • At first came to compile at least, after using for a few moments he gave the same error again...

  • i edited the answer pq tb has the following: the event has to be the ol.events.Event and not ol.render.Event, as you put in your code.

  • Yes, but I needed the context of Event, so I discovered that ol.render.Event had this property, for more reference I was following an example of Openlayers http://openlayers.org/en/latest/examples/layer-spy.html?q=spyitself

Browser other questions tagged

You are not signed in. Login or sign up in order to post.