Let image resolution be calculated when the image loads
This commit is contained in:
@@ -34,8 +34,16 @@
|
|||||||
<h4 id="title">Static image example</h4>
|
<h4 id="title">Static image example</h4>
|
||||||
<p id="shortdesc">Example of a static image layer.</p>
|
<p id="shortdesc">Example of a static image layer.</p>
|
||||||
<div id="docs">
|
<div id="docs">
|
||||||
<p>Source: <a href="http://xkcd.com/256/">xkcd.com/256/</a></p>
|
<p>
|
||||||
<p>See the <a href="static-image.js" target="_blank">static-image.js source</a> to see how this is done.</p>
|
This example uses a <a href="http://xkcd.com/256/">static image</a>
|
||||||
|
as a layer source. The map view is configured with a custom
|
||||||
|
projection that translates image coordinates directly into map
|
||||||
|
coordinates.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
See the <a href="static-image.js" target="_blank">static-image.js source</a>
|
||||||
|
for details on how this is done.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="tags">static image, xkcd</div>
|
<div id="tags">static image, xkcd</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ goog.require('ol.proj.Projection');
|
|||||||
goog.require('ol.source.ImageStatic');
|
goog.require('ol.source.ImageStatic');
|
||||||
|
|
||||||
|
|
||||||
// Maps always need a projection, but the static image is not geo-referenced,
|
// Map views always need a projection. Here we just want to map image
|
||||||
// and are only measured in pixels. So, we create a fake projection that the
|
// coordinates directly to map coordinates, so we create a projection that uses
|
||||||
// map can use to properly display the layer.
|
// the image extent in pixels.
|
||||||
var pixelProjection = new ol.proj.Projection({
|
var extent = [0, 0, 1024, 968];
|
||||||
code: 'pixel',
|
var projection = new ol.proj.Projection({
|
||||||
|
code: 'xkcd-image',
|
||||||
units: 'pixels',
|
units: 'pixels',
|
||||||
extent: [0, 0, 1024, 968]
|
extent: extent
|
||||||
});
|
});
|
||||||
|
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
@@ -26,16 +27,15 @@ var map = new ol.Map({
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
url: 'http://imgs.xkcd.com/comics/online_communities.png',
|
url: 'http://imgs.xkcd.com/comics/online_communities.png',
|
||||||
imageSize: [1024, 968],
|
projection: projection,
|
||||||
projection: pixelProjection,
|
imageExtent: extent
|
||||||
imageExtent: pixelProjection.getExtent()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new ol.View({
|
view: new ol.View({
|
||||||
projection: pixelProjection,
|
projection: projection,
|
||||||
center: ol.extent.getCenter(pixelProjection.getExtent()),
|
center: ol.extent.getCenter(extent),
|
||||||
zoom: 2
|
zoom: 2
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user