[GIS] How to get coordinates of Drag Box using OpenLayers 3

coordinatesopenlayers

I'm pretty new to From Openlayers and I have a problem. I can draw a rectangle using DragBox on my OpenLayers 3 map. How can I get its coordinates? I tried getGeometry() but it returns 'null'. I think I just added the 'drawing dragbox feature' to my map and I am not creating an actual rectangle. I am going to use the area inside these coordinates later. Here is my code:


        boxControl =new ol.interaction.DragBox
        ({
            condition: ol.events.condition.altKeyOnly,
            style: new ol.style.Style
            ({
                stroke: new ol.style.Stroke({color: [0, 0, 255, 1]})
            })
        });
        map.addInteraction(boxControl);

OpenLayers 3 is pretty new and most of the resources on the web are for 2.x and I couldn't find any help.

Best Answer

I think I found the answer. There is a Question here

So I wrote:

boxControl.on('boxend', function () 
{
      var a= boxControl.getGeometry().getCoordinates();
      $('#taOzet').text(a); 
});

and it's returned:

3524005.462580891,4941742.299355211, 3524005.462580891,4609088.352258123, 4069460.0964239086,4609088.352258123, 4069460.0964239086,4941742.299355211, 3524005.462580891,4941742.299355211

there are 5 points with x-y coordinates also 1st and 5th ones are same, so they make a polygon, in my case a rectangle! Thanks again.

Related Question