Im немного новичок в workng с OpenLayers 3.OpenLayers 3 Попробуйте загрузить GeoJSON объект
им пытаются загрузить объект GeoJSON в OpenLayers 3, но отображать центр только точка [0,0], которые даже не в моем объекте geojson, где im i идет не так.
код ниже:
//CREATE A BASE LAYER
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
// create a source from the feature
var source = new ol.source.GeoJSON(
({
object:
{
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {'name': 'EPSG:3857'}
},
'features': [
{
'type': 'Feature',
//'properties': {'id': 63},
'geometry': {
'type': 'Point',
'coordinates': [12, 12]
}
},
{
'type': 'Feature',
'properties': {'id': 62},
'geometry': {
'type': 'Point',
'coordinates': [35.0, 1.0]}
},
{
'type': 'Feature',
'properties': {'id': 61},
'geometry': {
'type': 'Point',
'coordinates': [34.0, 0.0]}
},
{
'type': 'Feature',
'properties': {
'id': 56
},
'geometry': {
'type': 'Point',
'coordinates': [33.0, 33.0]
}
}
]
}
})
);
// CREATE THE LAYER WITH THE DATA
var vectorLayer = new ol.layer.Vector({
source: source
});
// create an openlayers map object
var map = new ol.Map({
target: attrs.id,
layers: [raster,vectorLayer],
view: new ol.View({
//projection:'EPSG:4326',
center:[0,0],
zoom:2
})
});
}
Спасибо за это, помог мне понять, что у меня была та же проблема, повторная проекция ** обрабатывается автоматически для источника URL, но не для источника объекта **. То есть для 'var vectorSource = new ol.source.Vector ({url:" ./data_inventory.geojson ", format: new ol.format.GeoJSON()})', но не 'var vectorSource = new ol.source.Vector ({ Функции: (новый ol.format.GeoJSON()). readFeatures (data)}); 'где данные просто' ./data_inventory.geojson "" вставлены. –