简体   繁体   English

如何将标记添加到rich:gmap组件?

[英]How to add marker to rich:gmap component?

I can see that I cannot specify the gmap marker in atribute.. I suppose that I need to use a4j function inside this tag. 我可以看到我无法在属性中指定gmap标记。我想我需要在此标记内使用a4j函数。 The problem is that I am complete newbie to this stuff... Could anyone tell me how to do this? 问题是我是这个东西的新手...谁能告诉我该怎么做? step by step solution would be greatly appreciated... I have api key and map component (worked with lat and lng, zoom, etc) but need to leave a marker in the center of the map... 逐步解决方案将不胜感激...我有api键和地图组件(与lat和lng,zoom等配合使用),但需要在地图中心保留一个标记...

<rich:gmap gmapVar="map" id="map" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"

I believe there is an easy way to do that... 我相信有一个简单的方法可以做到...

UPDATE: 更新:

<a4j:form>
    <rich:gmap gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.658471" lng="12.59084" mapType="G_NORMAL_MAP" zoom="12">
    </rich:gmap>
    <script type="text/javascript">
          window.onload = function() {
             mapVar.addOverlay(new GMarker(50, 12));
         }
    </script>
</a4j:form>

This one is no joy, I tried to do everything programaticaly, but still no joy. 这一点都不快乐,我试图以编程的方式做所有事情,但仍然没有喜悦。 It displays the marker, but every time (no matter what are my coordinates) it is displayed in top left corner. 它显示标记,但是每次(无论我的坐标是什么)都将其显示在左上角。 Here is the programatic code: 这是程序代码:

<head>
    <title>map</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw"
            type="text/javascript"></script>
    <script type="text/javascript">
        function initialize() {
            if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map_canvas"));
                map.setCenter(new GLatLng(37.4419, -122.1419), 13);
                map.setUIToDefault();
                map.addOverlay(new GMarker(38, -130));
            }
        }
    </script>
</head>
<body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>

Please help. 请帮忙。

UPDATE 2: The body of map.jsp file: 更新2:map.jsp文件的主体:

<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <body>
            <a4j:form>
                <rich:gmap id="mapVar" gmapVar="mapVar" gmapKey="ABQIAAAAr_kWlyTgX4yfWopvtEcxDRRRDOqc_-HaCvCgl460ugpXPxZCkhQyHpWen4IabAs4w-La8EuEU92tPw" lat="55.664515" lng="12.579517" mapType="G_NORMAL_MAP" zoom="12">
                </rich:gmap>
                <script type="text/javascript">
                    window.onload = function() {
                        mapVar.addOverlay(new GMarker(new GLatLng(55.658471, 12.59084)));
                    }
                </script>

            </a4j:form>
        </body>
    </html>
</f:view>

For example: 例如:

<rich:gmap var="mapVar" ... />

and then (in a javascript block, below the definition of <rich:gmap> ) 然后(在javascript块中, <rich:gmap>的定义下方)

window.onload = function() {
    mapVar.addOverlay(
        new GMarker(new GLatLng(#{yourBean.lat}, #{yourBean.lng})));
}

You should take a look at the Google maps API for all possible ways of loading your map. 您应该查看Google Maps API,了解所有可能的地图加载方式。

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

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