Javascript Openlayers:GeoJSON和坐标
我试图解析GeoJSON数据,并在ESPG:4326地图上绘制“点”,取得了一些成功。它在地图上绘制“点”,但使用默认设置[0,0]。我是Openlayers的新手。我还通过两个验证器验证了geojson,返回时没有错误。我下面的代码是一个.js文件 我以前在更改地图的“中心”时遇到过类似的问题,我使用“fromlonat”来解决这个问题。我假设存在某种涉及“fromlonat”的解决方案,但我在Openlayers 6的任何地方都找不到与此相关的任何内容Javascript Openlayers:GeoJSON和坐标,javascript,openlayers,geojson,Javascript,Openlayers,Geojson,我试图解析GeoJSON数据,并在ESPG:4326地图上绘制“点”,取得了一些成功。它在地图上绘制“点”,但使用默认设置[0,0]。我是Openlayers的新手。我还通过两个验证器验证了geojson,返回时没有错误。我下面的代码是一个.js文件 我以前在更改地图的“中心”时遇到过类似的问题,我使用“fromlonat”来解决这个问题。我假设存在某种涉及“fromlonat”的解决方案,但我在Openlayers 6的任何地方都找不到与此相关的任何内容 import Feature from
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,因此您需要功能:(new GeoJSON())。readFeatures(geojsonObject,{dataProjection:'ESPG:4326',featureProjection:'ESPG:3857')–Mike 23小时前您的数据是ESPG:4326,地图视图是ESPG:3857,因此您需要
功能:(new GeoJSON())。readFeatures(geojsonObject,{dataProjection:'ESPG:4326',featureProjection:'ESPG:3857'})
相关Mike,我尝试了你的建议,但分数仍然在3857默认值[0,0]上,请尝试使用EPSG而不是ESPG(打字错误),不要在标题中添加[SOLVED]
。添加答案并接受它(如果可以的话)要正确地结束此问题。正如问题所附的注释中所述,此答案中有一个打字错误-使用EPSG:x
而不是ESPG:x
格式化任何代码也是一个很好的做法。正如您在上面或本例中所做的那样,我认为使用缩进单独进行是合适的。感谢您的回答.