Skip to content

Instantly share code, notes, and snippets.

@tsauerwein
Created March 19, 2013 09:44
Show Gist options
  • Save tsauerwein/5194835 to your computer and use it in GitHub Desktop.
Save tsauerwein/5194835 to your computer and use it in GitHub Desktop.
Shows an OpenLayers image layer in grayscale, a combination of these two examples: http://openlayers.org/dev/examples/image-layer.html http://openlayers.org/dev/examples/osm-grayscale.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Image Layer Example</title>
<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
<style type="text/css">
p.caption {
width: 512px;
}
</style>
<script src="http://openlayers.org/dev/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map('map');
var graphic = new OpenLayers.Layer.Image(
'City Lights',
'4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288),
{
numZoomLevels: 3,
eventListeners: {
loadend: function(evt) {
var tile = evt.object.tile;
var ctx = tile.getCanvasContext();
if (ctx) {
var imgd = ctx.getImageData(0, 0, tile.size.w, tile.size.h);
var pix = imgd.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
pix[i] = pix[i + 1] = pix[i + 2] = (3 * pix[i] + 4 * pix[i + 1] + pix[i + 2]) / 8;
}
ctx.putImageData(imgd, 0, 0);
tile.imgDiv.removeAttribute("crossorigin");
tile.imgDiv.src = ctx.canvas.toDataURL();
}
}
}
}
);
graphic.events.on({
loadstart: function() {
OpenLayers.Console.log("loadstart");
},
loadend: function() {
OpenLayers.Console.log("loadend");
}
});
var jpl_wms = new OpenLayers.Layer.WMS(
"Global Imagery",
"http://demo.opengeo.org/geoserver/wms",
{layers: "bluemarble"},
{maxExtent: [-160, -88.759, 160, 88.759], numZoomLevels: 3}
);
map.addLayers([graphic, jpl_wms]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<h1 id="title">Image Layer Example</h1>
<div id="tags">
image, imagelayer
</div>
<p id="shortdesc">
Demonstrate a single non-tiled image as a selectable base layer.
</p>
<div id="map" class="smallmap"></div>
<div id="docs">
<p class="caption">
The "City Lights" layer above is created from a single web accessible
image. If you construct it without any resolution related options,
the layer will be given a single resolution based on the extent/size.
Otherwise, it behaves much like a regular layer. This is primarily
intended to be used in an overview map - where another layer type
might not make a good overview.
</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment