def create_map(location, size=(250, 250)): class MapForm(forms.Form): map = forms.Field(widget=GoogleMap(attrs={ 'width': size[0], 'height': size[1] })) if location != None and location.latitude != None and location.longitude != None: if location.street != "": zoom = 13 else: zoom = 10 gmap = maps.Map( opts={ 'center': maps.LatLng(location.latitude, location.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': zoom, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(location.latitude, location.longitude), }) map = MapForm(initial={'map': gmap}) return map, True else: return None, False
def map(request, images, lat, lng): gmap = maps.Map( opts={ 'center': maps.LatLng(float(lat), float(lng)), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 2, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) for image in images: location = image.location if not image.has_latlng(): continue lat, lng = location.lat, location.lng if not lat or not lng: continue marker = maps.Marker(opts={ 'map': gmap, 'title': image.title, 'position': maps.LatLng(lat, lng) }) maps.event.addListener(marker, 'click', 'myobj.markerOver') #maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<a href="' + reverse('image', args=(image.pk, )) + '"><h1 class="marker_title">' + image.title + '</h1><img class="marker_image" src="/' + image.image.url + '"></a>', 'disableAutoPan': False }) info.open(gmap, marker) return gmap
def oferta_detalhe(request, cidade_slug, oferta_slug): cidade = Cidade.objects.get(slug=cidade_slug) cidades_disponiveis = Cidade.objects.all() try: user_msg = request.GET.get('user_msg', None) except: user_msg = None oferta = get_object_or_404(Oferta, slug=oferta_slug) if not oferta.esta_expirado(): tempo_restante = oferta.publicado_em.strftime( "%d,%m,%Y") #+ ' 11:59 PM' else: tempo_restante = -1 #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(oferta.latitude, oferta.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU #'style': maps.MapTypeControlStyle }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(oferta.latitude, oferta.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + oferta.anunciante.nome + '</h3>' + '<p>Rua: ' + oferta.anunciante.endereco + '</p>' + '<p>Telefone: ' + oferta.anunciante.telefone + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'oferta': oferta, 'tempo_restante': tempo_restante, 'cidades_disponiveis': cidades_disponiveis, } return render_to_response('oferta_detalhes.html', context)
def cupon_detalhes(request, cidade_slug, cupon_slug): cidade = get_object_or_404(Localizacao, slug=cidade_slug) cidades_disponiveis = Localizacao.objects.filter(ativo=True) cupom = get_object_or_404(Cupon, slug=cupon_slug) #cidade_cliente=_cidade_cliente(request) cidade_cliente = 'goiania' #pega a mensagem da url try: user_msg = request.GET.get('user_msg', None) except: user_msg = None #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(cupom.latitude, cupom.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(cupom.latitude, cupom.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + cupom.anunciante.nome + '</h3>' + '<p>Rua: ' + cupom.anunciante.endereco + '</p>' + '<p>Telefone: ' + cupom.anunciante.telefone + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) form_busca = FormBuscar() context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'cupom': cupom, # 'porcentagem_vendido': porcentagem_vendido, # 'desconto': desconto, 'form_busca': form_busca, 'cidade_cliente': cidade_cliente, 'cidades_disponiveis': cidades_disponiveis, } return render_to_response('oferta/oferta_detalhes.html', context)
def mapview(request, template_name='bikematchapp/mapview.html'): gmap = maps.Map( opts={ 'center': maps.LatLng(34.122605, -118.309708), #USC is 34.0205N, 118.2856W 'mapTypeId': maps.MapTypeId.ROADMAP, #'size': maps.Size(800,600), 'zoom': 11, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) for profile in Profile.objects.all(): if profile.location: if profile.profile_pic_small.url: image = os.path.join(profile.profile_pic_small_border.url) else: image = os.path.join(settings.STATIC_URL, "images", "bike_blue.png") marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(profile.location.latitude, profile.location.longitude), 'icon': image, 'profile_username': profile.user.username }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') maps.event.addListener(marker, 'click', 'myobj.onClick') contentString = '<div class="row"><div class="span2"><img src="%s"/></div><div class="span2"><p><strong>%s</strong></p><p>%s</p></div></div>' % ( escape(profile.profile_pic_med.url), escape( profile.name), escape(profile.about[:60] + "..")) info = maps.InfoWindow({ 'content': contentString, }) info.open(gmap, marker) return render_to_response(template_name, {'form': MapForm(initial={'map': gmap})}, context_instance=RequestContext(request))
def oferta_detalhe(request, cidade_slug, oferta_slug): try: user_msg = request.GET.get('user_msg', None) except: user_msg = None oferta = get_object_or_404(Oferta, slug=oferta_slug) if not oferta.esta_expirado(): tempo_restante = oferta.publicado_em.strftime( "%Y,%m,%d") #+ ' 11:59 PM' else: tempo_restante = -1 #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(oferta.latitude, oferta.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU #'style': maps.MapTypeControlStyle }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(oferta.latitude, oferta.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({'content': 'Hello!', 'disableAutoPan': True}) info.open(gmap, marker) context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'oferta': oferta, 'tempo_restante': tempo_restante, } return render_to_response('oferta_detalhes.html', context)
def get_map(self,profile): if (profile.location == None): return None gmap = maps.Map(opts={ 'center': maps.LatLng(profile.location.latitude, profile.location.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 12, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng(profile.location.latitude, profile.location.longitude), }) return gmap
def get_map(request, latitude=Substation.get_center_latitude(), longitude=Substation.get_center_longitude(), zoom=8): gmap = maps.Map( opts={ 'center': maps.LatLng(latitude, longitude), 'mapTypeId': maps.MapTypeId.HYBRID, 'zoom': zoom, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DEFAULT }, }) substations = Substation.objects.all() substation_url = 'http://' + request.get_host() + '/substation/' for substation in substations: marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(substation.position.latitude, substation.position.longitude), }) marker.setTitle(substation_url + str(substation.pk)) maps.event.addListener(marker, 'click', 'marker.markerClick') maps.event.addListener(marker, 'mouseover', 'marker.markerOver') maps.event.addListener(marker, 'mouseout', 'marker.markerOut') info = maps.InfoWindow({ 'content': substation.name, 'disableAutoPan': True }) info.open(gmap, marker) return gmap
def generate_map(latitude, longitude): if not latitude or not longitude: return None gmap = maps.Map( opts={ 'center': maps.LatLng(latitude, longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 12, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng(latitude, longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({'content': 'Hello!', 'disableAutoPan': False}) info.open(gmap, marker) return MapForm(initial={'map': gmap})
def get_map(self): gmap = maps.Map() for form_object in self.object_list: if form_object.show_on_map: try: lng, lat = getattr(form_object, form_object.location_field()).coords marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng(lat, lng), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<a href="{url}">{text}</a>'.format( text=form_object.__unicode__().encode('utf-8'), url=reverse('web_update', kwargs={ 'model_name': form_object.model_name(), 'pk': form_object.pk })), 'disableAutoPan': True }) info.open(gmap, marker) except (TypeError, AttributeError ): #no coordinates field or it has invalid value continue class MapForm(Form): map = Field(widget=GoogleMap(attrs={'width': 800, 'height': 550})) return MapForm(initial={'map': gmap})
def mapa(request): template = get_template("mapa.html") uri = request.GET.get('param','') kk = Koszyk.objects.get(nazwa=uri) kkk = kk.atrakcje.all() kkko = list(kkk) kkkoo = kkko.pop(0) kkkkk = kkkoo.miastoto kkkkkk = Miasta.objects.get(miasto=kkkkk) wsp_m = kkkkkk.wspolrzedne gmap = maps.Map(opts = { 'center': maps.LatLng(wsp_m.wsp_y, wsp_m.wsp_x), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 13, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) najlepszaLista = list(kkk) najlepszaDlugosc = 100000 for num in range(0, 10000): kopiaNajlepszej = [] kopiaNajlepszej.extend(najlepszaLista) nowaLista = [] nowaLista.append(kopiaNajlepszej.pop(0)) ostatnie = kopiaNajlepszej.pop() dlugosc = len(kopiaNajlepszej) for numm in range(0, dlugosc): nrAtrakcji = kopiaNajlepszej.pop(random.randrange(0, len(kopiaNajlepszej))) nowaLista.append(nrAtrakcji) nowaLista.append(ostatnie) suma = 0 for nummm in range(0, len(nowaLista)-1): nl1 = nowaLista[nummm] nl1wsp = nl1.wspolrzedne n = nummm+1 nl2 = nowaLista[n] nl2wsp = nl2.wspolrzedne wynik = math.sqrt(math.pow((nl2wsp.wsp_x-nl1wsp.wsp_x),2)+math.pow((nl2wsp.wsp_y-nl1wsp.wsp_y),2)) suma= suma + wynik dlugoscNowej = suma if dlugoscNowej<najlepszaDlugosc: najlepszaDlugosc=dlugoscNowej najlepszaLista=nowaLista z = 0 nr = 1 czas = 0 path = [] for ko in najlepszaLista: wsp = ko.wspolrzedne if z==0: l1 = maps.LatLng(wsp.wsp_y, wsp.wsp_x) path.append(l1) z = 1 else: l2 = maps.LatLng(wsp.wsp_y, wsp.wsp_x) path.append(l2) czas+=ko.czas marker = maps.Marker(opts = { 'map': gmap, 'position': maps.LatLng(wsp.wsp_y, wsp.wsp_x), 'title': ko.nazwa, 'label': nr, }) nr+=1 czasd = najlepszaDlugosc*1000 czas+=czasd czasy=math.ceil(czas) czass = math.floor(czas/60) czasss = czasy - czass*60 if z==1: polyline = maps.Polyline(opts={'map':gmap,'path':path, 'strokeColor':'#0066cc', 'strokeWeight':3, 'strokeOpacity':1}) context = {'form': MapForm(initial={'mapa': gmap}), 'nazwa':uri, 'lista':najlepszaLista, 'droga':czass, 'droga2':czasss} else: context = {'form': MapForm(initial={'mapa': gmap}), 'nazwa':uri,'lista':najlepszaLista,} variables = RequestContext(request,context) output = template.render(variables) return HttpResponse(output)
def dana(request, **kwargs): tmpl = 'core/dana.html' #Contains counts of #encounters/x, x is location, concept, etc. numencs = {} #Contains counts of #subjects/x, x is location, concept, etc. All x except location are associated with subject via the encounters numsubjs = {} #Contains counts of #x and #x that have actually happened in the trial so far nums = {'enum':Encounter.objects.all().count()} numencs['e_in_s'] = Subject.objects.annotate(revcount = Count('encounter')).order_by('-revcount') nums['snum'] = numencs['e_in_s'].count() nums['snum_in_e'] = numencs['e_in_s'].exclude(revcount=0).count() numencs['e_in_p'] = Procedure.objects.annotate(revcount = Count('encounter')).order_by('-revcount') numencs['e_in_cc'] = Concept.objects.annotate(revcount = Count('encounter')).order_by('-revcount') numencs['e_in_o'] = Observer.objects.annotate(revcount = Count('encounter')).order_by('-revcount') nums['onum_in_e'] = numencs['e_in_o'].exclude(revcount=0).count() nums['onum'] = numencs['e_in_o'].count() numsubjs['s_in_l'] = Location.objects.annotate(revcount = Count('subject')).order_by('-revcount') numsubjs['o_s_in_e'] = Observer.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numsubjs['p_s_in_e'] = Procedure.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numsubjs['cc_s_in_e'] = Concept.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numencs['e_in_l'] = Location.objects.annotate(revcount = Count('subject__encounter')).order_by('-revcount') #All EncounterTasks that have an associated concept datesas = EncounterTask.objects.exclude(concept = '').prefetch_related() #structures that will contain sorted counts of late, ontime, early, and missing encounters basedict = {'conc': [], 'proc': [], 'loc': [], 'subj': [], 'obs': [], 'days': [], 'count': 0} timely = {'late': deepcopy(basedict), 'ontime': deepcopy(basedict), 'early': deepcopy(basedict), 'missing': deepcopy(basedict)} #function that returns whether an encounter was late, ontime, or early, and by how much def checklate(a,b): ch = (a-b).days if ch > 0: return (ch, 'late') elif ch < -1: return (abs(ch), 'early') else: return (abs(ch), 'ontime') #Adds values to appropriate list def sorttimes(entry, delay, late, timely): timely[late]['conc'].append(entry.concept) timely[late]['proc'].append(entry.procedure) timely[late]['loc'].append(entry.subject.location) timely[late]['subj'].append(entry.subject) timely[late]['obs'].append(entry.observer) timely[late]['days'].append(delay) timely[late]['count'] += 1 upcomingcount = 0 #for each EncounterTask, finds and processes corresponding encounters for x in datesas: f = Encounter.objects.filter(subject = x.subject).filter(concept = x.concept) #checks if nonextant encounters were already due. If so, they are missing. If not, they are upcoming if f.count() == 0: delay, late = checklate(datetime.today().date(), x.due_on.date()) if late == 'late': timely['missing']['conc'].append(x.concept) timely['missing']['proc'].append(x.procedure) timely['missing']['loc'].append(x.subject.location) timely['missing']['subj'].append(x.subject) timely['missing']['obs'].append(x.assigned_to) timely['missing']['days'].append(delay) timely['missing']['count'] += 1 else: upcomingcount += 1 else: #processes existing encounters for entry in f: delay, late = checklate(entry.modified.date(), x.due_on.date()) sorttimes(entry, delay, late, timely) #actually perform sorted counts on the entries that have been assigned to each category danacounts = {} for x in timely: danacounts[x] = {} for y in timely[x]: if y != 'count': danacounts[x][y] = Counter(timely[x][y]).most_common() #function that takes in a uuid and returns a hex color of the form XXXXXX def chwtocolor(uuid): return uuid.replace('-','').upper()[2:8] #Sets the basic map options gmap = maps.Map(opts = { 'center': maps.LatLng(19.3, -72.7), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 9, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) chwscolors = {} for x in Observer.objects.all(): chwscolors[x.uuid] = {'color': chwtocolor(x.uuid), 'chw': x} markers = [] pinImages = [] infos = [] content = [] mycounter = -1 obswithgps = Observation.objects.filter(node = '1a') #Places a map pin with correct observer color for every location observation for obj in obswithgps: mycounter += 1 a,b,c = map(float, obj.value_text.strip('()').replace(',','').split()) pinImages.append(maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + chwscolors[obj.encounter.observer.uuid]['color'], maps.Size(21, 34), maps.Point(0,0), maps.Point(10, 34))) markers.append(maps.Marker(opts = { 'map': gmap, 'position': maps.LatLng(a, b), 'icon': pinImages[mycounter], })) #Adds popup textboxes with info to describe the pinned encounter maps.event.addListener(markers[mycounter], 'mouseover', 'myobj.markerOver') maps.event.addListener(markers[mycounter], 'mouseout', 'myobj.markerOut') content.append('<p>' + str(obj.encounter.observer) + ' visited ' + str(obj.encounter.subject) + '</br>for ' + str(obj.encounter.concept) + ' on ' + str(obj.encounter.modified.date()) + '</p>') infos.append(maps.InfoWindow({ 'content': content[mycounter], 'disableAutoPan': True })) infos[mycounter].open(gmap, markers[mycounter]) return render_to_response(tmpl, context_instance=RequestContext(request, {'chwscolors': chwscolors.values(), 'nums': nums, 'numencs': numencs, 'numsubjs': numsubjs, 'form': MapForm(initial={'map': gmap}), 'upcomingcount': upcomingcount, 'danacounts': danacounts, 'timely': timely}))
def contato(request, cidade_slug): cidade = get_object_or_404(Cidade, slug=cidade_slug) cidades_disponiveis = Cidade.objects.all() #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng('-34', '20'), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng('-34', '20'), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + 'Clipper Magazine' + '</h3>' + '<p>Rua: ' + 'etc etc' + '</p>' + '<p>Telefone: ' + '62 888992212' + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) #formulario de contato if request.POST: postdata = request.POST.copy() form_contato = Contato_Form(postdata) if form_contato.is_valid(): cad_contato = Contato() cad_contato.nome = form_contato.cleaned_data['nome'] cad_contato.empresa = form_contato.cleaned_data['empresa'] cad_contato.email = form_contato.cleaned_data['email'] cad_contato.telefone = cad_contato.cleaned_data['telefone'] cad_contato.mensagem = form_contato.cleaned_data['mensagem'] cad_contato.save() mensagem_site = form_contato.cleaned_data['mensagem'] mensagem = "Ola\nO %s Mandou a seguinte mensagem:\n%s" % ( cad_contato.nome, mensagem_site) email = EmailMessage(cad_contato.mensagem, mensagem, to=['*****@*****.**']) email.send() if request.is_ajax(): return render_to_response('contato/sucesso.html') else: return redirect('contato_sucesso') else: form_contato = Contato_Form() if request.session.get('email_cadastrado', False): email_cadastrado = True email_form = None else: email_cadastrado = False email_form = EmailForm() email_duplicado = False if request.POST: postdata = request.POST.copy() email_form = EmailForm(postdata) if email_form.is_valid(): cad_email = EmailInscricao() cad_email.email = email_form.cleaned_data['email'] cad_email.cidade = email_form.cleaned_data['cidade'] cad_email.save() email_cadastrado = True context = { 'form_mapa': MapForm(initial={'map': gmap}), 'email_form': email_form, 'email_cadastrado': email_cadastrado, 'form_contato': form_contato, 'cidades_disponiveis': cidades_disponiveis, 'cidade': cidade, } return render_to_response('contato/contato.html', context, context_instance=RequestContext(request))