Openlayers:GeoJSON 和坐标

Openlayers: GeoJSON and Coordinates

我正在尝试解析 GeoJSON 数据并在 ESPG:4326 地图上绘制 'Points',并取得了一些成功。它在地图上绘制 'Point',但在默认设置 [0, 0] 上。我是 Openlayers 的新手。我还让我的 geojson 通过了两个验证器,它们没有错误地返回。我下面的代码是一个 .js 文件。

我以前在更改地图的 'center' 时遇到过类似的问题,我使用 'fromLonLat' 解决了这个问题。我假设有某种涉及 'fromLonLat' 的解决方案,但我在 Openlayers 6 的任何地方都找不到与此相关的任何内容。

import Feature from 'ol/Feature';
import Map from 'ol/Map';
import View from 'ol/View';
import GeoJSON from 'ol/format/GeoJSON';
import Point from 'ol/geom/Point';
import {fromLonLat} from 'ol/proj';
import {defaults as defaultInteractions, DragRotateAndZoom} from 'ol/interactio$
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
import {OSM, Vector as VectorSource} from 'ol/source';
import {Circle as CircleStyle, Fill, Stroke, Style} from 'ol/style';

var image = new CircleStyle({
  fill: new Fill({
        color: 'rgba(255, 0, 0, 1)'
        }),
  radius: 5,
  stroke: new Stroke({color: 'red', width: 1})
});


var markerStyle = {
  'Point': new Style({
    image: image
  })
};


var styleFunction = function(feature) {
  return markerStyle[feature.getGeometry().getType()];
};

var geojsonObject = {
   'type': 'FeatureCollection',
   'crs': {
       'type': 'name',
       'properties': {
        'name': 'ESPG:4326'
        }
  },
   'features': [
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.65, 54.34]
    },
    'properties': {
    'Site':'ARMAGH'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.86, 54.6]
    },
   'Site':'BELFAST EAST'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.97, 54.56]
    },
    'properties': {
    'Site':'BELFAST BALMORAL'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.27, 54.86]
    },
    'properties': {
    'Site':'BALLYMENA TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.26, 54.35]
    },
    'properties': {
    'Site':'BANBRIDGE TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.67, 54.65]
    },
    'properties': {
    'Site':'BANGOR REPEATER STATION'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.38, 55.09]
    },
    'properties': {
    'Site':'CREGAGH'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point','properties': {
    'Site':'BANBRIDGE TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.67, 54.65]
    },
    'properties': {
    'Site':'BANGOR REPEATER STATION'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.38, 55.09]
    },
    'properties': {
    'Site':'CREGAGH'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.66, 55.13]
    },
    'properties': {
    'Site':'COLERAINE REPEATER STATION'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.76, 54.50]
    },
    'properties': {
    'Site':'DUNGANNON'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.70, 54.32]
    },
    'properties': {
    'Site':'DOWNPATRICK TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-7.64, 54.34]
    },
    'properties': {
    'Site':'ENNISKILLEN'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.95, 54.66]
    },
    'properties': {
    'Site':'GLENGORMLEY'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.83374, 54.59279]
    },
    'properties': {
    'Site':'BELFAST KNOCK'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-7.30, 54.99]
    },
    'properties': {
    'Site':'LONDONDERRY MEG'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.82, 54.85]
    },
    'properties': {
    'Site':'LARNE TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.95, 55.05]
    },
    'properties': {
    'Site':'LIMAVADY'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.05, 54.51]
    },
    'properties': {
    'Site':'LISBURN'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.34, 54.45]
    },
    'properties': {
    'Site':'LURGAN'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.96, 54.55]
    },
    'properties': {
    'Site':'MALONE TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.60, 54.75]
    },
    'properties': {
    'Site':'MAGHERAFELT TRANSMISSION AREA'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.70, 54.59]
    },
    'properties': {
    'Site':'NEWTOWNARDS'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-6.33, 54.17]
    },
    'properties': {
    'Site':'NEWRY TE'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-7.29, 54.60]
    },
    'properties': {
    'Site':'OMAGH SPERRIN TRUNK'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.91, 54.57]
    },
    'properties': {
    'Site':'ORMEAU REPEATER STATION'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.88, 54.61]
    },
    'properties': {
    'Site':'INTAKE'
   }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.83, 54.45]
    },
    'properties': {
    'Site':'SAINTFIELD'
    }
  },
  {
    'type': 'Feature',
    'geometry': {
       'type': 'Point',
       'coordinates':  [-5.89, 54.67]
    },
    'properties': {
    'Site':'WHITEABBEY'
    }
  }
]
}

var vectorSource = new VectorSource({
        features: new GeoJSON().readFeatures(geojsonObject, {
                dataProjection: 'ESPG:4326',
                featureProjection: 'ESPG:3857'
        })
});

var vectorLayer = new VectorLayer({
        source: vectorSource,
        style: styleFunction
});


var map = new Map({
  interactions: defaultInteractions().extend([
    new DragRotateAndZoom()
  ]),
  layers: [
    new TileLayer({
      source: new OSM()
    }),
    vectorLayer
  ],
  target: 'map',
  view: new View({
    center: fromLonLat([1.155670, 52.059311]),
    zoom: 2
  })
});



您的数据是 ESPG:4326,地图视图是 ESPG:3857,所以您需要

features: (new GeoJSON()).readFeatures(geojsonObject, {
  dataProjection: 'ESPG:4326',
  featureProjection: 'EPSG:3857'
})