예제 #1
0
파일: admin.py 프로젝트: trousev/olwidget
    def get_changelist_map(self, cl, request=None):
        """
        Display a map in the admin changelist, with info popups
        """
        if self.list_map:
            info = []
            if request:
                qs = cl.get_query_set(request)
            else:
                qs = cl.get_query_set()
            for obj in qs:
                # Transform the fields into one projection.
                geoms = []
                for field in self.list_map:
                    geom = getattr(obj, field)
                    if geom:
                        if callable(geom):
                            geom = geom()
                        geoms.append(geom)
                for geom in geoms:
                    geom.transform(int(DEFAULT_PROJ))

                if geoms:
                    info.append((GeometryCollection(geoms,
                                                    srid=int(DEFAULT_PROJ)),
                                 "<a href='%s'>%s</a>" %
                                 (cl.url_for_result(obj), force_unicode(obj))))

            return InfoMap(info, options=self.list_map_options)
        return None
예제 #2
0
def location_detail(request, slug):
    location = get_object_or_404(Location, slug=slug)

    this_map = InfoMap(
        [(location.point, location.map_html)],
        {  #'layers': ['google.streets', 'google.satellite', 'google.hybrid'],
            'map_div_style': {
                'width': '570px',
                'height': '400px'
            }
        })

    display_validate_it = not (request.user.is_authenticated()
                               and location.is_validated_by(request.user))

    areas = Geom.objects.filter(
        geom__contains=location.point).order_by('area__lft')
    country = areas[0]
    area = areas[areas.count() - 1]
    tweet_url = 'http://%s%s' % (Site.objects.get_current().domain,
                                 location.get_absolute_url())
    tweet_text = 'See %s in %s, %s. Please validate this %s location' % (
        location.name, area, country, location.type.name)

    return render(
        request, 'world/location_detail.html', {
            'location': location,
            'map': this_map,
            'display_validate_it': display_validate_it,
            'tweet_url': tweet_url,
            'tweet_text': tweet_text,
        })
예제 #3
0
파일: admin.py 프로젝트: CulturePlex/artdb
 def ubication_map(self, obj):
     info = [u""]
     try:
         if obj.geometry:
             geo = obj.geometry
             coords = geo.point_on_surface.get_coords()
         elif obj.point:
             geo = obj.point
             coords = geo.get_coords()
         info = [(geo, "%s %s" % (_(u"On surface"), coords))]
     except:
         return u""
     options = {
         'layers': ['google.streets'],
         'map_div_Style': {'width': '300px', 'height': '200px'},
     }
     map_display = InfoMap(info, options)
     return mark_safe(map_display.render(obj.title, {}))
예제 #4
0
 def ubication_map(self, obj):
     info = [u""]
     try:
         if obj.geometry:
             geo = obj.geometry
             coords = geo.point_on_surface.get_coords()
         elif obj.point:
             geo = obj.point
             coords = geo.get_coords()
         info = [(geo, "%s %s" % (_(u"On surface"), coords))]
     except:
         return u""
     options = {
         'layers': ['google.streets'],
         'map_div_Style': {
             'width': '300px',
             'height': '200px'
         },
     }
     map_display = InfoMap(info, options)
     return mark_safe(map_display.render(obj.title, {}))
예제 #5
0
파일: views.py 프로젝트: trousev/olwidget
def show_tree(request, object_id):
    obj = get_object_or_404(Tree, id=object_id)
    # Use the convenience 1-layer map type
    map_ = InfoMap([
        [obj.root_spread, "Root spread"],
        [obj.location, "Trunk center"],
    ])
    return render_to_response("testolwidget/show_obj.html", {
        'obj': obj,
        'map': map_,
        'edit_link': reverse("edit_tree", args=[obj.id]),
    },
                              context_instance=RequestContext(request))
