1

I'm trying to get a satellite image from GeoServer. I've specified the extent and projection that was given in the URL (not shown in the code). But when it renders, the image is nearly invisible and put to the corner, which means that the view(?) didn't consider the extent, center, and zoom that was specified. I've broken down the code be more specific. Does anybody know how to fix this problem?


var projection = new ol.projection({
  code: "EPSG:25832",
  units: "m"
});

var img_source = new ol.source.Tilewms({ url: "http://localhost:8080/geoserver/basic/wms" params: { "LAYERS": "" } //this was specified in my actual code });

var extent = [ minX, minY, maxX, maxY ]; //taken from URL and specified in code var x_center = (extent[0] + extent[2]) / 2; var y_center = (extent[1] + extent[3]) / 2;

var view = new ol.view({ center: [x_center, y_center], zoom: 12, });

var layer = new ol.layer.tile({ visible: true, source: img_source, extent: extent, projection: projection });

const map = new ol.map({ layers: [ layer ], extent: extent, view: view });

1

You need to set the projection of the map not the layer. Or if you want the map to be in the default projection then just leave the layer in the same projection and geoserver will handle the reprojection for you.

  • How do I set the projection of the map? It's not an option on ol.Map – JayKay_90 Aug 10 '17 at 13:07
  • Move the projection line to the map block – Ian Turton Aug 10 '17 at 13:08
  • It worked but it has to be under view – JayKay_90 Aug 10 '17 at 13:28
  • That may be a ol4 thing – Ian Turton Aug 10 '17 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.