0

I have 3 vector layers and one raster which I want to display with OpenLayers. I used Geoserver and Geowebcache for creating VectorTiles cache (in EPSG:4326). These cached layers displayed well in the standard Geoserver viewer.

Then I created map in OL (for this example I left only one raster (basemap) and one vector tile layer):

var layerCity = 'xxx:city',
    layerTerrain = 'xxx:terrain';

var epsg_projection = '4326';

var City = new ol.layer.VectorTile({
    source: new ol.source.VectorTile({
      tilePixelRatio: 1, // oversampling when > 1
      tileGrid: ol.tilegrid.createXYZ({maxZoom: 13}),
      format: new ol.format.MVT(),
      projection: 'EPSG:4326',
      url: 'http://xxx/geoserver/gwc/service/tms/1.0.0/' + layerCity + '@EPSG%3A' + epsg_projection +'@pbf/{z}/{x}/{-y}.pbf'
    }),
    style: function(feature) { //sdsds
      return styleCity = new ol.style.Style({
              image: new ol.style.RegularShape({
                  stroke: new ol.style.Stroke({
                    color: 'white',
                    width: 1.5
                  }),
                  fill: new ol.style.Fill({
                    color: 'black'
                  }),
                  radius: 5,
                  points: 4,
                  angle: Math.PI / 4,
             }),
             text: new ol.style.Text({
                stroke: new ol.style.Stroke({
                   color: '#ffffff',
                   width: 2.5
                 }),
                // fill: new ol.style.Fill({
                //    color: 'f2cb00',
                //    width: 2.5
                //  }),
                font: 'bold 14px Roboto, sans-serif',
                text: feature.get("name").toString(),
                offsetX: 17,
                offsetY: -12
            })
        })
    }
  });

var Terrain = new ol.layer.Tile({
    source: new ol.source.TileWMS({
      url: 'http://xxx/geoserver/gwc/service/wms?',
      params: {
        'LAYERS': layerTerrain,
        'TILED': true,
        'VERSION': '1.1.1',
        // 'SRS': 'EPSG:4326',
        'FORMAT': 'image/png8'
      }
  })
});


var map = new ol.Map({
    target: 'map-frame',
    view: new ol.View({
        projection: 'EPSG:4326',
        // center: [-26.103, -4.195], //Deois
        zoom: 2,
        minZoom: 0,
        maxZoom: 8
      //  projection: 'EPSG:4326'
    }),
    layers: [Terrain, City]
});

As you сan see I set projection for my map to "EPSG:4326", because default prj is 3857.

But unfortunatly I got a partial result: displaying of basemap without vectortile layer visualisation. Also I used Chrome developer extension for checking donwloads. So I got about 15 pbf files without fails but I don't see that on the map!

However, if I change (or remove) map projection to 3857, I get the vector tile visualisation. I think it must sounds strange because on the server I have tiles' directories only with such format: "EPSG_4326...".

I have no any idea for solving this problem.

1

After understanding your question, The problem is how you define the projection of your vector layers, your tiles and map all in [EPSG:4326] projection. So in this case, you need define your vector layers as:

var City = new ol.layer.VectorTile({
source: new ol.source.VectorTile({
  tilePixelRatio: 1, // oversampling when > 1
  tileGrid: ol.tilegrid.createXYZ({maxZoom: 13}),
  format: new ol.format.MVT({
  defaultDataProjection: 'EPSG:4326' 
 }),
  url: 'http://xxx/geoserver/gwc/service/tms/1.0.0/' + layerCity + '@EPSG%3A' + epsg_projection +'@pbf/{z}/{x}/{-y}.pbf'
}),

A working example with same procedure

  • As I understood displayProjection is used only for displaying map units in another projection (by click or hover for instance). If I am wrong, would you mind specifying me placement of this function in my code? – Bulantsev Oleg Feb 16 '18 at 8:31
  • please check the updated answer – Moh Feb 16 '18 at 11:29
  • I meant default OL projection is 3857, but all my data are 4326 beacuse I want to have an output map in 4326. But paradoxically basemap data is displayed without any problems (if I set projection parameter as 4326) and there aren't any vector data. – Bulantsev Oleg Feb 16 '18 at 15:22
  • ok, I understand now, but why your target is not 'map' and why you defined the center like this? just define it as center: [0,0] – Moh Feb 16 '18 at 15:45
  • hmm, What do you mean "target is not map". Definitly my main task to have a good-working map :) And I suppose "center" parameter is not affected my map because this is just an extent variable. – Bulantsev Oleg Feb 16 '18 at 16:04

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.