按openlayer 3中的位置名称放大

Zoom in to by name of location in openlayer 3

本文关键字:放大 位置 openlayer      更新时间:2023-11-14

我正试图通过动态选择框按州>地区>村庄的顺序按名称放大到位置。

在这篇文章中,我创建了两个名为zoomToExtDist(name)zoomToExtVil(distname,vilname)的函数。但不知道它们不起作用。我们应该在openlayers 3中使用哪个函数。有人能告诉我哪里做错了吗。这是我创建的plunker缩放到位置更新链接

请告诉我在openlayers 3中,我们应该使用哪个函数来设置通过lat-long的视图。提前感谢:)

试试这个

   $(function() {
    var records = jsonList.listval;
   // console.log(records);
    insert($('#state_id'), plucker(records, 'state'));
    //------------------------^ grabs unique states
    //--^ populate state list on DOM ready
    $('select').on('change', function() {
      var category = this.id.split('_id')[0];
      var value = $(this).find('option:selected').text();
      switch (category) {
        case 'state':
          {
            insert($('#district_id'), plucker(filter(records, 'state', value), 'district'));
             break;
          }
        case 'district':
          {
            insert($('#village_id'), plucker(filter(records, 'district', value), 'village'));
            break;
          }
          case 'village':
          {
             zoomToExtDist($(this).val());
            break;
          }
      }
  });

        function zoomToExtDist(name)
        { console.log(name);
            for (var i = 0; i < jsonList.listval.length; i++)
             {
              if(name==jsonList.listval[i].village)
              {
                  var tlon = parseFloat(jsonList.listval[i].longitude);
                  var tlat = parseFloat(jsonList.listval[i].latitude);
                  //var lonlat = new OpenLayers.LonLat(tlat,tlon);
                   map.getView().setCenter(ol.proj.fromLonLat([tlat, tlon]));
                  map.getView().setZoom(5);
              }
             }
        }
....

http://plnkr.co/edit/Rja2b1dLsJm7FDFtlUJ0?p=preview

我不能发表评论,因为我没有足够的声誉,但在你的博客中,我没有看到zoomtoist和zoomtovil函数?它们在哪个文件中?此外,您是否尝试过使用view.centerOn()[http://openlayers.org/en/v3.14.2/apidoc/ol.View.html#centerOn]?还是单独使用view.setCenter()和view.setZoom()来执行居中和缩放?