# Path: mapwidgets/constants.py
# STATIC_MAP_PLACEHOLDER_IMAGE = "mapwidgets/images/no-map-image.png"
# 
# Path: mapwidgets/settings.py
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }
# class MapWidgetSettings(object):
#     def __init__(self, app_settings=None, defaults=None):
#     def app_settings(self):
#     def __getattr__(self, attr):
# def reload_widget_settings(*args, **kwargs):


import json
from django import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import Point
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.http import urlencode
from mapwidgets.constants import STATIC_MAP_PLACEHOLDER_IMAGE
from mapwidgets.settings import MapWidgetSettings, mw_settings

    def get_point_field_params(self, latitude, longitude):
        marker_point = "%s,%s" % (latitude, longitude)

        marker_params = ["%s:%s" % (key, value) for key, value in self.marker_settings.items()]
        marker_params.append(marker_point)
        marker_url_params = "|".join(marker_params)
        params = {
            "center": marker_point,
            "markers": marker_url_params,
        }
        params.update(self.map_settings)
        return params

    def get_image_url(self, value):
        if isinstance(value, Point):
            longitude, latitude = value.x, value.y
            params = self.get_point_field_params(latitude, longitude)

            image_url_template = "%(base_url)s?%(params)s"
            image_url_data = {
                "base_url": self.base_url,
                "params": urlencode(params)
            }
            return image_url_template % image_url_data

        return static(STATIC_MAP_PLACEHOLDER_IMAGE)


class GoogleStaticOverlayMapWidget(GoogleStaticMapWidget):

# Path: mapwidgets/constants.py
# STATIC_MAP_PLACEHOLDER_IMAGE = "mapwidgets/images/no-map-image.png"
# 
# Path: mapwidgets/settings.py
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }
# class MapWidgetSettings(object):
#     def __init__(self, app_settings=None, defaults=None):
#     def app_settings(self):
#     def __getattr__(self, attr):
# def reload_widget_settings(*args, **kwargs):


# Path: mapwidgets/widgets.py
import json
from django import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import Point
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.http import urlencode
from mapwidgets.constants import STATIC_MAP_PLACEHOLDER_IMAGE
from mapwidgets.settings import MapWidgetSettings, mw_settings


    def get_point_field_params(self, latitude, longitude):
        marker_point = "%s,%s" % (latitude, longitude)

        marker_params = ["%s:%s" % (key, value) for key, value in self.marker_settings.items()]
        marker_params.append(marker_point)
        marker_url_params = "|".join(marker_params)
        params = {
            "center": marker_point,
            "markers": marker_url_params,
        }
        params.update(self.map_settings)
        return params

    def get_image_url(self, value):
        if isinstance(value, Point):
            longitude, latitude = value.x, value.y
            params = self.get_point_field_params(latitude, longitude)

            image_url_template = "%(base_url)s?%(params)s"
            image_url_data = {
                "base_url": self.base_url,
                "params": urlencode(params)
            }
            return image_url_template % image_url_data

        return static(STATIC_MAP_PLACEHOLDER_IMAGE)


class GoogleStaticOverlayMapWidget(GoogleStaticMapWidget):

    settings = mw_settings.GoogleStaticOverlayMapWidget