谷歌地图与灯箱图像效果

发布于 2024-10-13 05:32:30 字数 2684 浏览 0 评论 0原文

所以我有一个自定义的谷歌地图,我在上面放置了点,当您单击该图像时,会显示一个 HTML 弹出窗口。

我遇到的问题是我想对弹出 HTML 框中的图像使用 lightbox/fancybox 效果。看起来由于这些是动态生成的,jquery 在页面加载时无法识别它们或无法找到它们。

   <script type="text/javascript">
     function initialize() {

        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(39.470125,83.605957 ), 4); // Taklamakan desert
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var blueIcon = new GIcon(G_DEFAULT_ICON);

            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";

            // Set up our GMarkerOptions object

            markerOptions = { icon:blueIcon };


            // Creates a marker at the given point
            // Clicking the marker will hide it
            function createMarker(latlng, number, myHtml)
            {
                var marker = new GMarker(latlng, markerOptions);
                marker.value = number;
                GEvent.addListener(marker,"click", function() {
                    map.openInfoWindowHtml(latlng, myHtml);
                });
                return marker;
            }



            var latlng = new GLatLng(40.641468, 87.756958 );
            var myHtml = 'Yingpan Man was excavated here near the Könchi River. Yingpan was active from 300 BCE–500 CE. <img src="http://www.penn.museum/silkroad/images/objects/thumbs/yingpan_man_web_thumb.jpg" alt="Yingpan Man" /> <br /><br /><br />';
            map.addOverlay(createMarker(latlng, 0, myHtml));

            var latlng1 = new GLatLng(39.548953, 88.899536 );
            var myHtml1 = 'The Beauty of Xiahoe<br /> <a class="fancier_image" href="images/objects/beauty_xiaohe.jpg"> <img src="images/objects/thumbs/beauty_xiaohe_thumb.jpg" alt="The Beauty of Xiahoe" /> </a> <br /><br /><br />';
            map.addOverlay(createMarker(latlng1, 1, myHtml1));


}
 }


$(document).ready(function() {


    $(".fancier_image").fancybox({
    'overlayShow'   : false,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn'      : 'easeOutBack',
    'easingOut'     : 'easeInBack'

    });

});

</script>

我已经确认 Fancybox 实际上可以在带有 Google 地图中没有的静态图像的页面上运行。

我之前已经通过使用 jquery 查找内容来解决这种情况

$(document).find('a.fancier_image')

,但我需要一个 jquery 事件来关闭,并且由于图像是在页面加载后动态创建的,所以我无法在弹出窗口的 HTML 部分中分配任何内容 a .click事件(或者至少我不知道如何发生)。

回顾一下,我只是希望能够在谷歌地图弹出 HTML 中点击 GLatLng 点的图像上放置一个灯箱/花式盒子。

任何想法或帮助将不胜感激。

So I have a custom google map that I put points on and an HTML popup window shows when you click on that image.

The problem I'm having is that I want to use a lightbox/fancybox effect on images inside the popup HTML box. It seems like since these are dynamically generated that jquery is not recognizing them on page load or can't find them.

   <script type="text/javascript">
     function initialize() {

        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(39.470125,83.605957 ), 4); // Taklamakan desert
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var blueIcon = new GIcon(G_DEFAULT_ICON);

            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";

            // Set up our GMarkerOptions object

            markerOptions = { icon:blueIcon };


            // Creates a marker at the given point
            // Clicking the marker will hide it
            function createMarker(latlng, number, myHtml)
            {
                var marker = new GMarker(latlng, markerOptions);
                marker.value = number;
                GEvent.addListener(marker,"click", function() {
                    map.openInfoWindowHtml(latlng, myHtml);
                });
                return marker;
            }



            var latlng = new GLatLng(40.641468, 87.756958 );
            var myHtml = 'Yingpan Man was excavated here near the Könchi River. Yingpan was active from 300 BCE–500 CE. <img src="http://www.penn.museum/silkroad/images/objects/thumbs/yingpan_man_web_thumb.jpg" alt="Yingpan Man" /> <br /><br /><br />';
            map.addOverlay(createMarker(latlng, 0, myHtml));

            var latlng1 = new GLatLng(39.548953, 88.899536 );
            var myHtml1 = 'The Beauty of Xiahoe<br /> <a class="fancier_image" href="images/objects/beauty_xiaohe.jpg"> <img src="images/objects/thumbs/beauty_xiaohe_thumb.jpg" alt="The Beauty of Xiahoe" /> </a> <br /><br /><br />';
            map.addOverlay(createMarker(latlng1, 1, myHtml1));


}
 }


$(document).ready(function() {


    $(".fancier_image").fancybox({
    'overlayShow'   : false,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn'      : 'easeOutBack',
    'easingOut'     : 'easeInBack'

    });

});

</script>

I have confirmed that the Fancybox actually works on the page with a static image that is not in the Google map.

I have remedied this type of situation before by finding the thing with jquery

$(document).find('a.fancier_image')

but I need a jquery event to go off of and since the image was dynamically created after page load I can't assign anything in the HTML portion of the popup a .click event (or at least I don't know how).

So to recap I just want to be able to put a lightbox/fancybox on an image inside a google maps popup HTML off of a clicked GLatLng point.

Any ideas or help would be greatly appreciated.

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

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

发布评论

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

评论(1

仙女山的月亮 2024-10-20 05:32:30

可能不完全理解您的代码的行为方式,但在 createMarker() 末尾返回标记之前,您是否尝试添加以下内容:

$(document).find('a.fancier_image').fancybox({
    'overlayShow'   : false,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn'      : 'easeOutBack',
    'easingOut'     : 'easeInBack'

    });

编辑:
使用 .livequery() 插件 怎么样?

$("a.fancier_image").livequery(addFancyBox);

Might not fully understand how your code is behaving, but before returning marker at the end of createMarker(), have you tried adding this:

$(document).find('a.fancier_image').fancybox({
    'overlayShow'   : false,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn'      : 'easeOutBack',
    'easingOut'     : 'easeInBack'

    });

Edit:
How about using the .livequery() plugin for this?

$("a.fancier_image").livequery(addFancyBox);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文