Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: google map, powracające znaczniki
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
nmts
Pobieram wszystkie znaczniki i umieszczam na mapie,
następnie pobieram znaczniki będące tylko podzbiorem tamtych znaczników, czyszcząc oczywiście mapę i tablicę,
i jest ok do czasu kiedy zrobie zoom - powracają wszystkie poprzednie znaczniki.

Kod poucinany tu i ówdzie wygląda tak:
  1. <script type='text/javascript'>
  2. <!--
  3. var mapa = null;
  4. var obszar = null;
  5. var markery = [];
  6. var mmgr;
  7.  
  8. $(function(){
  9. load_map();
  10.  
  11. $("input[type=submit]").click(function(){
  12. $('.ajax-loader').slideDown('slow');
  13. var form = $("form#map_search").serialize();
  14. $.ajax({
  15. url: "<?php echo url::base(); ?>ajax/getObjects/",
  16. type: "POST",
  17. data: form,
  18. dataType: "xml",
  19. success: function(data){
  20. markers = data.documentElement.getElementsByTagName('marker');
  21. dodajMarkery(markers);
  22. $('.ajax-loader').slideUp('slow');
  23. },
  24. error: function( xhrInstance, message, optional ){ alert(xhrInstance + " - " + message); }
  25. });
  26. return false;
  27. });
  28.  
  29. <?php if(isset($subdomain_city)){ ?>
  30. $("input[type=submit]").trigger('click');
  31. <?php } ?>
  32. });
  33.  
  34. // definiuje ikony
  35. var icon_normal = new GIcon();
  36. icon_normal.image = '<?php echo url::base(); ?>assets/img/marker_normal.png';
  37. icon_normal.shadow = "<?php echo url::base(); ?>assets/img/shadow-marker_normal.png";
  38. icon_normal.shadowSize = new GSize(25,16);
  39. icon_normal.iconSize = new GSize(16,16);
  40. icon_normal.infoWindowAnchor = new GPoint(16,16);
  41. icon_normal.iconAnchor = new GPoint(10,10);
  42. var icon_distinction = new GIcon(icon_normal);
  43. icon_distinction.image = '<?php echo url::base(); ?>assets/img/marker_distinction.png';
  44. var icon_rebate = new GIcon(icon_normal);
  45. icon_rebate.image = '<?php echo url::base(); ?>assets/img/marker_rebate.png';
  46. var icon_all_year = new GIcon(icon_normal);
  47. icon_all_year.image = '<?php echo url::base(); ?>assets/img/marker_all_year.png';
  48.  
  49. function dodajMarkery(markers)
  50. {
  51. wyczyscMape();
  52. //console.log(markers);
  53. markers_number = markers.length;
  54. if(markers_number){
  55. $("#lokalizator .details").show();
  56. $("#lokalizator .details strong").html(markers_number);
  57. } else {
  58. $("#lokalizator .details").hide();
  59. }
  60.  
  61. for (var i = 0; i < markers_number; i++)
  62. {
  63. //console.log(i);
  64. _marker = markers[i];
  65. var lat = _marker.getAttribute('lat');
  66. var lng = _marker.getAttribute('lng');
  67. var punktLatLng = new GLatLng(parseFloat(lat),parseFloat(lng));
  68. icon = definiujIkone(_marker);
  69. var marker = new GMarker(punktLatLng, {icon: icon, clickable: true, title: _marker.getAttribute('title')});
  70. dodajMarker(marker, minimalnyZoom(_marker), "<div style='width: 300px; overflow: hidden;'><div style='float: left; width: 18px;'><img src='"+icon.image+"' /></div><div style='float: left; width: 280px;'><a href='<?php echo url::base(); ?>"+_marker.getAttribute('category_slug')+","+_marker.getAttribute('id')+"' style='font-size: 1.1em;'><strong>"+_marker.getAttribute('title')+"</strong></a><br /><div style='padding: 10px 0; margin-top: 10px; border-bottom: 1px solid #eee; border-top: 1px solid #eee;'>"+_marker.getAttribute('description')+"</div><br /><a href='<?php echo url::base(); ?>"+_marker.getAttribute('category_slug')+","+_marker.getAttribute('id')+"'><img src='"+_marker.getAttribute('image')+"' style='border: 1px solid #f3f3f3; width: 100px; margin: 10px 0 0 75px;' /></a></div></div>");
  71. markery.push(marker);
  72. }
  73. }
  74.  
  75. function dodajMarker(marker, minZoom, html){
  76. mmgr.addMarker(marker, minZoom, 17);
  77. GEvent.addListener(marker, "click", function() {
  78. marker.openInfoWindowHtml(html);
  79. });
  80. }
  81.  
  82. function definiujIkone(marker){
  83. if(marker.getAttribute('distinction') == 1) icon_type = icon_distinction;
  84. else if(marker.getAttribute('rebate') != 0) icon_type = icon_rebate;
  85. else if(marker.getAttribute('all_year') == 1) icon_type = icon_all_year;
  86. else icon_type = icon_normal;
  87.  
  88. return icon_type;
  89. }
  90.  
  91. function wyczyscMape(){
  92. mapa.clearOverlays();
  93. var markery = [];
  94. }
  95.  
  96. function minimalnyZoom(marker_xml){
  97. packet = marker_xml.getAttribute('packet');
  98. if(packet == 2) return 11;
  99. else if(packet == 1) return 9;
  100. else if(packet == 3) return 7;
  101. }
  102.  
  103. function load_map()
  104. {
  105. if(GBrowserIsCompatible())
  106. {
  107. mapa = new google.maps.Map(document.getElementById('map'));
  108. mmgr = new GMarkerManager(mapa,{maxZoom: 17});
  109. <?php if(isset($subdomain_city)){ ?>
  110. mapa.setCenter(new GLatLng(<?php echo $subdomain_city->lat ?>,<?php echo $subdomain_city->lng ?>),14);
  111. <?php } else { ?>
  112. mapa.setCenter(new GLatLng(53.90692700949985,17.830810546875),7);
  113. <?php } ?>
  114. mapa.addControl(new GScaleControl());
  115. mapa.addControl(new GLargeMapControl());
  116. mapa.addControl(new GMapTypeControl());
  117. mapa.enableContinuousZoom();
  118. mapa.enableScrollWheelZoom();
  119. mapa.addControl(new GOverviewMapControl());
  120. mapa.addMapType(G_PHYSICAL_MAP)
  121.  
  122. GEvent.addListener(mapa,'mousemove',function(p)
  123. {
  124. if(!obszar || !obszar.punkt1)
  125. return;
  126. obszar.ustawPunktKoncowy(p);
  127. });
  128.  
  129. GEvent.addListener(mapa,'click',function(o,p)
  130. {
  131. if(obszar && obszar.status != "stop"){
  132. obszar.remove();
  133. obszar = null;
  134. }
  135. });
  136.  
  137. GEvent.addListener(mapa,'singlerightclick',function(o,p)
  138. {
  139. //if(!p) return;
  140.  
  141. if(obszar && obszar.status == "stop"){
  142. obszar.remove();
  143. obszar = null;
  144. }
  145.  
  146. if(!obszar){
  147. p = mapa.fromContainerPixelToLatLng(o);
  148. obszar = new ZaznaczObszar(p);
  149. obszar.status = "move";
  150. mapa.addOverlay(obszar);
  151. } else {
  152. obszar.status = "stop";
  153. latlngs = obszar.pobierz();
  154. window.location = "<?php echo url::base(); ?>szukaj?latlngs="+latlngs;
  155. }
  156. });
  157. }
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. -->
  166. </script>
arecki
Nie tylko Ty masz taki problem smile.gif poczytaj tutaj i tutaj smile.gif
nmts
Kurde, zastosowałem tą metodę z drugiego linka i nic nie zmieniła. :/ Próbowałem też sposobu z nadpisaniem:

Kod
    var unusedManager = new GMarkerManager(map);

    function killMarkers() {
        map.clearOverlays();
        manager.refresh = function() {};
        manager.Ko = function() {};
    }

    function resurectMarkers() {
        manager.refresh = unusedManager.refresh;
        manager.Ko = unusedManager.Ko;
        manager.refresh();
    }


Również bez skutku... ohmy.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.