Pinch to Zoom - Disable rotation on mobile device 4.3

2384
6
Jump to solution
03-03-2017 05:08 PM
MattNicol
New Contributor III

In the ArcGIS API for JavaScript 4.3, when looking at a map on a mobile device, is it possible to configure the map or map view to not rotate when pinching to zoom? 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Matt,

   you can use:

// Disables map rotation

view.constraints = {

    rotationEnabled: false

};

For your specific use case you would have to add the constraint using the view pointer-down event and then on the pointer-up you could remove the constraint.

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Matt,

   you can use:

// Disables map rotation

view.constraints = {

    rotationEnabled: false

};

For your specific use case you would have to add the constraint using the view pointer-down event and then on the pointer-up you could remove the constraint.

MattNicol
New Contributor III

Robert,

That's perfect - thanks!

0 Kudos
JaredRowe
New Contributor

Hi all, 

I am also attempting to prevent map rotation on pinch zoom with JSAPI v4.3.

Finding that any use of the rotationEnabled constraint kills pinch zooming completely, which seems odd.

Tried using rotationEnabled constraint property on creation of the MapView, also attempted Robert's suggestion of adding/removing constraint on view pointer-down/pointer-up events.

view.on('pointer-down', function(){
   view.constraints = {
     rotationEnabled: false
   };
});
view.on('pointer-up', function(){
   view.constraints = {
     rotationEnabled: true
   };
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any ideas on why the rotationEnabled constraint would prevent pinch zooming?

Thanks!

Jared

0 Kudos
KiSungChon
New Contributor

I think when you assign the new object you are clearing out the default constraints.

However, I am getting the same behavior (pinch zooming disabled) even when I do

(<__esri.MapView>view).constraints.rotationEnabled = false;
0 Kudos
StéphaneGuignard
New Contributor II

Hi All,

I have the same problem since the version 4.3 of JSAPI, the pinch to zoom doesn't work if you disable the rotation option.

My workaround for the moment is :

1) Active rotationEnabled à true

constraints : {
    rotationEnabled: true
}

2) set rotation=0 for each pointer-up event

var view = new MapView(*****);
view.on('pointer-up', function(){
    view.rotation = 0;
});

It works on mobile. It would be nice if this option rotation will be separate from the zoom...

BR,

Stéphane

deleted-user-OlpHy1NoMNug
Occasional Contributor II

As an update to this, I was looking for a way to disable user rotation while still setting a rotation amount at the view level.  

Working with Tech Support, credit to Mayur, we created a watch function where the if a user tries to rotate the map is returned to the view setting.  This has the effect of essentially disabling rotation.

// to watch any change in "rotation" property of view.
view.watch("rotation", function(norotate) {
   console.log(norotate);
   view.rotation = 289 // if this is hit set the rotation back to 289
}),

You can see result here, https://gis.greenvillesc.gov/imaginefestival/index.html 

Scott