我在地图上有很多折线,如果用户单击某些折线,我想“选择”所需的折线,但有时折线可能会重叠。因此,如果用户想选择一个并单击2,我想知道用户单击了哪些折线并显示出来。我该怎么办?
我试图编写一些代码来循环折线并检查单击的位置是否在某些图形上,但是不起作用,因为单击图形并不意味着单击了折线地理位置。
这是我的代码:(Run in JSFiddle)
{-# LANGUAGE UnicodeSyntax #-}
import qualified Data.Maybe as M
import qualified Data.List as L
data Term a = F a [Term a]
| V a deriving (Eq)
data Literal a = P a [Term a]
| E (Term a) (Term a) deriving (Eq)
class Substitutable f where
substitute :: f a -> (Term a -> Maybe (Term a)) -> f a
instance Substitutable Term where
substitute x@(V _) σ = M.fromMaybe x (σ x)
substitute f@(F l xs) σ = M.fromMaybe f' (σ f)
where f' = F l (map (flip substitute σ) xs)
instance Substitutable Literal where
substitute (P l xs) σ = P l (map (flip substitute σ) xs)
substitute (E s t) σ = E (substitute s σ) (substitute t σ)
(<|) t σ = substitute t $ flip L.lookup σ
-- variables
x = V "x"
y = V "y"
-- constants
a = F "a" []
b = F "b" []
-- functions
fa = F "f" [a]
fx = F "f" [x]
σ = [(x,y), (fx, fa)]
main = print $ show $ (P "p" [x, b, fx] <| σ) == P "p" [y, b, fa]
所以我试图如图所示单击(光标是黄色圆圈):
我希望控制台日志:
“嘿,您点击了红色的
嘿,您点击了蓝色的“
但是什么都没记录。