私はマップエリアをピクチャで動的に変更するオブジェクトマップエリアを作成しました。今、別のマップエリアにリダイレクトされるべき機能があります。私は特定の領域を押すと確認ウィンドウが表示されます。 「はい」または「いいえ」を押すと、特定のマップにリダイレクトされます。しかしどうですか?オブジェクト値に到達する方法(マップエリア)
// Object Map-Area
var _images = {
homepage: {
path: 'homepage.jpg',
areas: [{
coords: '45,143,106,158',
text: 'Homepage',
clickHandler: doSomething
}]
},
}
//DOM-Elements
image.areas.forEach(function(area) {
var areaElem = document.createElement('AREA');
areaElem.coords = area.coords;
areaElem.setAttribute('link', area.goto);
areaElem.setAttribute("title", area.text);
areaElem.setAttribute("shape", "rect");
//click handler and click listener
areaElem.addEventListener('click', onArea_click);
areaElem.addEventListener('click', area.clickHandler);
_map.appendChild(areaElem);
})
}
function onArea_click(domEvent) {
//update cuurent imageid with current link
_currentImageId = domEvent.target.getAttribute('link');
refreshImage();
}
function doSomething(e){
var areaClicked= e.target;
var r = confirm("Data will get lost!");
if (r == true) {
// I know I need something like in the function onArea_click
//Now how can I redirect to map homepage ?
} else {
//or to a different one?
}
// There is missing code but it's not important for what I need now because then the code will get sooo long.
編集:ここでは全体refreshImage機能。
function refreshImage() {
var image = _images[_currentImageId];
_image.src = image.path;
_map.innerHTML = "";
image.areas.forEach(function(area) {
var areaElem = document.createElement('AREA');
areaElem.coords = area.coords;
areaElem.setAttribute('link', area.goto);
areaElem.setAttribute("title", area.text);
areaElem.setAttribute("shape", "rect");
areaElem.addEventListener('click', onArea_click);
areaElem.addEventListener('click', area.clickHandler);
_map.appendChild(areaElem);
})
}
あなたが「リダイレクト」と言うとき、あなたはあなただけの別の画像とareamapのためにそれを変更したい意味ですか? – Whothehellisthat
はい、areamapと画像を変更したい – Emloy
おそらく、あなたはおそらくそれを使用するように、画像とエリアマップを変更する 'refreshImage()'関数をどこかに持っています。しかし、あなたはその質問をしているので、その部分はうまくいかないかもしれません。しかし、それはコードなどではありません...あなたが何をする必要があるのか分かりにくいです。コードの別々の部分だけが表示されますが、すべてのコードがどのように結びついているかはわかりません。あなたが私たちにすべてを負わせなかったのは良いことです。あなたがしようとしている特定の部分を見る必要があります。 – Whothehellisthat