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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -