Browse Source

Adicionada pesquisa por nome do município no mapa de atuação do Interlegis

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
ec5d1a951e
  1. 53
      media/js/metas/mapa.js
  2. 16
      sigi/templates/metas/mapa.html
  3. 1
      sigi/urls.py

53
media/js/metas/mapa.js

@ -1,9 +1,10 @@
(function($) {
var map; // O mapa - Será carregado assim que o documento estiver pronto
var municipiosArray = [];
var municipiosArray = {};
$(document).ready(function($) {
$("input[type='checkbox']").change(filter);
$("#changelist-search").submit( search );
var latlng = new google.maps.LatLng(-14.2350040, -51.925280);
var myOptions = {
zoom: 5,
@ -22,12 +23,10 @@
cache: true,
success: function(return_data) {
// Delete all markers
if (municipiosArray) {
for (i in municipiosArray) {
municipiosArray[i].setMap(null);
}
for (i in municipiosArray) {
municipiosArray[i].setMap(null);
}
municipiosArray.length = 0;
municipiosArray = {}
// Create new markers
for (var i in return_data) {
@ -42,7 +41,7 @@
var infoWin = new google.maps.InfoWindow({content: '<strong>' + municipio.nome + '</strong><br/><br/>' + municipio.info });
linkMarkMessage(mark, infoWin, map);
municipio['mapmark'] = mark
municipiosArray.push(municipio);
municipiosArray[i] = municipio;
}
filter(null);
}});
@ -99,4 +98,44 @@
}
}
function search(event) {
var data =
$.ajax({
url: "/sigi/dashboard/mapsearch/",
type: 'GET',
data: $("#changelist-search").serializeArray(),
cache: true,
success: function(return_data) {
if (return_data.result == 'NOT_FOUND') {
$("#search-panel").html('Nenhum município encontrado.');
return;
}
if (return_data.ids.length == 1) {
$("#search-panel").html('um município encontrado.');
} else {
$("#search-panel").html(return_data.ids.length + ' municípios encontrados.');
}
var total = 0;
for (var i in return_data.ids) {
var municipio = municipiosArray[return_data.ids[i]];
if (typeof(municipio) != 'undefined') {
google.maps.event.trigger(municipio.mapmark, 'click');
total = total + 1;
}
}
if (total == 0) {
$("#search-panel").html('Nenhum município encontrado.');
return;
}
if (total == 1) {
$("#search-panel").html('um município encontrado.');
} else {
$("#search-panel").html(total + ' municípios encontrados.');
}
}});
return false;
}
})(django.jQuery);

16
sigi/templates/metas/mapa.html

@ -5,6 +5,7 @@
{% block extrahead %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
<script type="text/javascript" src="{% admin_media_prefix %}js/core.js"></script>
<script type="text/javascript" src="{% admin_media_prefix %}js/jquery.min.js"></script>
<script type="text/javascript" src="{% admin_media_prefix %}js/jquery.init.js"></script>
@ -12,6 +13,21 @@
<script type="text/javascript" src="{{ MEDIA_URL }}js/metas/mapa.js"></script>
{% endblock %}
{% block content_title %}
<h1>Mapa de atuação do Interlegis</h1>
<div id="changelist">
<div id="toolbar">
<form method="get" action="" id="changelist-search">
<div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img alt="Search" src="/sigi/admin_media/img/admin/icon_searchbox.png"></label>
<input type="text" id="searchbar" value="" name="q" size="40">
<input type="submit" value="Pesquisar">
<span id="search-panel" class="small quiet">&nbsp;</span>
</div>
</form>
</div>
</div>
{% endblock %}
{% block content %}
<div id="map" style="width:100%; height: 800px; float: left;">
<!-- google map -->

1
sigi/urls.py

@ -99,6 +99,7 @@ urlpatterns = patterns(
# Views de dashboard
(r'^sigi/dashboard/mapa/$', 'sigi.apps.metas.views.mapa'),
(r'^sigi/dashboard/mapdata/$', 'sigi.apps.metas.views.map_data'),
(r'^sigi/dashboard/mapsearch/$', 'sigi.apps.metas.views.map_search'),
# automatic interface based on admin
#(r'^sigi/(.*)', sites.default.root),
(r'^sigi/', include(sites.default.urls)),

Loading…
Cancel
Save