javascript - How to get a pixel's color value from an Openlayers 3 layer? -
is there way read pixel color values of openlayers 3 layer? this:
layerid.getpixelcolor(x, y); i'm aware of getimagedata() method used canvas, far can see, allows proper color values of top layer 100% alpha.
i want colors lower or hidden layers. (wms tiles same domain.)
you can set postcompose handler directly on layer , read pixel value there. made small example based on layer spy example:
imagery.on('postcompose', function(event) { var ctx = event.context; var pixelratio = event.framestate.pixelratio; if (mouseposition) { var x = mouseposition[0] * pixelratio; var y = mouseposition[1] * pixelratio; var data = ctx.getimagedata(x, y, 1, 1).data; var color = 'rgb(' + data[0] + ',' + data[1] + ','+ data[2] + ')'; $('#box').css('background-color', color); } }); http://jsfiddle.net/m1abjrkm/1/
you might interested in ol.map.html#hasfeatureatpixel.
Comments
Post a Comment