0

I'm making a map with OpenLayers 3, I have coordinates (EPSG:3857) in PostgreSQL and the map layer is OSM (same projection that the icons, EPSG:3857).

The problem is that when I increment the zoom, the icons disappear... But if I decrement then the icons won't disappear.

Someone told me that the projection's ICONS and LAYER must be the same.

Can someone help me, please?

I'm new in StackOverFlow,

Thank you for your time,

Enrique.

Note: My code is in JSFiddle, can see here: jsfiddle.net/y3sLksg6/

dhilt
  • 18,707
  • 8
  • 70
  • 85
  • Your jsfiddle don't show anything. Could you rewrite it? – Anders Finn Jørgensen Nov 13 '14 at 20:01
  • Hi Anders, my problem is that I have coordinates in EPSG3857 in a database (postgresql). I draw feature with this coordinates...but if I increment zoom, the icon disappear and if I decrement icon is visible. Sorry for my english... –  Nov 13 '14 at 23:47
  • Please, someone can help me? It's very important for my project. Is a problem with the projections. –  Nov 17 '14 at 07:15

1 Answers1

1

Try to set the style to each of your markers individually as in the exaple below, which is a copy from your jsfiddle:

function AddMarkers() {
//create a bunch of icons and add to source vector
  var sizeY = Object.size(coordenadas);
  var x = null;
  var y = null;

  for (var i = 0; i < sizeY; i++) {
    x = coordenadas[i].Longitude;
    y = coordenadas[i].Latitude;
    var iconFeature = new ol.Feature({
        geometry: new ol.geom.Point([x, y]),
        name: 'Marker ' + i,
        population: 4000,
        rainfall: 500
    });
    markers[i] = [x, y];

    var iconStyle = new ol.style.Style({
        image: new ol.style.Icon(({
           anchor: [0.5, 46],
           anchorXUnits: 'fraction',
           anchorYUnits: 'pixels',
           opacity: 0.75,
           src: './img/circleRed.png'
       }))
    });      
    // This is new !
    iconFeature.setStyle(iconStyle);

    vectorSource.addFeature(iconFeature);
 }
 return vectorLayer;
}
Anders Finn Jørgensen
  • 1,275
  • 1
  • 17
  • 33
  • Good morning! Thank for your help but I have the same problem. When I create the map, icons appear in Africa. If I set fix coordinates, the icon appear in a correct place, but if I get coordinates from PostgreSQL, I have this problem. The coordinates in PostgreSQL are in EPSG3857 and my layer is OSM that use the same projection. I don't understand... –  Nov 18 '14 at 10:04