【发布时间】:2011-08-16 10:41:46
【问题描述】:
我在 iphone 中创建了 OpenLayer 地图应用程序。所以我想通过 iphone 的功能访问它的事件意味着我想通过触摸事件拖动 OpenLayer 地图并通过 iphone 缩放手势事件进行缩放。为了调用 OpenLayer 地图,我已经在 web 视图中实现了一个 html 文件。它工作正常我得到了 OpenLayer 地图和地图触摸事件现在我也想缩放地图,就像其他地图或图像将在 iphone 中放大一样。请指导我用于在 iphone 的 OpenLayer 地图中实现缩放功能..
为了调用地图和触摸事件,我在 .html 文件中使用了此代码
<!DOCTYPE html>
<html>
<head>
<title>OpenLayers Tutorial - Basic Map Setup</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map, baseLayer;
function init(){
map = new OpenLayers.Map('map');
baseLayer = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers:"basic"});
map.addLayer(baseLayer);
map.setCenter(new OpenLayers.LonLat(0,0),1);
}
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type="mousemove"; break;
case "touchend": type="mouseup"; break;
default: return;
}
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
</script>
<style>
@media screen
{
#map{width: 300px; height:360px; border: 2px solid black;}
}
</style>
</head>
<body onload="init()">
<h3>OpenLayers Tutorial - Basic Map Setup</h3>
<div id="map"></div>
</body>
</html>
这段代码运行正常。
【问题讨论】:
标签: javascript iphone openlayers