def details(request, slug): area = get_object_or_404(Area, path=slug) subareas = area.get_children() locations = Location.objects.filter(point__within=area.geom.geom) layers = [] locations_layer = InfoLayer([(l.point, l.map_html) for l in locations]) layers.append(locations_layer) if subareas: subareas_layer = InfoLayer([(sa.geom_simplify, sa.name) for sa in subareas]) layers.append(subareas_layer) else: layers.append(InfoLayer([(area.geom_simplify, area.name)])) this_map = Map(layers, {'layers': ['google.streets', 'google.satellite', 'google.hybrid'], 'map_div_style': {'width': '570px', 'height': '400px'}}) return render(request, 'world/details.html', { 'area': area, 'map': this_map, 'subareas': subareas, 'locations': locations, })
def lea(request, id=None, stat=None): county = get_object_or_404(County, id=id) stat = stat or ops.PredictedAttainment.code op = STATS[stat](county) op.run() county_layer = InfoLayer([[county.shape, {}]], COUNTY_OPTIONS) best_layer = InfoLayer( [[school.location, "<p>%s</p>" % school.name] for school in op.best_schools()], BEST_OPTIONS) worst_layer = InfoLayer( [[school.location, "<p>%s</p>" % school.name] for school in op.worst_schools()], WORST_OPTIONS) map_ = Map([county_layer, best_layer, worst_layer], MAP_OPTIONS) context = { 'stats': {code: op.title for code, op in STATS.items()}, 'county': county, 'op': op, 'map': map_ } return render_to_response(op.template, context, context_instance=RequestContext(request))
def add(request): # If viewing through full flavour #if False: if request.flavour == "full": # Show a big map with all facilities using olwidget template = "reports/add.html" # Get a list of all the issues for all facilities # Status shouldn't be hard-coded - update if time issues = [[ f.location, style_issues(f, f.facilityissue_set.filter(status__lt=3)) ] for f in Facility.objects.select_related().all()] # Display a clickable list of facilities for the user fac_map = Map( [ InfoLayer( issues, { 'name': 'facilities', 'cluster': True, 'overlay_style': { 'fill_color': "${specialAttributeHandler}", }, 'overlay_style_context': { 'specialAttributeHandler': 'function(feature) {}', }, }) ], { 'overlay_style': { 'fill_opacity': 0.1, 'fill_color': '#ffa500', 'stroke_color': '#ffa500' }, 'default_zoom': 18, 'map_div_style': { 'width': '100%', 'height': '100%' } }, template="reports/add_map.html") context = { 'map': fac_map, } return render(request, template, context) elif request.flavour == "mobile": #elif True: return render(request, "reports/mobile/add.html")
def __init__(self, fields=None, options=None, layer_names=None, template=None, **kwargs): # create map widget enclosing vector layers and options if not fields: fields = [EditableLayerField()] layers = [field.widget for field in fields] self.fields = fields kwargs['widget'] = kwargs.get( 'widget', Map(layers, options, template, layer_names)) super(MapField, self).__init__(**kwargs)
def leas(request): counties = County.objects.all().order_by('name') counties_per_col = counties.count() / 4 county_layer = InfoLayer([[c.shape, _link(c)] for c in counties]) map_ = Map([county_layer], LEAS_MAP_OPTIONS) context = { 'counties_columns': paged(counties_per_col, counties), 'map': map_, } return render_to_response('dashboard/leas.html', context, context_instance=RequestContext(request))
def index(request): return render_to_response("testolwidget/index.html", { 'map': Map( [ EditableLayer({ 'geometry': ['point', 'linestring', 'polygon'], 'is_collection': True, }), ], { 'default_lat': 42.360836996182, 'default_lon': -71.087611985694, 'default_zoom': 10, 'layers': ['osm.mapnik', 'google.physical'], }), }, context_instance=RequestContext(request))
def show_alienactivity(request, object_id): obj = get_object_or_404(AlienActivity, id=object_id) return render_to_response("testolwidget/show_obj.html", { 'obj': obj, 'map': Map([ InfoLayer( [[obj.landings, "%s landings" % obj.incident_name]], { 'overlay_style': { 'external_graphic': settings.MEDIA_URL + "alien.png", 'graphic_width': 21, 'graphic_height': 25, 'fill_color': '#00FF00', 'stroke_color': '#008800', }, 'name': "Landings" }), InfoLayer( [[obj.strange_lights, "%s strange lights" % obj.incident_name]], { 'overlay_style': { 'fill_color': '#FFFF00', 'stroke_color': '#FFFF00', 'stroke_width': 6, }, 'name': "Strange lights", }), InfoLayer( [[obj.chemtrails, "%s chemtrails" % obj.incident_name]], { 'overlay_style': { 'fill_color': '#ffffff', 'stroke_color': '#ffffff', 'stroke_width': 6, }, 'name': "Chemtrails", }) ], {'layers': ['osm.mapnik', 'google.physical']}), 'edit_link': reverse("edit_alienactivity", args=[obj.id]) }, context_instance=RequestContext(request))
def details(request, path): try: area = Area.objects.get(path=path) except Area.DoesNotExist: # Dirty hack to try Django-CMS pages. return cms_details(request, slug=path) subareas = area.get_children() locations = Location.objects.filter(point__within=area.geom.geom) location_types = LocationType.objects.filter( location__point__within=area.geom.geom).annotate( id__count=Count('location')) layers = [] locations_layer = InfoLayer([(l.point, l.map_html) for l in locations]) layers.append(locations_layer) if subareas: subareas_layer = InfoLayer([(sa.geom_simplify, sa.name) for sa in subareas]) layers.append(subareas_layer) else: layers.append(InfoLayer([(area.geom_simplify, area.name)])) this_map = Map( layers, { #'layers': ['google.streets', 'google.satellite', 'google.hybrid'], 'map_div_style': { 'width': '570px', 'height': '400px' } }) return render( request, 'world/details.html', { 'area': area, 'map': this_map, 'subareas': subareas, 'locations': locations, 'location_types': location_types })
def poly_map(regions = [], realestates = []): app_info = Region._meta.app_label, Region._meta.module_name return Map([ InfoLayer([ (region.poly, '<h2>%s</h2><br/><a href="%s">%s</a><br/><br/>%s' % ( _("Region %s") % region.name, reverse("admin:%s_%s_change" % app_info, args = (region.id,)), _("Go to %s administration page") % region.name, region.add_realestate_link ),) for region in regions ], {"name": _("Region")} ), InfoLayer([ (realestate.poly, '<h2>%s: %s</h2><br/><a href="%s">%s</a>' % ( _("ID: %s") % realestate.id, _("Type: %s") % realestate.get_type_display(), reverse("admin:%s_%s_change" % ( realestate._meta.app_label, realestate._meta.module_name,), args = (realestate.region.id,)), _("Go to this realestate administration page") ),) for realestate in realestates ], { "name": _("Real Estates"), "overlay_style": {"fill_color": "#0000ff", "stroke_color":"#000"} } ), ], options = { "map_div_style": { "width": "800px", "height": "600px" } })
def _get_map_media(): from olwidget.widgets import Map layers = [settings.MAP_BASELAYER_TYPE] map_media = Map([], options={"layers": layers}).media return map_media.render()
def _get_map_media(): from olwidget.widgets import Map layers = [settings.MAP_BASELAYER_TYPE] map_media = Map([], options={'layers': layers}).media return map_media.render()