Browse Source

Corrige pesquisa do mapa

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
c871a4a53d
  1. 3
      sigi/apps/home/templates/home/mapfilter.html
  2. 83
      sigi/apps/home/templates/home/openmap.html

3
sigi/apps/home/templates/home/mapfilter.html

@ -25,7 +25,8 @@
<form id="searchform" class="form-inline ui-front"> <form id="searchform" class="form-inline ui-front">
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">search</i> <i class="material-icons prefix">search</i>
<input type="text" id="search-text" class="autocomplete" placeholder="Procurar" aria-label="Procurar"> <input type="text" class="search-text" placeholder="{% trans "Procurar" %}" aria-label="{% trans "Procurar" %}">
<div class="search-result hide"></div>
</form> </form>
</div> </div>
</div> </div>

83
sigi/apps/home/templates/home/openmap.html

@ -58,53 +58,52 @@
var options = {color: 'blue', fillColor: 'red', fillOpacity: 0.4, radius: 500}; var options = {color: 'blue', fillColor: 'red', fillOpacity: 0.4, radius: 500};
var unfiltred_options = {color: 'red', fillColor: 'red', fillOpacity: 0, radius: 1000}; var unfiltred_options = {color: 'red', fillColor: 'red', fillOpacity: 0, radius: 1000};
$("#search-text").each(function() { $(".search-text").on("input change", function() {
var search = M.Autocomplete.init(this, { $resultbox = $(".search-result");
minLength: 3, var $this = $(this);
onAutocomplete: function(label) { var term = $this.val();
var data = search.options.ajaxdata;
for (k in data) { if (term.length < 3) {
if (data[k].label == label) { $resultbox.html("");
mymap.flyTo([data[k].lat, data[k].lng], 8.5); $resultbox.addClass("hide");
var encontrado = false; return;
mymap.eachLayer(function(layer) { }
if (layer instanceof L.Circle) {
if (layer.orgao_id == data[k].id) { $.get("{% url "openmapsearch" %}", {"q": term}, function(data) {
layer.openPopup(); $resultbox.html("");
encontrado = true; for (i in data) {
} var plain = JSON.stringify(data[i]);
} var $item = $(`<a href="#" class="search-result-item" data-orgao='${plain}'></a>`);
}) $item.html(data[i].label);
if (!encontrado) { $item.prop("data_item", data[i]);
var mark = L.circle([data[k].lat, data[k].lng], unfiltred_options).bindTooltip(data[k].label).bindPopup("").addTo(mymap); $resultbox.append($item);
mark.orgao_id = data[k].id }
mark.openPopup(); $resultbox.removeClass("hide");
$(".search-result-item").on("click", function() {
var plain = $(this).attr("data-orgao");
var result = JSON.parse(plain);
console.log(result);
$this.val(result.label);
$resultbox.html("").addClass("hide");
mymap.flyTo([result.lat, result.lng], 8.5);
var encontrado = false;
mymap.eachLayer(function(layer) {
if (layer instanceof L.Circle) {
if (layer.orgao_id == result.id) {
layer.openPopup();
encontrado = true;
} }
} }
});
if (!encontrado) {
var mark = L.circle([result.lat, result.lng], unfiltred_options).bindTooltip(result.label).bindPopup("").addTo(mymap);
mark.orgao_id = result.id
mark.openPopup();
} }
}
});
$(this).on("input change", function() {
if (this.value.length < search.options.minLength) {
return;
};
$.ajax({
url: "{% url "openmapsearch" %}",
data: {"q": this.value },
dataType: "json",
appendTo: "#searchform",
success: function(data) {
console.log(data);
var result = {};
for (k in data) {
result[data[k].label] = null;
}
search.updateData(result);
search.options['ajaxdata'] = data;
},
}); });
}); });
}) });
$("input[type=checkbox]").change(filtra); $("input[type=checkbox]").change(filtra);

Loading…
Cancel
Save