Карты Google скрывают маркер (и информацию) и отображаются только при нажатии на область с информацией - PullRequest
0 голосов
/ 14 ноября 2009

Я хочу добавить прозрачный png в карты Google вместо использования значка по умолчанию. Где в моем примере кода я бы изменил значок по умолчанию на png с именем transparent.png?

Спасибо!

 function onLoad() {
      map = new GMap(document.getElementById("div_map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(54, -3), 5);

      getMarkers();

      GEvent.addListener(map, "click", function(overlay, point) {
          if (overlay){ // marker clicked
              overlay.openInfoWindowHtml(overlay.infowindow);   // open InfoWindow
          } else if (point) {   // background clicked

          }
      });
    }

    function getMarkers(){
        var urlstr="read.php";
        var request = GXmlHttp.create();
        request.open('GET', urlstr , true); // request XML from PHP with AJAX call
        request.onreadystatechange = function () {
            if (request.readyState == 4) {
                var xmlDoc = request.responseXML;
                locations = xmlDoc.documentElement.getElementsByTagName("location");
                markers = [];
                if (locations.length){
                    for (var i = 0; i < locations.length; i++) { // cycle thru locations
                        markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng")));
                        // Add attributes to the marker so we can poll them later.
                        // When clicked, an overlay will have these properties.
                        markers[i].infowindow = "This is "+locations[i].getAttribute("name");

                        // Useful things to store on a marker (Not needed for this example, could be removed)
                        // Tells you what index in the markers[] array an overlay is
                        markers[i].markerindex = i;
                        // Store the location_id of the location the marker represents.
                        // Very useful to know the true id of a marker, you could then make
                        // AJAX calls to the database to update the information if you had it's location_id
                        markers[i].db_id = locations[i].getAttribute("location_id");

                        map.addOverlay(markers[i]);

                    }
                }
            }
        }
        request.send(null);
    }

Ответы [ 2 ]

0 голосов
/ 14 ноября 2009

Вы можете использовать почти невидимый файл PNG в качестве маркера в обычном GIcon.image, вам просто нужно быть осторожным, чтобы в качестве цели клика было что-то непрозрачное на 100%. Это может быть либо GIcon.image, либо GIcon.transparent. Некоторые браузеры не обрабатывают клики на объектах, которые прозрачны на 100%.

Одна из проблем этого подхода заключается в том, что активная область будет изменяться при изменении уровня масштабирования. Альтернативный подход - рисовать невидимые кликабельные многоугольники, чтобы отмечать области, в которых есть информация. В этом случае полигоны могут быть прозрачными на 100%, потому что API не полагается на то, что браузер определяет, был ли нажат полигон.

0 голосов
/ 14 ноября 2009

То есть вы вообще не хотите, чтобы маркер показывался? Просто отреагировать, запустив всплывающее окно? Я бы поменял иконку с пользовательскими прозрачными png.

http://code.google.com/apis/maps/documentation/reference.html#GIcon

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...