From ea346a785dc1b3f7c156f6fc33da634e1f1a627b Mon Sep 17 00:00:00 2001 From: Chris Schlaeger Date: Tue, 12 Aug 2014 21:56:44 +0200 Subject: Adding jquery, flot and openlayers to be included with the GEM. --- misc/openlayers/examples/canvas-inspector.js | 91 ++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 misc/openlayers/examples/canvas-inspector.js (limited to 'misc/openlayers/examples/canvas-inspector.js') diff --git a/misc/openlayers/examples/canvas-inspector.js b/misc/openlayers/examples/canvas-inspector.js new file mode 100644 index 0000000..064b4d5 --- /dev/null +++ b/misc/openlayers/examples/canvas-inspector.js @@ -0,0 +1,91 @@ + +var features = [ + + new OpenLayers.Feature.Vector( + OpenLayers.Geometry.fromWKT( + "LINESTRING(-90 90, 90 -90)" + ), + {color: "#0f0000"} + ), + + new OpenLayers.Feature.Vector( + OpenLayers.Geometry.fromWKT( + "LINESTRING(100 50, -100 -50)" + ), + {color: "#00ff00"} + ) + +]; + +var layer = new OpenLayers.Layer.Vector(null, { + styleMap: new OpenLayers.StyleMap({ + strokeWidth: 3, + strokeColor: "${color}" + }), + isBaseLayer: true, + renderers: ["Canvas"], + rendererOptions: {hitDetection: true} +}); +layer.addFeatures(features); + +var map = new OpenLayers.Map({ + div: "map", + layers: [layer], + center: new OpenLayers.LonLat(0, 0), + zoom: 0 +}); + +var xOff = 2, yOff = 2; + +var rows = 1 + (2 * yOff); +var cols = 1 + (2 * xOff); + +var template = new jugl.Template("template"); +template.process({ + clone: true, + parent: "inspector", + context: { + rows: rows, + cols: cols + } +}); + +function isDark(r, g, b, a) { + a = a / 255; + var da = 1 - a; + // convert color values to decimal (assume white background) + r = (a * r / 255) + da; + g = (a * g / 255) + da; + b = (a * b / 255) + da; + // use w3C brightness measure + var brightness = (r * 0.299) + (g * 0.587) + (b * 0.144); + return brightness < 0.5; +} + +var context = layer.renderer.canvas; //layer.renderer.hitContext; +var size = map.getSize(); +map.events.on({ + mousemove: function(event) { + var x = event.xy.x - 1; // TODO: fix this elsewhere + var y = event.xy.y; + if ((x >= xOff) && (x < size.w - xOff) && (y >= yOff) && (y < size.h - yOff)) { + var data = context.getImageData(x - xOff, y - yOff, rows, cols).data; + var offset, red, green, blue, alpha, cell; + for (var i=0; iG: " + green + "
B: " + blue + "
A: " + alpha; + cell.style.backgroundColor = "rgba(" + red + ", " + green + ", " + blue + ", " + (alpha / 255) + ")"; + cell.style.color = isDark(red, green, blue, alpha) ? "#ffffff" : "#000000"; + } + } + } + } +}); + + -- cgit v1.2.3