简体   繁体   English

如何使用openlayers3为Image png设置动画

[英]How to animate Image png with openlayers3

I need to implement a function with openlayers-3. 我需要用openlayers-3实现一个功能。 Description:There are a series of images .png. 描述:有一系列的图像.png。 I need to play them like a animation.I set the image source as ImageStatic,but When I set the current image visible is false ,it doesn't work. 我需要像动画一样播放它们。我将图像源设置为ImageStatic,但是当我将当前图像设置为visible时,它将不起作用。 the visible property seems like not work. 可见属性似乎不起作用。 Code: 码:

  var extent = [0, 0, 418, 600]; var projection = new ol.proj.Projection({ code: 'xkcd-image', units: 'pixels', extent: extent }); var map = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Group({ layers: [ new ol.layer.Image({ source: new ol.source.ImageStatic({ url: 'http://localhost:2265/images3/test2.png', projection: projection, imageExtent: extent, }) }), new ol.layer.Image({ source: new ol.source.ImageStatic({ url: 'http://localhost:2265/images2/test1.png', projection: projection, imageExtent: extent, }) }) ] }) ], target: 'map', view: new ol.View({ projection: projection, center: ol.extent.getCenter(extent), zoom: 2, maxZoom: 8 }) }); var layers = map.getLayers().getArray(); var frame = 1; setInterval(function () { layers[frame].setVisible = false; frame = (frame + 1) % 2; layers[frame].setVisible = true; },500); 

map.layers[ 1 ] is a group, to get the image layers try: map.layers [ 1 ]是一个组,要获取图像层,请尝试:

var layers = map.getLayers().getArray()[1].getLayers().getArray();

You can also do 'real' animation by rendering directly to the canvas: 您还可以通过直接渲染到画布上来制作“真实”动画:

http://openlayers.org/en/latest/examples/feature-move-animation.html http://openlayers.org/en/latest/examples/flight-animation.html http://openlayers.org/en/latest/examples/feature-move-animation.html http://openlayers.org/en/latest/examples/flight-animation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM