Esempio n. 1
0
 def __init__(self, *args, **kwargs):
     super(PlaceAdminForm, self).__init__(*args, **kwargs)
     self.initial["position"] = make_point(
         self.initial["position"],
         origin_coord_srid=DEFAULT_PROJECTED_SRID,
         destiny_coord_srid=DEFAULT_WGS84_SRID
     )
Esempio n. 2
0
    def test_search_form(self):
        user = UserFactory()
        JourneyFactory(departure=datetime.datetime.now() +
                       datetime.timedelta(days=2),
                       user=user,
                       driver=user)
        journey = JourneyFactory(user=user, driver=user)

        data = {
            "departure_date":
            journey.departure.date(),
            "departure_time":
            journey.departure.time(),
            "distance":
            1000,
            "time_window":
            30,
            "position":
            six.text_type(
                make_point(journey.residence.position,
                           origin_coord_srid=DEFAULT_PROJECTED_SRID,
                           destiny_coord_srid=DEFAULT_GOOGLE_MAPS_SRID))
        }
        form = SearchJourneyForm(data)
        self.assertTrue(form.is_valid())
        results = form.search(UserFactory())
        self.assertEquals(1, results.count())
Esempio n. 3
0
def point_google_maps(origin_point):
    if isinstance(origin_point,
                  Point) and origin_point.srid == DEFAULT_PROJECTED_SRID:
        point = make_point(origin_point,
                           origin_coord_srid=DEFAULT_PROJECTED_SRID,
                           destiny_coord_srid=DEFAULT_GOOGLE_MAPS_SRID)
        return "POINT ({} {})".format(point.coords[0], point.coords[1])
    return origin_point
Esempio n. 4
0
 def clean_position(self):
     position = self.cleaned_data["position"]
     position_point = GEOSGeometry(position, srid=DEFAULT_WGS84_SRID)
     position_projected_point = make_point(
         position_point,
         origin_coord_srid=DEFAULT_WGS84_SRID,
         destiny_coord_srid=DEFAULT_PROJECTED_SRID)
     return position_projected_point
Esempio n. 5
0
 def clean_default_position(self):
     default_position = self.cleaned_data["default_position"]
     if default_position:
         default_position_point = GEOSGeometry(
             default_position, srid=DEFAULT_GOOGLE_MAPS_SRID)
         default_position_projected_point = make_point(
             default_position_point,
             origin_coord_srid=DEFAULT_GOOGLE_MAPS_SRID,
             destiny_coord_srid=DEFAULT_PROJECTED_SRID)
         return default_position_projected_point
     return default_position
Esempio n. 6
0
def google_static_map(point, width=600, height=300, zoom=13):
    google_maps_point = make_point(point, origin_coord_srid=point.srid, destiny_coord_srid=DEFAULT_GOOGLE_MAPS_SRID)
    base_uri = "https://maps.googleapis.com/maps/api/staticmap"
    args = {
        "maptype": "roadmap",
        "zoom": zoom,
        "size": "{}x{}".format(width, height),
        "key": settings.GOOGLE_MAPS_API_KEY,
        "center": "{},{}".format(google_maps_point.coords[1], google_maps_point.coords[0]),
        "markers": "color:red|{},{}".format(google_maps_point.coords[1], google_maps_point.coords[0]),
    }
    query_dict = QueryDict(mutable=True)
    query_dict.update(args)
    return "{}?{}".format(base_uri, query_dict.urlencode())