def map(request):
    """Display a map of places associated with the people connected to the
    Belfast Group or mentioned in the digitized Group sheets on the site.

    If a :class:`~django.contrib.flatpages.models.FlatPage` is found for
    this url, it is passed to the template to include in display.
    """

    fpage = get_flatpage(request)

    people = {}
    # semi-redundant with json view functionality, but easier to build filter
    for pl in find_places():
        # lat/long should have been added in rdf data prep, but
        # check just in case, because missing lat/long breaks the map
        if not all([pl.latitude, pl.longitude]):
            continue

        for p in pl.people:
            if p.local_uri:
                people[str(p.identifier)] = p.fullname

    return render(request, "network/map.html", {"people": people, "flatpage": fpage})
def map_js(request):
    """Location data for places associated with the people connected to the
    Belfast Group or mentioned in the digitized Group sheets on the site,
    returned as JSON for use with :meth:`map`.
    """
    places = find_places()
    markers = []
    for pl in places:
        # lat/long should have been added in rdf data prep, but
        # check just in case, because missing lat/long breaks the map
        if not all([pl.latitude, pl.longitude]):
            continue

        tags = []
        # if this place is mentioned in poems, add title/link to description
        texts = ""
        if pl.texts:
            texts = "<p>Mentioned in %s.</p>" % (
                "; ".join('<a href="%s">%s</a>' % (t.identifier, normalize_whitespace(t.name)) for t in pl.texts)
            )
            tags.append("text")
            for t in pl.texts:
                if t.author is not None:
                    tags.append(unicode(t.author.identifier))

        people = ""
        if pl.people:
            people = "<p>Connected people: %s.</p>" % (
                "; ".join(
                    '<a href="%s">%s</a>' % (p.identifier, p.fullname) if p.local_uri else p.fullname for p in pl.people
                )
            )
            # possibly put specific slugs here for filtering
            tags.append("people")
            tags.extend([unicode(p.identifier) for p in pl.people if p.local_uri])

        # if this place is not identifiably connected to a person or place
        # in our data, skip it (for now at least)
        if not people and not texts:
            continue

        # flag to indicate the type of icon that should be used on the map
        if people and texts:
            icon = "bio-text"
        elif people:
            icon = "bio"
        else:
            icon = "text"

        info = {
            "latitude": pl.latitude,
            "longitude": pl.longitude,
            "title": pl.name,
            # text (html) content to be shown when clicking on a marker
            "content": """<b>%s</b> %s %s""" % (pl.name, people, texts),
            # properties to affect display
            "tags": tags,
            "icon": icon,
        }
        markers.append(info)

    map_data = {"markers": markers}
    return HttpResponse(json.dumps(map_data), content_type="application/json")