简体   繁体   English

在 SVG 地图上捏合和缩放

[英]Pinch and Zoom on SVG Map

I have an SVG that is a building map with each room having its own element.我有一个 SVG,它是一个建筑地图,每个房间都有自己的元素。 I am using javascript with Snap.svg with the Snap.svg.zpd plugin and jquery-touchswipe to capture touch events.我使用带有 Snap.svg 的 javascript 和 Snap.svg.zpd 插件和 jquery-touchswipe 来捕获触摸事件。 Each room has an element so a person can click or touch a room to get room information.每个房间都有一个元素,因此人们可以单击或触摸房间以获取房间信息。 I can pinch and zoom perfectly fine outside the map, but on the map doesn't work well.我可以在地图外完美地捏合和缩放,但在地图上效果不佳。 The problem is that on the map I'm touching different rooms when I try to pinch the map, so it's not picking the pinch up.问题是,在地图上,当我尝试捏合地图时,我正在触摸不同的房间,因此它并没有选择捏合。 If I can pinch on a single large room it works fine.如果我可以捏住一个大房间,它就可以正常工作。

Does anyone have any ideas on how to approach this problem to make pinching and zooming on the map work?有没有人对如何解决此问题以使地图上的捏合和缩放工作有任何想法?

I'm not familiar with the Snap.svg library, but I've had similar situations before.我对 Snap.svg 库不熟悉,但我以前也遇到过类似的情况。

What I've done is to remove the events from individual elements and let the parent handle everything.我所做的是从单个元素中删除事件,让父元素处理所有事情。 This means that your map needs to be able to discern which of it's rooms/children/whatever are getting touched, so it can appropriately handle child specific events, but it can then process the non-child specific events that are similar.这意味着您的地图需要能够辨别哪些房间/孩子/任何被触摸的东西,以便它可以适当地处理特定于孩子的事件,但它随后可以处理类似的非特定于孩子的事件。

When you have multiple layers of children, it can be tough to do, but there are ways to do it.当您有多个孩子时,这可能很难做到,但有很多方法可以做到。 I did it a couple months ago, but not with Snap.svg and I don't remember how I did it.几个月前我做了,但不是用 Snap.svg,我不记得我是怎么做的。

In this case, your individual rooms are likely getting the single touch events and blocking the map multi-touch event.在这种情况下,您的各个房间可能会收到单点触摸事件并阻止地图多点触摸事件。 This seems to be evident due to being able to pinch on the rooms just fine and having separate touch events.由于能够很好地捏住房间并具有单独的触摸事件,这似乎很明显。 It'll take some work to revise how you handle the touch events, but it's probably the easiest way to handle it.修改处理触摸事件的方式需要一些工作,但这可能是处理它的最简单方法。

The only other way I can think of to deal with this is to somehow detect if multiple events are happening at the same time.我能想到的唯一另一种处理方法是以某种方式检测多个事件是否同时发生。 This is usually pretty dicey and unreliable.这通常是非常冒险和不可靠的。 It might be managed by working with global variables, but that's not a recommended way to deal with most things, especially events.它可以通过使用全局变量来管理,但这不是处理大多数事情的推荐方法,尤其是事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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