Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

javascript - OpenLayers 6 bad performance vectorlayer containing polygons and linestrings

The problem occurs when I'm displaying more than 2000 polygons and/or linestrings, the map's panning and zooming gets slow, also the loading of the osm tiles gets slow. The problem is gone when there are less features visible in the viewport(zooming in or panning away from features). I don't think it's an styling issue because it also occurs with the standard openlayers styling.

Because of the code snippet's limitations I could only add a few features of the real data to the map, unfortunately the problem isn't visible with this amount of data. But maybe someone can spot something wrong with the code or has a better way of displaying lots of polygons/linestrings on a vectorlayer.

<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/css/ol.css" type="text/css">
    <style>
      .map {
        height: 95vh;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var geoJsonData = {
    "crs": {
        "type": "name",
        "properties": {
            "name": "EPSG:28992"
        }
    },
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            685441.262918955,
                            7022605.59
                        ],
                        [
                            685441.039740355,
                            7022586.08
                        ],
                        [
                            685438.582036506,
                            7022584.54
                        ],
                        [
                            685436.865980189,
                            7022584.1
                        ],
                        [
                            685434.284371417,
                            7022583.44
                        ],
                        [
                            685434.261433221,
                            7022585.66
                        ],
                        [
                            685435.181676638,
                            7022586.01
                        ],
                        [
                            685436.736225901,
                            7022587.56
                        ],
                        [
                            685436.7100026,
                            7022588.07
                        ],
                        [
                            685436.571626044,
                            7022589.15
                        ],
                        [
                            685436.530014489,
                            7022589.94
                        ],
                        [
                            685436.323742369,
                            7022590.91
                        ],
                        [
                            685436.103124509,
                            7022592.1
                        ],
                        [
                            685435.779683307,
                            7022593.02
                        ],
                        [
                            685435.386742883,
                            7022593.68
                        ],
                        [
                            685435.074618194,
                            7022594.1
                        ],
                        [
                            685434.412768294,
                            7022594.54
                        ],
                        [
                            685433.80001363,
                            7022594.9
                        ],
                        [
                            685432.853304886,
                            7022595.19
                        ],
                        [
                            685431.872737418,
                            7022595.44
                        ],
                        [
                            685429.855558338,
                            7022595.36
                        ],
                        [
                            685429.073510219,
                            7022595.47
                        ],
                        [
                            685428.626841421,
                            7022595.77
                        ],
                        [
                            685428.399095635,
                            7022596.29
                        ],
                        [
                            685428.254838334,
                            7022596.83
                        ],
                        [
                            685428.115213326,
                            7022597.8
                        ],
                        [
                            685428.370541637,
                            7022654.54
                        ],
                        [
                            685428.382657063,
                            7022655.68
                        ],
                        [
                            685428.405020634,
                            7022656.21
                        ],
                        [
                            685428.376684955,
                            7022656.68
                        ],
                        [
                            685428.365367803,
                            7022657.18
                        ],
                        [
                            685428.005926213,
                            7022657.85
                        ],
                        [
                            685427.608527838,
                            7022658.09
                        ],
                        [
                            685425.602559711,
                            7022658.13
                        ],
                        [
                            685425.55793753,
                            7022664.88
                        ],
                        [
                            685426.897739616,
                            7022664.88
                        ],
                        [
                            685427.332560588,
                            7022665.02
                        ],
                        [
                            685427.605391799,
                            7022665.61
                        ],
                        [
                            685428.206939893,
                            7022901.65
                        ],
                        [
                            685425.646257605,
                            7022901.4
                        ],
                        [
                            685425.73507516,
                            7022909.73
                        ],
                        [
                            685428.225456642,
                            7022909.64
                        ],
                        [
                            685428.78013709,
                            7022910.08
                        ],
                        [
                            685428.937050443,
                            7022910.73
                        ],
                        [
                            685428.103531107,
                            7022956.32
                        ],
                        [
                            685441.139919701,
                            7022956.91
                        ],
                        [
                            685441.139394247,
                            7022956.39
                        ],
                        [
                            685441.523807046,
                            7022936.19
                        ],
                        [
                            685441.875336024,
                            7022920.72
                        ],
                        [
                            685441.748992747,
                            7022902.63
                        ],
                        [
                            685441.799700934,
                            7022887.07
                        ],
                        [
                            685441.678791454,
                            7022874.18
                        ],
                        [
                            685441.678177743,
                            7022853.82
                        ],
                        [
                            685441.695029443,
                            7022831.97
                        ],
                        [
                            685441.799738679,
                            7022808.98
                        ],
                        [
                            685441.509185026,
                            7022780.18
                        ],
                        [
                            685441.507866647,
                            7022747.26
                        ],
                        [
                            685441.511628204,
                            7022713.25
                        ],
                        [
                            685441.428954069,
                            7022689.88
                        ],
                        [
                            685441.289877033,
                            7022669.03
                        ],
                        [
                            685441.130931211,
                            7022647.89
                        ],
                        [
                            685441.138783873,
                            7022629.88
                        ],
                        [
                            685441.262918955,
                            7022605.59
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            685444.18869203,
                            7022248.82
                        ],
                        [
                            685441.789495138,
                            7022246.66
                        ],
                        [
                            685437.679498426,
                            7022246.43
                        ],
                        [
                            685437.60881564,
                            7022247.46
                        ],
                        [
                            685437.875308075,
                            7022247.45
                        ],
                        [
                            685438.308503048,
                            7022247.44
                        ],
                        [
                            685438.708375331,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I fixed it by using a VectorImageLayer, seems to be a lot faster than a normal VectorLayer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...