1

Trying to find the best way to take the current map view extent

const extent = mapView.calculateExtent();

and get a WKT from that value. i thought i might be able to take that extent, convert it into a polygon:

const poly =  fromExtent(mapExt);

and then somehow get the geometry from that polygon and convert to wkt like so:

const wktFormat = new WKT();
const polyGeom = //get geometry from poly here?
const ret = wktFormat.writeGeometry(polyGeom, {
  dataProjection: 'EPSG:4326',
  featureProjection: 'EPSG:3857'
});

but i'm not able to find a good way to do that. Am i missing a step?

2
  • that link doesn't help. It only says to use mapView.calculateExtent(), which i already show i'm using above. I have the extent, i need to either a) find a way to convert extent into a geometry, or b) find a way to translate an extent into WKT. Either one is fine for me. There was a comment in your link about using .ToGeometry().ToString(), but that method doesn't exist in OL 5
    – Phil
    Nov 18, 2018 at 15:24

1 Answer 1

1

You can transform your extent to a polygon using ol.geom.Polygon.fromExtent().

You can try something like this:

var e = map.getView().calculateExtent();
var wkt = format.writeGeometry(ol.geom.Polygon.fromExtent(e), {
    dataProjection: 'EPSG:4326',
    featureProjection: 'EPSG:3857'
});
console.log(wkt);
1
  • thanks, i was getting hung up apparently cause i thought i had to run getGeometry on the polygon
    – Phil
    Nov 18, 2018 at 18:13

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.