无法在 Seadragon 中创建多个叠加层

发布于 2024-09-04 03:57:22 字数 1784 浏览 5 评论 0原文

我正在尝试将叠加层添加到我正在制作的海龙地图中,但由于某种原因,我无法想象我们的海龙会忽略除第一个叠加层之外的所有叠加层。非常感谢任何对此的帮助。

var viewer = null;

function init() {
    Seadragon.Config.autoHideControls = false;

    viewer = new Seadragon.Viewer("container");

    viewer.addEventListener("open", addOverlays);

    viewer.addControl(makeControl(), Seadragon.ControlAnchor.TOP_RIGHT);

    $(viewer.getNavControl()).parent().parent().css({ 'top': 10, 'right': 10 });
    viewer.openDzi("_assets/Mapdata/dzc_output.xml");

}

function makeControl() {
    var control = document.createElement("a");
    var controlText = document.createTextNode("");

    control.href = "#"; // so browser shows it as link
    control.className = "control";
    control.appendChild(controlText);

    Seadragon.Utils.addEvent(control, "click",
                    onControlClick);

    return control;
}

function onControlClick(event) {
    Seadragon.Utils.cancelEvent(event); // don't process link

    if (!viewer.isOpen()) {
        return;
    }

    // These are the coordinates of europe on this map
    var x = 0.5398693914203284;
    var y = 0.21155952391206562;
    var z = 5;

    viewer.viewport.panTo(new Seadragon.Point(x, y));
    viewer.viewport.zoomTo(z);
    viewer.viewport.ensureVisible();
}

function addOverlays(viewer) {
    drawer = viewer.drawer;
    var img = document.createElement("img");
    img.src = "_assets/Images/pushpin.png";

    $(img).addClass('pushPin');

    var overlays = [
        { elmt: img, point: new Seadragon.Point(0.51, 0.22) },
        { elmt: img, point: new Seadragon.Point(0.20, 0.13) }
    ];

    for (var i = 0; i < overlays.length; i++) {
        drawer.addOverlay(overlays[i].elmt, overlays[i].point);
    }


}

Seadragon.Utils.addEvent(window, "load", init);

I am trying to add overlays to a seadragon map I am making but for some reason that I can not figure our seadragon ignores all my overlays except the first one. Any help with this is much appreciated.

var viewer = null;

function init() {
    Seadragon.Config.autoHideControls = false;

    viewer = new Seadragon.Viewer("container");

    viewer.addEventListener("open", addOverlays);

    viewer.addControl(makeControl(), Seadragon.ControlAnchor.TOP_RIGHT);

    $(viewer.getNavControl()).parent().parent().css({ 'top': 10, 'right': 10 });
    viewer.openDzi("_assets/Mapdata/dzc_output.xml");

}

function makeControl() {
    var control = document.createElement("a");
    var controlText = document.createTextNode("");

    control.href = "#"; // so browser shows it as link
    control.className = "control";
    control.appendChild(controlText);

    Seadragon.Utils.addEvent(control, "click",
                    onControlClick);

    return control;
}

function onControlClick(event) {
    Seadragon.Utils.cancelEvent(event); // don't process link

    if (!viewer.isOpen()) {
        return;
    }

    // These are the coordinates of europe on this map
    var x = 0.5398693914203284;
    var y = 0.21155952391206562;
    var z = 5;

    viewer.viewport.panTo(new Seadragon.Point(x, y));
    viewer.viewport.zoomTo(z);
    viewer.viewport.ensureVisible();
}

function addOverlays(viewer) {
    drawer = viewer.drawer;
    var img = document.createElement("img");
    img.src = "_assets/Images/pushpin.png";

    $(img).addClass('pushPin');

    var overlays = [
        { elmt: img, point: new Seadragon.Point(0.51, 0.22) },
        { elmt: img, point: new Seadragon.Point(0.20, 0.13) }
    ];

    for (var i = 0; i < overlays.length; i++) {
        drawer.addOverlay(overlays[i].elmt, overlays[i].point);
    }


}

Seadragon.Utils.addEvent(window, "load", init);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-09-11 03:57:22

我应该创建一个返回 img 的函数并在对象数组内调用它

function newpushPin() {
    var img = document.createElement("img");
    img.src = "_assets/Images/pushpin.png";
    return img
}

var overlays = [
    { elmt: newpushPin(), point: new Seadragon.Point(0.51, 0.22) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.53, 0.22) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.53, 0.23) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.50, 0.20) }
];

I should have created a function that returns the img and call that inside the object array

function newpushPin() {
    var img = document.createElement("img");
    img.src = "_assets/Images/pushpin.png";
    return img
}

var overlays = [
    { elmt: newpushPin(), point: new Seadragon.Point(0.51, 0.22) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.53, 0.22) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.53, 0.23) },
    { elmt: newpushPin(), point: new Seadragon.Point(0.50, 0.20) }
];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文