我正在显示一些多边形,但是我想更改执行方式

时间:2019-02-18 11:11:42

标签: javascript html json geojson

我正在以这种方式在地图上显示一些多边形。

var featurecollection = {
  "type": "FeatureCollection",
  "totalFeatures": "unknown",
  "features": [
    {
      "type": "Feature",
      "id": "exm",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -18.216667,
              28.933332
            ],
            [
              -18.416668,
              27.6
            ],
            [
              -17.966667,
              27.383333
            ],
            [
              -17.183332,
              27.8
            ],
            [
              -16.75,
              27.8
            ],
.......................
.......
var geojs_format = new OpenLayers.Format.GeoJSON({
        'internalProjection': new OpenLayers.Projection("EPSG:900913"),
        'externalProjection': new OpenLayers.Projection("EPSG:4326")
    });
           var vector_layer = new OpenLayers.Layer.Vector(); 
           new OpenLayers.Projection("EPSG:4326"),
           map.addLayer(vector_layer);
           vector_layer.addFeatures(geojs_format.read(featurecollection));

它可以工作,但是我的“ var featurecollection = {”的值很大,在我的代码中需要51000行。可以像从file.json这样的项目中删除我的代码中的geojson,然后从那里访问和读取它。

0 个答案:

没有答案