简体   繁体   English

如何在openlayers中获得线的经度和纬度

[英]how to get longitude & latitude of line in openlayers

I am getting line latitude & longitude as 我正在获得线纬度和经度

LINESTRING(1491215.4689647 6893983.2031826,1494163.0718675 6894785.7919795) 换行(1491215.4689647 6893983.2031826,1494163.0718675 6894785.7919795)

after seeing this solution. 看到这个解决方案之后。 how to get points return from OpenLayers.Control.DrawFeature 如何从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. 因此,如何从此处提取纬度和经度,以便可以在页面中显示它。

Thats WKT format, you're looking at. 这就是WKT格式,您正在查看。 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. 之后,您应该可以使用基本几何图形向openlayer询问任何给定几何图形的点。 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! 希望有帮助!

If your linestring is already in OpenLayers, there is no reason to convert it to WKT. 如果您的线串已经在OpenLayers中,则没有理由将其转换为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. 注意-这适用于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]; 也许没有必要详细介绍clone() ,它取决于特定的用例,无论您是否需要它,也可以只使用var firstPointGeom = f.feature.geometry.components[0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM