Example #1
0
    def __init__(
        self,
        request,
        instance="public",
        show_contents=False,
        mode="viewer",
        width=800,
        height=400,
        features=None,
        html_info=None,
        service="goldeneye",
        *args,
        **kwargs
    ):
        """

        """
        self.request = request
        self.instance = instance
        self.show_contents = show_contents
        self.mode = mode
        self.width = width
        self.height = height
        self.features = features or []
        if html_info:
            self.html_info = html_info
        if service:
            self.service = service
        self.url, self.access_token = retrieve_access_token(request, self.service)
        super(GoldenEyeWidget, self).__init__(*args, **kwargs)
Example #2
0
    def __init__(self,
                 request,
                 instance='public',
                 show_contents=False,
                 mode='viewer',
                 width=800,
                 height=400,
                 features=None,
                 html_info=None,
                 service='goldeneye',
                 *args,
                 **kwargs):
        """

        """
        self.request = request
        self.instance = instance
        self.show_contents = show_contents
        self.mode = mode
        self.width = width
        self.height = height
        self.features = features or []
        if html_info:
            self.html_info = html_info
        if service:
            self.service = service
        self.url, self.access_token = retrieve_access_token(
            request, self.service)
        super(GoldenEyeWidget, self).__init__(*args, **kwargs)
Example #3
0
def GoldenEyeViewer(request,
                    features=None,
                    geom_field="shape",
                    instance="cc/instances/public",
                    html_info=None):
    serviceurl, access_token = retrieve_access_token(request, "goldeneye")
    uniqueid = shorthash(html_info)
    options = GEDEFAULTS
    options["spatial"] = "textarea#features_{0}".format(uniqueid)
    options["access_token"] = access_token
    options["mode"] = "viewer"
    html_info = re.sub(r"([^{]){([^{])", r"\1{0.\2", html_info)
    featuresjson = []
    for feature in features:
        if getattr(feature, geom_field):
            featuresjson.append({
                "type":
                "Feature",
                "id":
                feature.pk,
                "properties": {
                    "html_info": html_info.format(feature)
                },
                "geometry":
                json.loads(getattr(feature, geom_field).json)
            })
    featuresjson = json.dumps({
        "type": "FeatureCollection",
        "features": featuresjson
    })
    urlparams = urlencode(options)
    output = u'''
    <link rel="stylesheet" href="{0}/api/geoserver/v1/static/geoserver.css" type="text/css" />
    <script src="{0}/api/geoserver/v1/static/geoserver.js"></script>
    <script src="{0}/api/geoserver/v1/workspaces/{1}.js?{2}"></script>
    <textarea id="features_{4}" style="display:none;">{3}</textarea>
    <div id="{4}" class="goldeneye-viewer-widget" style="float:left;"></div>
    <script type="text/javascript">
        $(function() {{
        new GoldenEye.SpatialView("{4}");
    }});
    </script>
    <div style="clear:both;"></div>
    '''.format(serviceurl, instance, urlparams, featuresjson,
               uniqueid).strip()
    return mark_safe(output)
Example #4
0
def GoldenEyeViewer(request, features=None, geom_field="shape", instance="cc/instances/public", html_info=None):
    serviceurl, access_token = retrieve_access_token(request, "goldeneye")
    uniqueid = shorthash(html_info)
    options = GEDEFAULTS
    options["spatial"] = "textarea#features_{0}".format(uniqueid)
    options["access_token"] = access_token
    options["mode"] = "viewer"
    html_info = re.sub(r"([^{]){([^{])", r"\1{0.\2", html_info)
    featuresjson = []
    for feature in features:
        if getattr(feature, geom_field):
            featuresjson.append(
                {
                    "type": "Feature",
                    "id": feature.pk,
                    "properties": {"html_info": html_info.format(feature)},
                    "geometry": json.loads(getattr(feature, geom_field).json),
                }
            )
    featuresjson = json.dumps({"type": "FeatureCollection", "features": featuresjson})
    urlparams = urlencode(options)
    output = """
    <link rel="stylesheet" href="{0}/api/geoserver/v1/static/geoserver.css" type="text/css" />
    <script src="{0}/api/geoserver/v1/static/geoserver.js"></script>
    <script src="{0}/api/geoserver/v1/workspaces/{1}.js?{2}"></script>
    <textarea id="features_{4}" style="display:none;">{3}</textarea>
    <div id="{4}" class="goldeneye-viewer-widget" style="float:left;"></div>
    <script type="text/javascript">
        $(function() {{
        new GoldenEye.SpatialView("{4}");
    }});
    </script>
    <div style="clear:both;"></div>
    """.format(
        serviceurl, instance, urlparams, featuresjson, uniqueid
    ).strip()
    return mark_safe(output)