Browse Source

Mapa dos serviços SEIT

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
60aca644d1
  1. 28
      sigi/apps/servicos/views.py
  2. 61
      sigi/templates/servicos/mapa.html
  3. 1
      sigi/templates/snippets/modules/charts-convenios.html
  4. 5
      sigi/urls.py

28
sigi/apps/servicos/views.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.utils import simplejson
from django.db.models import Q
from sigi.apps.servicos.models import CasaAtendida
def municipios_atendidos(self, servico):
municipios = []
servico = servico.upper()
query = Q()
if servico != 'ALL':
for sigla in servico.split('_'):
query = query | Q(tipo_servico__sigla=sigla)
query = Q(data_desativacao=None) & query
for casa in CasaAtendida.objects.all():
if casa.servico_set.filter(query).exists():
m = casa.municipio
municipio = {'nome': casa.nome + ', ' + m.uf.sigla,
'lat': str(m.latitude),
'lng': str(m.longitude),
'servicos': "<ul><li>" + "</li><li>".join([s.tipo_servico.nome for s in casa.servico_set.filter(query)]) + "</li></ul>",}
municipios.append(municipio)
return HttpResponse(simplejson.dumps(municipios), mimetype="application/json")

61
sigi/templates/servicos/mapa.html

@ -0,0 +1,61 @@
{% extends "admin/index.html" %}
{% load adminmedia %}
{% block title %}SIGI{% endblock %}
{% block extrahead %}
{{ block.super }}
<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>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
(function($) {
$(document).ready(function($) {
var latlng = new google.maps.LatLng(-14.2350040, -51.925280);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
myOptions);
$.get("/sigi/servicos/munatenjson/{{ params.servico }}", function(municipios) {
for (var i in municipios) {
var municipio = municipios[i];
var markData = {
map: map,
position: new google.maps.LatLng(municipio.lat, municipio.lng),
title: municipio.nome,
icon: '{{ MEDIA_URL }}images/mapmarker.png' //'/sigi/media/images/mapmarker.png'
}
var mark = new google.maps.Marker(markData);
var infoWin = new google.maps.InfoWindow({content:
'<strong>' + municipio.nome + '</strong><br/>' +
'<strong>Serviço(s):</strong><br/>' + municipio.servicos });
linkMarkMessage(mark, infoWin, map);
}
});
function linkMarkMessage(mark, infoWin, map) {
google.maps.event.addListener(mark, 'click', function() {
infoWin.open(map, mark);});
}
})})(django.jQuery);
</script>
{% endblock %}
{% block content %}
{% comment %}
<div id="painel">
<form method="get">
{% for tipo in servicos %}
<input type="checkbox" value="{{ tipo.sigla }}"/>{{ tipo.nome }}
{% endfor %}
</form>
</div>
{% endcomment %}
<div id="map" style="width:100%; height: 800px; float: left;"></div>
{% endblock %}

1
sigi/templates/snippets/modules/charts-convenios.html

@ -81,6 +81,7 @@
{% endif %}
</tr>
{% endfor %}
<p><a href="/sigi/servicos/mapa/all/">Ver mapa</a></p>
</table>
</div>

5
sigi/urls.py

@ -1,8 +1,9 @@
#-*- coding:utf-8 -*-
from django.conf import settings
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to, direct_to_template
from django.views.generic.simple import redirect_to, direct_to_template
import sites
from sigi.apps.servicos.models import TipoServico
# register admin filters
import admin.filterspecs
@ -90,6 +91,8 @@ urlpatterns = patterns(
(r'^sigi/api/diagnosticos/$',
'sigi.apps.diagnosticos.views.grafico_api'),
# Views dos serviços SEIT
(r'^sigi/servicos/mapa/(?P<servico>\w+)/$', direct_to_template, {'template': 'servicos/mapa.html', 'extra_context': {'servicos': TipoServico.objects.all()}}),
(r'^sigi/servicos/munatenjson/(?P<servico>\w+)/$', 'sigi.apps.servicos.views.municipios_atendidos'),
# (r'^sigi/servicos/listacasas/(?P<sigla>\w+)',
# 'sigi.apps.servicos.views.casas_usam_servico'),
# automatic interface based on admin

Loading…
Cancel
Save