简体   繁体   中英

OpenLayers 3.13: issue with bindTo by linking two views

I'm new in using OpenLayers. I'm trying to do some exercises with version 3.0 and 3.13.

I have to link two views: the second map respond to changes in the first map, but zoomed out three times; when the first map is panned or zoomed, the second map should center on the same location and stay zoomed out in three levels. I'm using the following code that works quite well on version 3.0, but not on v3.13: the console prints Uncaught TypeError: view2.bindTo is not a function .

In another example I use map2.bindTo('view', map); on v3.13, without any issue. What is the difference?

EDIT I'm wrong, I obtain the same issue. There is no bindTo anymore (see the comment by Jonatas Walker for details).

var layer = new ol.layer.Tile({
  source: new ol.source.OSM()
});

var london = ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857');

var view = new ol.View({
  center: london,
  zoom: 6,
});

var view2 = new ol.View({
  center: london,
  zoom: 3,
});

var map = new ol.Map({
  target: 'map1',
  layers: [layer],
  view: view,
  //renderer: 'dom'
});

var map2 = new ol.Map({
  target: 'map2',
  layers: [layer],
  controls: new ol.Collection(),
  interactions: new ol.Collection(),
  view: view2
});

view2.bindTo('center', view);

view.on('change:resolution', function(){
  var zoom = this.getZoom();
  if (zoom >= 3 && zoom <= 18)
    view2.setZoom(this.getZoom()-3);
  else view2.setZoom(this.getZoom());
});

Since PR #3472 there's no bindTo method and you can achieve this center binding with something like:

view.on('change:center', function(evt){
  view2.setCenter(view.getCenter());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM