deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

some question about TileLayer

Open HeiYanjing opened this issue 7 years ago • 5 comments

Unfortunately ,#3316 closed ,because occur some deck.gl version problem . now it resolved.

Firstly. I publish a building Layer by geoserver. And I test it successful by mapbox . image For my mapbox js code:

		map.on('load', function() {
	          map.addSource('building',{
	              'type':'vector',
	              'scheme':'tms',
	              'tiles':['http://192.168.1.125:8090/geoserver/gwc/service/tms/1.0.0/mysapce%3Achognqing@EPSG%3A900913@pbf/{z}/{x}/{y}.pbf']
	          });
	          map.addLayer({ 
	            'id': '3d-buildings',
	            'source': 'building',
	            'source-layer':'chognqing',
	            'type': 'fill-extrusion',
	            'paint': { 
	                'fill-extrusion-color': [
	                      'interpolate', 
	                     ['linear'],
	                      ['get', 'height'],
	                    0, 'rgb(255,255,191)',
	                      10, 'rgb(253,174,97)',
	                      20, "#aaa",
	                ], 
	                'fill-extrusion-height': ['get', 'height'], 
	                'fill-extrusion-opacity': 0.6
	            } 
	        });
  });

I try it in my project like TileLayer For my package.json: "@deck.gl/core": "^7.1.7", "@deck.gl/geo-layers": "^7.1.7", "@deck.gl/layers": "^7.1.7", "@deck.gl/react": "^7.1.7", "@mapbox/vector-tile": "^1.3.1", "pbf": "^3.2.0",

For my deck.gl code:

import {TileLayer} from '@deck.gl/geo-layers'; import {VectorTile} from '@mapbox/vector-tile'; import Protobuf from 'pbf';

      new TileLayer({
          opacity: 0.7,
          lineWidthMinPixels: 1,
          getTileData: ({x, y, z}) => {
            const mapSource = `http://192.168.1.125:8090/geoserver/gwc/service/tms/1.0.0/mysapce%3Achognqing@EPSG%3A900913@pbf/${z}/${x}/${y}.pbf`;
            return fetch(mapSource)
              .then(response => response.arrayBuffer())
              .then(buffer => {
                const tile = new VectorTile(new Protobuf(buffer));
                const features = [];
                for (const layerName in tile.layers) {
                  const vectorTileLayer = tile.layers[layerName];
                  console.log('---------',vectorTileLayer);
                  for (let i = 0; i < vectorTileLayer.length; i++) {
                    const vectorTileFeature = vectorTileLayer.feature(i);
                    const feature = vectorTileFeature.toGeoJSON(x, y, z);
                    features.push(feature);
                  }
                }
                return features;
              });
          }
      })

In netwrok. I compare the difference : image and in console, there are three types of error: image

It looks like fetch error , and decoding tiles error. I don't know where is the mistake.

HeiYanjing avatar Jul 10 '19 10:07 HeiYanjing

I check the url by postman, it looks everything's ok. image

I set method,mode,headers in fetch. the mode 'cors' and 'no-cors' both tried.

            let option = {
                method:'get',
                mode:'cors',
                headers:{
                    'Access-Control-Allow-Origin':'*',
                    "Content-Type": "application/x-protobuf",
                    "Access-Control-Allow-Credentials":"true"
                }
            }
           return fetch(mapSource,option)
           ...

no matter what the value of x,y,z . image image Is there any requirements in deck.gl layer's fetch operation?

HeiYanjing avatar Jul 11 '19 12:07 HeiYanjing

In your getTileData function you are not passing any option to the fetch call.

Pessimistress avatar Jul 11 '19 18:07 Pessimistress

@Pessimistress
I made some change for my code . cause Cross-domain error . I set proxy in webpack.config.js:

'/maptiles/*': { target: 'http://192.168.1.125:8090', secure: false, changeOrigin: true },

and my js code:

          getTileData: ({x, y, z}) => {
            const mapSource = `/maptiles/geoserver/gwc/service/tms/1.0.0/mysapce%3Achognqing@EPSG%3A900913@pbf/${z}/${x}/${y}.pbf`;
           
            let option = {
                method:'get',
                mode:'cors',
            };
            return fetch(mapSource,option)
              .then(response => response.arrayBuffer())
              .then(buffer => {
                console.log(buffer);
                const tile = new VectorTile(new Protobuf(buffer));
                const features = [];
                for (const layerName in tile.layers) {
                  const vectorTileLayer = tile.layers[layerName];
                  console.log('---------',vectorTileLayer);
                  for (let i = 0; i < vectorTileLayer.length; i++) {
                    const vectorTileFeature = vectorTileLayer.feature(i);
                    const feature = vectorTileFeature.toGeoJSON(x, y, z);
                    features.push(feature);
                  }
                }
                return features;
              });
          }

Even 404 error still exist for my fetch call: image image print console.log(buffer); is not empty: image

Embarrassed,I don't know where I was wrong.

HeiYanjing avatar Jul 12 '19 12:07 HeiYanjing

it seems wrong when buffer convert to VectorTile

HeiYanjing avatar Jul 19 '19 06:07 HeiYanjing

As of 8.1 there's a purpose-built MVTLayer, so you don't need to do your own vector tile parsing anymore. Open a new issue if you still have problems.

kylebarron avatar Jun 24 '20 00:06 kylebarron