简体   繁体   English

Kinetic.js-图片未显示

[英]Kinetic.js - Images not showing up

I am building an app which should show different types of graphs. 我正在构建一个应显示不同类型图形的应用程序。 One should show two or more images positioned by the scores the user did. 一个应该显示两张或更多张按用户得分位置定位的图像。 Okay that has nothing to do with the problem. 好的,这与问题无关。 So I wrote a jQuery plugin which receives values via json to draw the graphs. 所以我写了一个jQuery插件,它通过json接收值来绘制图形。

The plugin first calls a function which draws the Lines of the graph (working) another function draws the grid behind the graph (also working). 该插件首先调用一个绘制图形线条的函数(有效),另一个函数绘制图形后面的网格(有效)。

Now the problem: the main part loops over the array of values and adds Kinetic.image objects to a layer wich is returned und added to the stage.: 现在的问题是:主体部分遍历值数组,并将Kinetic.image对象添加到返回到层中的层并添加到舞台上。

$.each(this.data, function(key, value) {
            $.each(value, function(secKey, secValue){
                secValue.X = Math.floor((secValue.X - minX) * scaleX) + xOffset;
                secValue.Y = Math.floor(yOffset + ((minY - secValue.Y) * scaleY));
                coords.push(secValue);
            });
        });

        $.each(coords, function(key, value){
            var imageObj = new Image();
            imageObj.src = value.image;
            imageObj.onload = function() {
                var image = new Kinetic.Image({
                    x: value.X,
                    y: value.Y,
                    image: imageObj,
                    width: 180,
                    height: 180
                });

            // add the shape to the layer
            pictures.add(image);

            };
        });

        return Array(pictures, popup);

At the end the the rendered page has 4 canvas objects. 最后,渲染的页面具有4个画布对象。 And also when I console.log() the stage there are the layers for graph, grid, pictures and popup in it, but whats not shown are the images. 而且,当我在console.log()舞台上时,其中包含用于图形,网格,图片和弹出窗口的图层,但是图像未显示。 The sources of the images are available. 图像来源可用。 Checked this several times. 检查了几次。

Does anyone have a hint where the problem could be.? 有没有人暗示问题可能在哪里?

Thanks in advance. 提前致谢。

Matthias 马蒂亚斯

have you confirmed that imageObj.onload is being executed? 您已确认正在执行imageObj.onload吗? It's standard practice to set the source of the imageObj after defining the imageObj onload function due to browser caching. 由于浏览器缓存的原因,在定义imageObj onload函数之后,设置imageObj的源是标准做法。

Next, you'll also want to be sure to redraw the layer whenever the images have been loaded with layer.draw(); 接下来,您还需要确保每当用layer.draw();加载图像时都重新绘制该层。 Recall that KineticJS layers don't auto redraw whenever things change for performance reasons 回想一下,由于性能原因一旦发生变化,KineticJS图层不会自动重绘

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

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