question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lost zoom position on click with preserveViewport = true

See original GitHub issue

Hi . regrading the following issue https://github.com/openseadragon/openseadragon/issues/1105 that.

when I upload my code I have the following code block to keep the zoom on 2 images :

`var viewer1 = OpenSeadragon({
             id: "id1",
             maxZoomPixelRatio:6,
           defaultZoomLevel: 	0.75,
           minZoomLevel: 	0.75,
           visibilityRatio: 	1,
             preserveViewport: true, 
             prefixUrl: "img",
   });
var viewer2 = OpenSeadragon({
                id: "id2",
                maxZoomPixelRatio:6,
                defaultZoomLevel: 	0.75,
                minZoomLevel: 	0.75,
                visibilityRatio: 	1,
                preserveViewport :true,
                prefixUrl: "img/",
      });

  var viewer1Leading = false;
  var viewer2Leading = false;

  var viewer1Handler = function() {
    if (viewer2Leading) {
      return;
    }

    viewer1Leading = true;
    viewer2.viewport.zoomTo(viewer1.viewport.getZoom());
    viewer2.viewport.panTo(viewer1.viewport.getCenter());
    viewer1Leading = false;
  };

  var viewer2Handler = function() {
    if (viewer1Leading) {
      return;
    }

    viewer2Leading = true;
    viewer1.viewport.zoomTo(viewer2.viewport.getZoom());
    viewer1.viewport.panTo(viewer2.viewport.getCenter());
    viewer2Leading = false;
  };

  viewer1.addHandler('zoom', viewer1Handler);
  viewer2.addHandler('zoom', viewer2Handler);
  viewer1.addHandler('pan', viewer1Handler);
  viewer2.addHandler('pan', viewer2Handler);`

that is work and both image working great together but somthing else with the keep zoom went wrong. I have a button to show and hide on of the image, but in each click of the button i lost some of the zoom event i added preserveViewport = true; in each click or without it so when i click the button i gout the second image and both are got the zoom, but after i click the hide button in the first click everything is ok but if I continue to show and hide the zoom is not at the same point. after 3 or 4 click the zoom return to the start point.

onclick i have the following code


`  var tileSource={
                            type: 'image',
                            url:  img
                      }

                      viewer1.open(tileSource);`

also i have css that i perform on click that divide the div to be 50%(each image is 50%) to show 2 images side by side side so i think maybe its related to css, but how can we keep the zoom event we change divs or with of divs ?

thx for the support

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
johnicocommented, Feb 28, 2017

@iangilman hi i opened a new issue with all the details , can you help me there ? https://github.com/openseadragon/openseadragon/issues/1141

the codepen is : http://codepen.io/anon/pen/RpWoar

0reactions
iangilmancommented, Jan 31, 2017

Regarding the open event I was thinking something like this:

viewer1.addHandler('open', viewer2Handler); // When Viewer 1 is opened we want Viewer 2 to lead
viewer2.addHandler('open', viewer1Handler);

You shouldn’t need to do anything extra on click, since the zoom and pan events should already cover it.

I’m having a hard time visualizing the scenario where things are breaking. Can you share a link to your code, or maybe a simplified version that shows the problem directly? You can fork my Codepen if you’d like, for instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Override Google Maps Directions Zoom - Stack Overflow
setZoom allows you to set your own zoom. ... setZoom() , if i set preserveViewport as true, then my map is not visible....
Read more >
Google Maps JavaScript API V3 Reference
KmlLayerOptions interface. Properties: clickable , map , preserveViewport , screenOverlays , suppressInfoWindows , url , zIndex ; KmlLayerMetadata interface.
Read more >
Integrating Google Maps in React| Sudolabs blog
preserveViewport : true , - disable zoom on direction display (when a direction is calculated the map is zoomed to fit the screen...
Read more >
Set zoom after loading KmlLayer? - Google Groups
map acquires the zoom and center properties of the KML files. I'd like ... {preserveViewport:true}" to the end of both KML files. That...
Read more >
React Google Maps Style Guide
isMarkerShown && <Marker position={{ lat: -34.397, lng: 150.644 }} onClick={props.onMarkerClick} />} </GoogleMap> )) class MyFancyComponent extends React.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found