OpenLayers и Geoserver, получая широту и длину слоя - PullRequest
0 голосов
/ 23 октября 2019

Вот сценарий:

У меня есть VectorTileLayer, построенный с VectorTileSource

    this.vectorTileSource = new VectorTileSource({
      format: new GeoJSON(),
      url: 'http://localhost:8090/geoserver/smartzone/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=work:name&outputFormat=application/json'
    });

this.vtLayer = new VectorTileLayer({
  declutter: true,
  source: this.vectorTileSource,
  style:someStyle
});

Теперь я хочу отобразить слой на карте:

this.map = new Map({
  target: this.viewMap.nativeElement,
  overlays: [this.overlay],
  layers: this.vtLayer,
  view: new View({
    center: ???
    zoom: 10.2
  })
});

??? я могу получить координаты (широта / долгота) для центра? Вручную я могу получить их из свойств слоя в GeoServer UI

enter image description here

Но мне нужно каким-то образом получить его, используя скрипты OpenLayers ...

Ответы [ 2 ]

0 голосов
/ 24 октября 2019

Вот как это делается:

//we do it on change event for the vector source
    this.wfsVectorSource.on('change', (evt)=>{
      var source=evt.target;
      if(source.getState() === 'ready'){ //then when its ready
          this.map.getView().fit(source.getExtent(), this.map.getSize() as any);
          //source.getExtent() gets you coordinates for the layer
      }
    });
0 голосов
/ 24 октября 2019

Вы можете задать слой :

layer.getExtent().getCenter()
...