简体   繁体   English

Openlayers可以实时简化线串功能

[英]Openlayers simplify linestring features on the fly

I have an issue on my OpenLayers openstreetmaps where I am loading LineString features from a kml file. 我在OpenLayers openstreetmaps上遇到一个问题,该问题是我从kml文件加载LineString功能。 Everything works fine except performance due to the sheer complexity of the LineString and the number of linestrings. 由于LineString的复杂性和线串的数量,除性能外,其他一切工作正常。 I wanted to use the simplyfy() function to simplify the linestring geometry/feature. 我想使用simplefy()函数简化线串的几何形状/功能。 Here is some code I wrote to simplify on the fly. 这是我为简化运行而编写的一些代码。 The problem is in the line of code below: 问题在下面的代码行中:

            feature.geometry.components[i].simplify(0.1);

This does not seem to modify the original geometry feature components at all. 这似乎根本没有修改原始的几何特征组件。 What am I doing wrong? 我究竟做错了什么? I think we might need to use removeComponents and then add the simplified geometries using addComponents() but how to do this? 我认为我们可能需要使用removeComponents,然后使用addComponents()添加简化的几何体,但是该怎么做呢?

preFeatureInsert: function(feature) preFeatureInsert:功能(功能)

{
    if (feature != "undefined" && feature.geometry != "undefined" && feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Collection");
    {
        if (feature.geometry.components != "undefined" && typeof(feature.geometry.components) != "undefined")
        {
            for (var i = 0; i < feature.geometry.components.length; i++)
            {
                if (feature.geometry.components[i].CLASS_NAME ==  "OpenLayers.Geometry.LineString")
                {
                    feature.geometry.components[i].simplify(0.1);
                }
            }
        }                           
    }
} 

The simplify function returns a simplified version of the component and does not modify the component itself. 简化函数返回组件的简化版本,并且不修改组件本身。 Within your loop you can set the component as needed: 在循环中,您可以根据需要设置组件:

feature.geometry.components[i] = feature.geometry.components[i].simplify(0.1);

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

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