0

What is the correct way to fetch vector features from the server using GeoJson?

{
  "type" : "FeatureCollection",
  "features" : [ {
    "type" : "Point",
    "coordinates" : {
      "x" : 14.8802,
      "y" : 22.1043,
      "z" : "NaN",
      "m" : "NaN"
    },
    "properties" : {
      "date" : 1472936467273,
      "device" : null,
      "longitude" : 14.8802,
      "latitude" : 22.1043,
      "mi_PRINX" : 1,
      "id" : 1
    }
  }]
}

The map shows no points.

  var dynamicFeatures = new ol.layer.Vector({
          source: new ol.source.Vector({
          format: new ol.format.GeoJSON(),
          url: "http://localhost:9090/map/layers"
        })
      });

      // Map
      this.mapObject = new ol.Map({
        target: 'map',
        controls: [],
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          }),
          dynamicFeatures
        ],
        view: new ol.View({
          center: [949282, 6002552],
          zoom: 4
        })
      });

URL is correct.

Could it be because the z and m values? these are generated automatically from the server...

Regards, Ido

  • Welcome to gis.stackexchange! Please edit the title of your question to include enough information for future visitors to be able to find this thread when looking for the same problem. – underdark Oct 21 '16 at 18:01
3

Your geoJson should be as below:

{
  "type" : "FeatureCollection",
  "features" : [
{ 
"type" : "Feature",
"geometry":  {
    "type" : "Point",
    "coordinates" : [14.8802, 22.1043]
    },
    "properties" : {
      "date" : 1472936467273,
      "device" : null,
      "longitude" : 14.8802,
      "latitude" : 22.1043,
      "mi_PRINX" : 1,
      "id" : 1
    }
  }
]
}

Reference : http://geojson.org/geojson-spec.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.