[GIS] OpenLayers 3 how to keep original image extent

imagejavascriptopenlayers

I'm new at ol3, I'm trying to display my GIS view by updating my ol2 code.

I created the projection and I can display my static image but I'm obliged to use local extent [0, 0, 1024, 968] instead of my image extent [44823.715846278064, 66102.38217556383, 49823.715846278064, 71102.38217556383] otherwise I get a blank screen. In ol2 I made my bounds with the original datas and everything worked fine :/

here the new code :

    var extent = [0, 0, 1024, 968];
    var projection = new ol.proj.Projection({
                       units: 'pixels',
                       extent: extent
                     });

    MAP = new ol.Map({
              target: target,
              view: new ol.View({
                  projection: projection,
                  center: ol.extent.getCenter(extent),
                  zoom: 2
              })
          );

   var imageProjection = new ol.proj.Projection({ 
                            units: 'pixels',
                            extent: [0, 0, 1024, 968]
                         });

   var graphic = new ol.layer.Image({
                        source: new ol.source.ImageStatic({
                            url: layerData,
                            projection: imageProjection,
                            imageExtent: [0, 0, 1024, 968]
                        })
                 });

   MAP.addLayer(graphic);

I need to keep the original extent to communicate with my server to generate the good image when moveend happens. I tried to use an EPSG:4326 projection but it doesn't work. I'm missing something but I don't know where.

Best Answer

Had the same problem and finally found the answer (not sure where). Here's what worked for me:

var ovProj = ol.proj.get('EPSG:3857');
...
source: new ol.source.ImageStatic({
        url: "images/MAP/DYNAMIC/T_1.png",
        imageSize: [1239,748],
        imageExtent: [-14483048.340, 2291674.487,-6775420.041, 6947393.399],
        projection: ovProj 
})
...

The examples in OL3 aren't expecting one to use a geo-referenced static image in the view for the map, though one could do this in OL2 previously. So, for OL3, you have to specify the map projection of the image differently than one had to before in the layer declaration. Looks like you would use the max values in your extent for the imageSize. Hope this is what you were looking for.