Получить центральную точку из источника слоя в OL OSM - PullRequest
1 голос
/ 19 января 2020

Я использую открытую карту OSM с Angular для просмотра стран, затем штатов и городов соответственно. Я могу повысить уровень в соответствии с выбором и добавив новый слой для каждого. Я не удаляю, а просто скрываю предыдущий слой. Предположим, что если кто-то выберет Нью-Йорк из Соединенных Штатов, тогда слой всех стран будет скрыт, и будет виден верхний слой с городами Нью-Йорк. Теперь мне нужно дать пользователю возможность вернуться к верхнему уровню. Как двойной щелчок по Нью-Йорку отобразит все графства. чтобы сделать это, когда я скрываю текущий слой и показываю предыдущий слой, он отображается правильно, но я не могу получить его центральную точку. Может ли кто-нибудь помочь в этом?

this.map.on('singleclick', (event) => {
    // do foreach for each layer  this.MapLevel is each layer number in map
    this['vectorLayer' + this.MapLevel].getFeatures(event.pixel).then((features) => {
        if (!features.length) {
          selection = {};
          return;
        }
        const feature = features[0];
        if (!feature) {
          return;
        }
        source: new VectorSource({source: new VectorSource({
          url: this.MapSourceURl, // local json file path to retrive Data
          map: this.map,
          format: new GeoJSON(),
          wrapX: false,
          useSpatialIndex: false,
          overlaps: false 
         })}); // layer parameters not pasting here as it has long
        this.map.addLayer(this['vectorLayer' + this.MapLevel]);
        this['vectorLayer'+ this.MapLevel].setVisible(true);
        this['vectorLayer' + (this.MapLevel - 1)].setVisible(false);
      });
      });


// On double click I am trying to show previous layer to downgrade Level in map

this.map.on('dblclick', (event) => {



this['vectorLayer' + (this.MapLevel-1)].getSource().forEachFeature(function (feature){
         var Coords = feature.getGeometry().getCoordinates();
 }); // i want to get outer boundary co-ordinated rather than per feature co-ordinates

     this['vectorLayer' + (this.MapLevel - 1)].setVisible(true);
     this['vectorLayer' + (this.MapLevel - 1)].setOpacity(1);
     this['vectorLayer'+ this.MapLevel].setVisible(false);
    });

But I am not getting correct zoom level of previous layer this so this code is failing. 
...