From ec5d1a951e75f8bbbd95185bae0673fd421d328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 20 Dec 2012 18:34:39 -0200 Subject: [PATCH] =?UTF-8?q?Adicionada=20pesquisa=20por=20nome=20do=20munic?= =?UTF-8?q?=C3=ADpio=20no=20mapa=20de=20atua=C3=A7=C3=A3o=20do=20Interlegi?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media/js/metas/mapa.js | 53 +++++++++++++++++++++++++++++----- sigi/templates/metas/mapa.html | 16 ++++++++++ sigi/urls.py | 1 + 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/media/js/metas/mapa.js b/media/js/metas/mapa.js index 56a5bce..c3f9fee 100644 --- a/media/js/metas/mapa.js +++ b/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: '' + municipio.nome + '

' + 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); \ No newline at end of file diff --git a/sigi/templates/metas/mapa.html b/sigi/templates/metas/mapa.html index 700369f..5cc2f60 100644 --- a/sigi/templates/metas/mapa.html +++ b/sigi/templates/metas/mapa.html @@ -5,6 +5,7 @@ {% block extrahead %} {{ block.super }} + @@ -12,6 +13,21 @@ {% endblock %} +{% block content_title %} +

Mapa de atuação do Interlegis

+
+
+ +
+
+{% endblock %} {% block content %}
diff --git a/sigi/urls.py b/sigi/urls.py index ef7e3df..ce90735 100644 --- a/sigi/urls.py +++ b/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)),