예제 #6
0
    def get_changelist_map(self, cl, request=None):
        def mygetattr(obj, prop):
            if len(prop) == 1:
                return getattr(obj, prop[0])
            else:
                return mygetattr(getattr(obj, prop[0]), prop[1:])

        """
        Display a map in the admin changelist, with info popups
        """
        if self.list_map:
            info = []
            #for obj in cl.get_query_set():
            if request:
                qs = cl.get_query_set(request)
            else:
                qs = cl.get_query_set()
            for obj in qs:
                # Transform the fields into one projection.
                geoms = []

                for field in self.list_map:
                    geom = mygetattr(obj, field.split('.'))

                    if geom:
                        if callable(geom):
                            geom = geom()
                        geoms.append(geom)
                for geom in geoms:
                    geom.transform(int(DEFAULT_PROJ))

                if geoms:
                    # Because this is a massive hack, I know that only my code is calling this line
                    # Therefore I can add additional info that shouldn't be added
                    if 'no_list_display_link' in self.list_map_options:
                        info_text = "Facility %d: %s" % (getattr(
                            obj, 'facility').pk, force_unicode(obj))
                    else:
                        info_text = "<a href='%s'>%s</a>" % (
                            cl.url_for_result(obj), force_unicode(obj))
                    info.append((GeometryCollection(geoms,
                                                    srid=int(DEFAULT_PROJ)),
                                 info_text))

            return InfoMap(info, options=self.list_map_options)
        return None
예제 #7
0
파일: views.py 프로젝트: trousev/olwidget
def show_countries(request):
    info = []
    colors = ["red", "green", "blue", "peach"]
    for i, country in enumerate(Country.objects.all()):
        info.append((
            country.boundary,
            {
                'html': country.about,
                'style': {
                    # TODO: 4-color map algorithm.  Just kidding.
                    'fill_color': colors[i]
                },
            }))
    map_ = InfoMap(info)
    return render_to_response("testolwidget/show_obj.html", {
        'obj': "Countries",
        "map": map_,
        "edit_link": "/admin/testolwidget/country/",
    },
                              context_instance=RequestContext(request))
예제 #8
0
def get_car_infomap(width='100%', height='400px'):
    """
    Returns olwidget.widgets.InfoMap instance with available cars on it.
    """
    return InfoMap([
                       [c.last_position, c.__unicode__()] for c in Car.objects.all()],
                   options={
                       'default_zoom': 8,
                       'map_div_style': {'width': width, 'height': height},
                       'popupOutside': True,
                       'overlayStyle': {
                           'externalGraphic': settings.STATIC_URL + "img/marker.png",
                           'backgroundGraphic': settings.STATIC_URL + "img/marker_shadow.png",
                           'graphicXOffset': -10,
                           'graphicYOffset': -12,
                           'graphicWidth': 21,
                           'graphicHeight': 25,
                           'backgroundXOffset': 2,
                           'graphicOpacity': 1
                       }
                   }
    )
예제 #9
0
def usersMap(theRequest):

    users = []
    myUserCount = QgisUser.objects.all().count()
    myRandomUser = None
    myRandomUsers = QgisUser.objects.exclude(image="").order_by('?')[:1]
    if myRandomUsers.count() > 0:
        myRandomUser = myRandomUsers[0]
    for user in QgisUser.objects.all():
        users.append([
            user.geometry,
            render_to_string('user_balloon.html', {'user': user})
        ])

    myMap = InfoMap(users)

    return render_to_response("view_users.html", {
        'myMap': myMap,
        'myUserCount': myUserCount,
        'myRandomUser': myRandomUser,
    },
                              context_instance=RequestContext(theRequest))
예제 #10
0
파일: tests.py 프로젝트: capooti/olwidget
 def test_info_map(self):
     # Just ensure that no errors arise from construction and rendering
     mymap = InfoMap([[Point(0, 0, srid=4326), "that"]], {"name": "frata"})
     unicode(mymap)
예제 #11
0
 def _media(self):
     from olwidget.widgets import InfoMap
     return InfoMap([]).media
