钛webview传单/ gmaps捏缩放不能正常工作

时间:2013-10-25 21:33:59

标签: google-maps webview titanium leaflet pinchzoom

我正在使用Android的本地HTML文件(非远程)开发Titanium webview移动应用程序。我的HTML代码包含地图(类似于Google地图),并允许用户使用缩放手势。

为了在我的本地HTML网页(不仅仅是在地图上)中启用缩放和缩放,我在HTML标题中添加了以下元标记:

<meta name="viewport" content="width=device-width, initial-scale=1.0, 
          maximum-scale=1.01, user-scalable=1">

maximum-scale属性的最小值为1.01 除此之外,我的ApplicationWindows.js文件将webview的scalesPageToFit属性设置为true,如下所示:

var webView = Ti.UI.createWebView({        
        url : "/HTML/index.html",
        scalesPageToFit : true
});

这两项更改启用了我的应用程序中的缩放缩放功能。但是,如果用户先前已经在某处捏缩放(在DOM的任何其他部分,但在地图外),则缩放缩放功能仅适用于地图。因此,举个例子,让我们假设这是我的HTML代码(基本gmaps示例):

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" 
    content="width=device-width, initial-scale=1.0, 
       maximum-scale=2, user-scalable=1">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas { height: 70%; margin: 0px; padding: 0px; }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
    </script>
    <script>
    var map;
    function initialize() {
      var mapOptions = {
        zoom: 8, center: new google.maps.LatLng(-34.397, 150.644)
      };
      map = new google.maps.Map(
          document.getElementById('map-canvas'),
          mapOptions);
    }
    google.maps.event.addDomListener(window, 'load', initialize);     
    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

请注意,地图仅填充屏幕的70%,底部有30%的“空白”空间。

我的ApplicationWindow.js文件是:

// Application Window Component Constructor
function ApplicationWindow() {          
    var self = Ti.UI.createWindow({
        backgroundColor : '#FFFFFF',
        modal : true,
        exitOnClose : true  // Android only
    });
    var webView = Ti.UI.createWebView({        
        url : '/HTML/gmap.html',
        scalesPageToFit: true
    }); 
    self.add(webView);  
    return self;
}

//make constructor function the public component interface
module.exports = ApplicationWindow;

运行应用程序(在Android模拟器,Android移动设备或Android平板电脑中)行为始终是相同的:只有在我们之前缩放过DOM的任何其他部分时,地图上的缩放才有效(在这种情况下,在底部的空白区域)。一旦检测到变焦,捏拉缩放手势也可以在地图上使用,但不能在之前使用!

详细说明:

  • Titanium SDK:3.1.2GA -
  • 平台&amp; version:在Android v.2.3.4,v.4.0,v.4.0.3
  • 上测试
  • 设备:仿真器,手机和平板电脑
  • 主机操作系统:在Ubuntu和Debian上测试
  • Titanium Studio:3.1.3.201309132423

我不确定我做错了什么或者这只是一个Titanium bug ...提前致谢!

0 个答案:

没有答案