0
votes

I am getting line latitude & longitude as

LINESTRING(1491215.4689647 6893983.2031826,1494163.0718675 6894785.7919795)

after seeing this solution. how to get points return from OpenLayers.Control.DrawFeature

Now what I want to do is that I want to display start point & end point on my web page. So how can I extract latitude & longitude from here so that I can show it in my page.

2

2 Answers

0
votes

If your linestring is already in OpenLayers, there is no reason to convert it to WKT. Linestring geometry contains array of Points. You can access components of geometry in several ways, for example:

drawControls[key].events.register('featureadded', drawControls[key], function(f) {

    // First point
    var firstPointGeom = f.feature.geometry.components[0].clone();

    // Last point
    var secondPointGeom = f.feature.geometry.components[f.feature.geometry.components.length - 1].clone();

    // Now you got geometries, let's create features from them...
    var firstPointFeat = new OpenLayers.Feature.Vector(firstPointGeom);
    var secondPointGeom = new OpenLayers.Feature.Vector(secondPointGeom);

    yourVectorLayer.addFeatures([firstPointFeat, secondPointGeom]);

});

Pay attention - this works with LineStrings. Probably it's not necessary to go into detail about clone(), it's up to particular use case, whether you need it, or you can use just var firstPointGeom = f.feature.geometry.components[0];

0
votes

Thats WKT format, you're looking at. You'll potentially need to reproject those coordinates to the target projection if they are not in the same projection. After than, you should be able ot ask openlayers for the points of any given geometry using the base geometry functionaily. Get the point array from the linestring instance and iterate over it. Make sure you know the right coordinate order for your projection / data model.

Hope that helps!