예제 #12
0
    def as_html(self, context=None):
        from django.contrib.gis.geos import Polygon, MultiPolygon
        from django.contrib.gis.geos import GeometryCollection
        from olwidget.widgets import InfoMap

        def _convert_to_multipolygon(field):
            l = []
            for p in field:
                if type(p) == MultiPolygon:
                    l += [item for item in p]
                else:
                    l.append(p)
            return MultiPolygon(l, srid=field.srid)

        context = self.context if context is None else context

        POLY_TYPES = [Polygon, MultiPolygon]
        olwidget_options = None
        if hasattr(settings, 'OLWIDGET_DEFAULT_OPTIONS'):
            olwidget_options = settings.OLWIDGET_DEFAULT_OPTIONS

        d = self.get_diff()
        if d is None:
            return ('<tr><td colspan="2">(%s)</td></tr>' %
                    _('No differences found'))

        # Split out polygons from other geometries in field1, field2,
        # same, deleted and inserted.
        poly_field1, misc = self._split_out_geometry(POLY_TYPES, self.field1)
        poly_field2, misc = self._split_out_geometry(POLY_TYPES, self.field2)
        poly_same, other_geom_same = self._split_out_geometry(
            POLY_TYPES, d['same'])
        poly_deleted, other_geom_deleted = self._split_out_geometry(
            POLY_TYPES, d['deleted'])
        poly_inserted, other_geom_inserted = self._split_out_geometry(
            POLY_TYPES, d['inserted'])

        # Remove items from other_geom_same that are fully contained
        # inside deleted, inserted.  If we didn't do this we would see
        # things like a point marked as "stayed the same" inside of a
        # newly-added polygon, when the polygon is really just replacing
        # the point.
        other_geom_same_for_del, other_geom_same_for_insert = [], []
        for geom in other_geom_same:
            if not d['deleted'].contains(geom):
                other_geom_same_for_del.append(geom)
            if not d['inserted'].contains(geom):
                other_geom_same_for_insert.append(geom)
        other_geom_same_for_del = GeometryCollection(other_geom_same_for_del,
                                                     srid=d['deleted'].srid)
        other_geom_same_for_insert = GeometryCollection(
            other_geom_same_for_insert, srid=d['inserted'].srid)

        # We need to convert from GeometryCollection to MultiPolygon to
        # compute boundary.
        poly_field1 = _convert_to_multipolygon(poly_field1)
        poly_field2 = _convert_to_multipolygon(poly_field2)

        deleted = InfoMap([
            (poly_same, {
                'html': _('Stayed the same'),
                'style': {
                    'stroke_opacity': '0'
                }
            }),
            (poly_deleted, {
                'html': _('Removed'),
                'style': {
                    'fill_color': '#ff7777',
                    'stroke_color': '#ff7777',
                    'fill_opacity': '0.8',
                    'stroke_opacity': '0'
                }
            }),
            (poly_field1.boundary, {}),
            (other_geom_same_for_del, {
                'html': _('Stayed the same'),
                'style': {
                    'fill_color': '#ffdf68',
                    'stroke_color': '#db9e33',
                    'stroke_opacity': '1'
                }
            }),
            (other_geom_deleted, {
                'html': _('Removed'),
                'style': {
                    'fill_color': '#ff7777',
                    'stroke_color': '#ff7777',
                    'fill_opacity': '0.8',
                    'stroke_opacity': '1'
                }
            }),
        ],
                          options=olwidget_options)

        inserted = InfoMap([
            (poly_same, {
                'html': _('Stayed the same'),
                'style': {
                    'stroke_opacity': '0'
                }
            }),
            (poly_inserted, {
                'html': _('Added'),
                'style': {
                    'fill_color': '#9bff53',
                    'stroke_color': '#9bff53',
                    'fill_opacity': '0.8',
                    'stroke_opacity': '0'
                }
            }),
            (poly_field2.boundary, {}),
            (other_geom_same_for_insert, {
                'html': _('Stayed the same'),
                'style': {
                    'fill_color': '#ffdf68',
                    'stroke_color': '#db9e33',
                    'stroke_opacity': '1'
                }
            }),
            (other_geom_inserted, {
                'html': _('Added'),
                'style': {
                    'fill_color': '#9bff53',
                    'stroke_color': '#9bff53',
                    'fill_opacity': '0.8',
                    'stroke_opacity': '1'
                }
            }),
        ],
                           options=olwidget_options)

        context.update({'deleted': deleted, 'inserted': inserted})

        return render_to_string(self.template, context)
예제 #13
0
파일: geomap.py 프로젝트: rrymrrsn/whyqd
 def show_map(self):
     info = [(self.map_shape, {'style': {'fill_color': 'blue'}})]
     options = {'height': "250px"}
     return InfoMap(info, options)