[OpenLayers-Users] ImageLayer for dynamically generated images

Arnd Wippermann arnd.wippermann at web.de
Mon Oct 24 12:17:51 EDT 2011


Hi,

You can use the javascript object Image() to get the size of an image.

Add the Image Layer to your map, perhaps with a blank image and use
something like below 
to retrieve your images and replace the previous of the Image Layer.

...
theImg = new Image();
theImg.onload = addImageLayer;
theImg.src = arrImages[imgCounter];
...

function addImageLayer()
{
    theWidth = theImg.width;
    theHeight = theImg.height;
    originX   = 0;
    originY   = 0;
    bounds    = new OpenLayers.Bounds(originX, originY, theWidth,
theHeight);

    //map.setCenter(new OpenLayers.LonLat(theWidth/2,theHeight/2),0);
    map.zoomToExtent(bounds);

    imageLayer.url=theImg.src;
    imageLayer.extent=new OpenLayers.Bounds(originX, originY, theWidth,
theHeight);
    imageLayer.attribution = theImg.src.replace(/^.*\/(.*)$/,"$1");
    imageLayer.setVisibility(false);
    imageLayer.setVisibility(true);
    $("Msg").innerHTML = "onload:" + imgCounter + ", " + theImg.src;

}

Example:
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL210/Swap%20Image%20Url/swap_ima
ge_url.asp
 

You need not only the size of the image, you need also the insert point of
the image. Above I use 0,0.

May be it's possible to add a function to the Image Layer Class, that use
onload to get the image and the size.

Arnd


-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von "Stefan
Jänicke"
Gesendet: Montag, 24. Oktober 2011 11:04
An: remi; users at openlayers.org
Betreff: Re: Re:[OpenLayers-Users] ImageLayer for dynamically generated
images

Hi Remi.

For sure, that is a possibility. But the problem is that I perform a request
to a Contentserver2 instance, which receives the desired width and computes
needed height of the image. I don't want to perform 2 requests (1 for image
size, 1 for ImageLayer), since effort in Contentserver takes 1-2 seconds per
request.

So is there a 1-request-way with OpenLayers for me?

Thanks,
Stefan.

-------- Original-Nachricht --------
> Datum: Sun, 23 Oct 2011 07:57:36 +0800
> Von: remi <remiglobal at gmail.com>
> An: "&quot,Stefan Jänicke&quot," <stefan.jaenicke at gmx.de>
> Betreff: Re:[OpenLayers-Users] ImageLayer for dynamically generated 
> images

> You can always use ur server side scripting language to get the size 
> of your image. For example, in php, u can use gd extension to get the 
> size of the image.
> On Oct 22, 2011 11:41 PM, "&quot;Stefan Jänicke&quot;" < 
> stefan.jaenicke at gmx.de> wrote:

-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!

Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list