def test_google_map_scripts(self): """ Testing GoogleMap.scripts() output. See #20773. """ from django.contrib.gis.maps.google.gmap import GoogleMap google_map = GoogleMap() scripts = google_map.scripts self.assertIn(GOOGLE_MAPS_API_KEY, scripts) self.assertIn("new GMap2", scripts)
def test_unicode_in_google_maps(self): """ Test that GoogleMap doesn't crash with non-ASCII content. """ from django.contrib.gis.geos import Point from django.contrib.gis.maps.google.gmap import GoogleMap, GMarker center = Point(6.146805, 46.227574) marker = GMarker(center, title='En français !') google_map = GoogleMap(center=center, zoom=18, markers=[marker]) self.assertIn("En français", google_map.scripts)
def googleMapShowUtils(points): markers = [] for point in points: marker = GMarker('POINT(%s %s)' % (point['lng'], point['lat'])) event = GEvent('click', 'function() { location.href = "%s"}' % point['href']) marker.add_event(event) markers.append(marker) google = GoogleMap(center=(0, 0), zoom=1, markers=markers, key=settings.GOOGLE_MAPS_API_PASSWORD) return google #add search utility here
def google_map(request): points = [ { 'lat': '35.42', 'lng': '139.42', 'href': 'http://en.wikipedia.org/wiki/Tokyo' }, { 'lat': '51.30', 'lng': '0.73', 'href': 'http://en.wikipedia.org/wiki/London' }, { 'lat': '40.43', 'lng': '-74.0', 'href': 'http://en.wikipedia.org/wiki/New_York_City' }, { 'lat': '34.03', 'lng': '-118.15', 'href': 'http://en.wikipedia.org/wiki/Los_Angeles' }, { 'lat': '36.774402', 'lng': '-119.755405', 'href': 'http://en.wikipedia.org/wiki/Fresno' }, ] markers = [] for point in points: marker = GMarker('POINT(%s %s)' % (point['lng'], point['lat'])) event = GEvent('click', 'function() { location.href = "%s"}' % point['href']) marker.add_event(event) markers.append(marker) google = GoogleMap(center=(0, 0), zoom=1, markers=markers, key=settings.GOOGLE_MAPS_API_PASSWORD) return render(request, 'rango/google_map.html', {'google': google})
values = data[c.iso2].filledValues() colors = [rgb2hex(jet(norm(val))[0:3]) if val != 1e20 else "#000000" for val in values] # print c.iso2, len(c.geom) # print [len(p.coords[0]) for p in c.geom] for p in c.geom: if len(p.coords[0]) < 5: continue poly = GPolygon(p, stroke_color="#000000", stroke_weight=1, stroke_opacity=0.8, \ fill_opacity=0.7, fill_color=colors[0]) polys.append(poly) timeseries.append(dumps(colors)) timesteps = dumps(data[data.keys()[0]].dates.tolist()); gmap = GoogleMap(template=GMAP_TPL, key=GMAP_KEY, polygons=polys, extra_context={'maptype':'G_SATELLITE_MAP', 'timesteps':timesteps, 'timeseries':timeseries, }) histo_values = ",".join([str(val) for val in histo[0][keptIndex]]) for reg in WBAPI.SELECTED_REGIONS: reg['url'] = reverse('world.views.countries', args=(reg['code'], indicator)) if reg['code'] == region: wb_region = reg for topic in WBAPI.SELECTED_TOPICS: for ind in topic["indicators"]: ind["url"] = reverse('world.views.countries', args=(region, ind["id"].strip())) for ind in WBAPI.WB_FEATURED:
def events_month(request, year, month, template_name="events/events_month.html"): size = request.GET.get('size', 10) events = Event.objects.filter(status__exact=2) if int(month) == datetime.datetime.now().month: events = events.filter(end_date__gte=datetime.datetime.now()) else: events = events.filter( end_date__gte=datetime.datetime(int(year), int(month), 1, 0, 0, 0)) # filter categories selected_category = None if request.GET.get("selected_category"): try: selected_category = EventCategory.objects.get(\ short_name=request.GET.get("selected_category")) except: selected_category = None if selected_category: events = events.filter(author__profile__categories=selected_category) # filter titles search_terms = request.GET.get('search', '') if search_terms: events = events.filter(title__icontains=search_terms) zip_code_or_adress = request.GET.get('zip_code_or_adress', '') display_map = request.GET.get('display_map', False) zoom = None point_of_interest = None bbox = None place = None if zip_code_or_adress or display_map: from django.contrib.gis.measure import D # get lat/lon for query #from django.contrib.gis.geos import * from geopy import geocoders g = geocoders.Google(settings.GOOGLE_MAPS_API_KEY) try: place, (lat, lng) = g.geocode(zip_code_or_adress + " salzburg austria") except: return render_to_response( "trumer/invalid_geocode.html", {"zip_code_or_adress": zip_code_or_adress}, context_instance=RequestContext(request)) events = events.exclude(location__exact=None) page = request.GET.get("page", 0) if page: offset = int(size) * int(page) else: offset = 0 page_events = events.order_by("end_date")[offset:offset + int(size)] event_location_ids = [event.location.id for event in page_events] pnt = fromstr("POINT(" + str(lat) + " " + str(lng) + ")", srid=4326) profiles = Profile.objects.filter(id__in=event_location_ids)\ .exclude(is_location=False)\ .filter(location__distance_lte=(pnt, D(km=500))) profiles = profiles.distance("POINT(" + str(lat) + " " + str(lng) + ")") profiles = profiles.order_by("distance") profiles = profiles.all() # get the amount of events needed point_of_interest = str(lat) + ", " + str(lng) zoom = 9 if size > 24: size = 24 for profile in profiles: for event in page_events: if event.location.id == profile.id: if hasattr(profile, "current_events"): profile.current_events.append(event) else: profile.current_events = [event] return render_to_response( template_name, { "zip_code_or_adress": zip_code_or_adress, 'search_terms': search_terms, "events": events.distinct(), "profiles": profiles, "current_date": datetime.date(int(year), int(month), 1), "year": int(year), "month": int(month), "size": int(size), "selected_category": selected_category, 'point_of_interest': point_of_interest, 'GMAP': GoogleMap(), 'categories': EventCategory.objects.all(), }, context_instance=RequestContext(request)) else: events = events.order_by("end_date") return render_to_response( template_name, { "zip_code_or_adress": zip_code_or_adress, 'search_terms': search_terms, "events": events.distinct(), "current_date": datetime.date(int(year), int(month), 1), "year": int(year), "month": int(month), "size": int(size), "selected_category": selected_category, 'categories': EventCategory.objects.all(), }, context_instance=RequestContext(request))