Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
Cant show my features in openlayers. Does someone know how to solve this?

I have been struggling with my projections for a few weeks now. At the beginning I could show my features but they appear in jemen (they are supposed to be in Italy). After I realised my coordinates were being inversed, for example my coordinate [41.18702782291,15.450187402143] (which is in Italy) was displaying in [15.450187402143, 41.18702782291] (which is in jemen), I decided to invert the coordinates of the multipolygons of my geometries so that now I have the [15.450187402143, 41.18702782291] format. I don´t know what happened but now I cant see my features shown in the map.

I have an object geojson with my features and this is my code:


var myview = new View({
  center: [15.450187402143, 41.18702782291],
  projection: 'EPSG:4326',
  zoom: 6
})

var mylayer = new TileLayer({
  source: new OSM()
})

var layer = [mylayer]

const map = new Map({
  target: 'map',
  layers: layer,
  view: myview
}); 

const vectorSource = new VectorSource({
  format: new ol.format.GeoJSON(),
  features: (new ol.format.GeoJSON()).readFeatures(geoJson, {dataProjection: 'EPSG:4326',
  featureProjection: map.getView().getProjection()})
  //EPSG:32633 - WGS 84 / UTM zone 33N
  //features: new GeoJSON().readFeatures(geoJson, {dataProjection: 'EPSG:4326', FeatureProjection: map.getView().getProjection()})
});

console.log(geoJson);
console.log(vectorSource.getFormat());
vectorSource.addFeatures((vectorSource.getFormat()).readFeatures(geoJson));
console.log("1");
const vectorLayer = new VectorLayer({
  source: vectorSource
});

map.addLayer(vectorLayer);

const numFeatures = vectorLayer.getSource().getFeatures().length;
console.log("Count right after construction: " + numFeatures);

The final lines show that the features are in the source and it is correctly getting them.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This works fine for me. enter image description here

const geoJson = {
    "type": "Feature",
    "properties": {
        "name": "Coors Field",
        "amenity": "Baseball Stadium",
        "popupContent": "This is where the Rockies play!"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [15.450187402143, 41.18702782291]
    }
};

let map;
$(document).ready(function() {

    // CREATE MAP
    map = new ol.Map({
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM({
                    wrapX: false
                }),
                projection: 'EPSG:4326',
                visible: true
            })
        ],
        target: 'map',
        view: new ol.View({
            projection: 'EPSG:4326',
            center: [15.450187402143, 41.18702782291],
            zoom: 7,
        })
    });

    const vectorSource = new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        features: (new ol.format.GeoJSON()).readFeatures(geoJson, {dataProjection: 'EPSG:4326',
        featureProjection: map.getView().getProjection()}),
        
        //EPSG:32633 - WGS 84 / UTM zone 33N
        //features: new GeoJSON().readFeatures(geoJson, {dataProjection: 'EPSG:4326', FeatureProjection: map.getView().getProjection()})
    });

    vectorSource.addFeatures((vectorSource.getFormat()).readFeatures(geoJson));
    const vectorLayer = new ol.layer.Vector({
        source: vectorSource,
        style: new ol.style.Style({
            image: new ol.style.Circle({
                radius: 10,
                fill: new ol.style.Fill({color: 'red'})
            })
        })
    });

    map.addLayer(vectorLayer);
});
 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda