Pregunta

Estoy buscando configurar mi mapa con marcadores de palanca, de modo que cuando un usuario compruebe / desmarca una serie de casillas de verificación en el mapa, la casilla de verificación se verifican en la categoría de marcadores que se muestran, por lo que si 3 de las 4 casillas de verificación son verificada, es decir: la barra, la escuela, el restulaunt, esos son los marcadores por categoría que se muestran, y si alguien desactiva ese 4to marcador o cualquier número de ellos, se volverán invisibles "en sentido", lo que no funciona, he mirado por todas partes. No podría encontrar ninguna referencia que ayude. Soy nuevo en JavaScript y soy competente en PHP. Configuré la matriz de ubicaciones [] para ser una columna de 4 columnas e infinitas hacia abajo. Así que para mí obtener el "tipo de lugar" sus ubicaciones [I] [4] ... He estado en esto durante días y no puedo mejorar. He intentado todas las combinaciones posibles en las que puedo pensar. como dije . Soy un scripter de PHP. Cualquier ayuda es mucho apreciada

<script type="text/javascript">
//PHP - Lat,Lng ARRAY
var locations = [
<?php
$x = 0; $i = 0; $j = 0; $y = 0; $z = 0; $a = 0; $b = 0; $c = 0;
for($aa = 0; $aa < $count; $aa++) {
$content = '<div class="coupon"><div class="ribbon"><div class="ribbon-stitches-top"></div><strong class="ribbon-content"><h1>'.$deal[$y].'</h1></strong><div class="ribbon-stitches-bottom"></div></div><div class="picture_coupon"><img src="'.$deal_photo[$b].'" width="150" height="100" /></div><div class="deal"><center><h1>'.$deal[$y].'</h1>'.$deal_info[$a].'<b>Expires: '.$deal_expiration[$c].'</b></center></div></div>';

echo "['" . $business_name[$x] . "'," . $lat[$i] . "," . $lng[$j] . "," . "'$content'" . ",".$type[$id]. "],";
$x++; $i++; $j++; $id++; $y++; $z++; $a++; $b++; $c++;
}
?>
['' , , ,'' , '']
];  
//PHP - Lat,Lng ARRAY 
  var map;

  function initialize() {
    var myOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'),
        myOptions);

    // Try HTML5 geolocation
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);

// Código inverso PHP Dynamic

var infowindow = new google.maps.InfoWindow();

var marker, i;


//Marker Icon Generation.. Will be changed WHEN make new colors
var blue = '../images/map-icons/blue.png';

for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    icon: blue // iconType[$num] 
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][3]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}

// Código inverso PHP Dynamic // Set de ubicación GEO Centro y manejo de errores

        map.setCenter(pos);
      }, function() {
        handleNoGeolocation(true);
      });
    } else {
      // Browser doesn't support Geolocation
      handleNoGeolocation(false);
    }
  }

  function handleNoGeolocation(errorFlag) {
    if (errorFlag) {
      var content = 'Error: The Geolocation service failed.';
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.';
    }   

// Set de ubicación GEO Centro y manejo de errores

  }

  google.maps.event.addDomListener(window, 'load', initialize);

//================= Intente en la casilla de verificación del marcador de palanca

//== muestra todos los marcadores de una categoría particular, y garantiza que la casilla de verificación está marcada==

  function show(category) {

    for (var i=0; i<locations.length; i++) {

      if (locations[i].mycategory == category) {

        locations[i].setVisible(true);

      }

    }

    // == check the checkbox ==

    document.getElementById(category+"box").checked = true;

  }



  // == hides all markers of a particular category, and ensures the checkbox is cleared ==

  function hide(category) {

    for (var i=0; i<locations.length; i++) {

      if (locations[i].mycategory == category) {

        locations[i].setVisible(false);

      }

    }

    // == clear the checkbox ==

    document.getElementById(category+"box").checked = false;

    // == close the info window, in case its open on a marker that we just hid

    infowindow.close();

  }



  // == a checkbox has been clicked ==

  function boxclick(box,category) {

    if (box.checked) {

      show(category);

    } else {

      hide(category);

    }

    // == rebuild the side bar

    makeSidebar();

  }  
 /*HTML*/<input type ="checkbox" name="resturauntbox" onclick="boxclick(this,'resturaunt')"><label></label>
     <input type ="checkbox" name="barbox" onclick="boxclick(this,'bar')"><label></label>

//============================================ Casilla de verificación // html

¿Fue útil?

Solución

Acabo de configurar un PHP para el bucle con una variable para capturar todas las categorías y una para encenderlos y la otra para ocultarlos.

function checkAll(field)
{
for (j = 0; j < field.length; j++) {
    field[j].checked = true;

}

    for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(true);
                    } 
                }
            }}
function uncheckAll(field)
{

for (j = 0; j < field.length; j++) {
    field[j].checked = false;

}

    for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="American";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Asian";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Deli - Cafe";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Ethnic";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Italian";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Mexican";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Seafood";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }for(var thisisgay =0; thisisgay < 1; thisisgay++) {category ="Sushi";
                for (var i=0; i<locations.length; i++) {
                    if (locations[i][4]) {
                        markers[i].setVisible(false);
                    } 
                }
            }      

}

Otros consejos

Sin ofensa, pero esta es una pregunta muy confusa.Sin embargo, simplemente salga del título, parece que desea agregar y eliminar marcadores.Para agregar marcadores, puede usar lo siguiente:

var marker = new google.maps.Marker({
    position: map.getCenter(), // center marker in map
    map: map,
    shadow: shadow, // MarkerImage type
    icon: image // MarkerImage type
});

Luego, cuando quiera eliminar el marcador del mapa, puede usar esto:

marker.setMap(null);

Por lo tanto, puede crear una función para activar y apagar los marcadores como este:

function toggleMarker(marker, map) {
    if (marker.getMap() == null)
        marker.setMap(map); // marker isn't visible on map, so make it visible
    else
        marker.setMap(null); // marker is visible on map, so make it invisible
}

Si esto no es lo que quieres, lo siento.Me pareció difícil entender tu pregunta.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top