-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
232 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# coding=utf-8 | ||
"""Context Layer Management.""" | ||
|
||
from django import forms | ||
|
||
from context_layer_management.models import LayerStyle | ||
|
||
|
||
class LayerStyleForm(forms.ModelForm): | ||
"""Layer style form.""" | ||
|
||
def save(self, commit=True): | ||
"""Save the data.""" | ||
if not self.instance.created_by_id: | ||
self.instance.created_by_id = self.user.pk | ||
return super(LayerStyleForm, self).save(commit=commit) | ||
|
||
class Meta: # noqa: D106 | ||
model = LayerStyle | ||
exclude = () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
django_project/context_layer_management/models/style_defaults.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
POINT = { | ||
"layers": [ | ||
{ | ||
"id": "<uuid>", | ||
"type": "circle", | ||
"paint": { | ||
"circle-color": "#ff7800", | ||
"circle-radius": 4, | ||
"circle-opacity": 1 | ||
}, | ||
"filter": ["==", "$type", "Point"], | ||
"source": "<uuid>", | ||
"source-layer": "default" | ||
} | ||
] | ||
} | ||
LINE = { | ||
"layers": [ | ||
{ | ||
"id": "<uuid>", | ||
"type": "line", | ||
"source": "<uuid>", | ||
"source-layer": "default", | ||
"filter": ["==", "$type", "LineString"], | ||
"paint": { | ||
"line-color": "#ff7800", | ||
"line-width": 1 | ||
}, | ||
} | ||
] | ||
} | ||
|
||
POLYGON = { | ||
"layers": [ | ||
{ | ||
"id": "<uuid>", | ||
"type": "fill", | ||
"source": "<uuid>", | ||
"source-layer": "default", | ||
"filter": ["==", "$type", "Polygon"], | ||
"paint": { | ||
"fill-color": "#ff7800", | ||
"fill-opacity": 0.8 | ||
}, | ||
} | ||
] | ||
} |
46 changes: 46 additions & 0 deletions
46
django_project/context_layer_management/serializer/style.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding=utf-8 | ||
"""Context Layer Management.""" | ||
|
||
import json | ||
|
||
from rest_framework import serializers | ||
|
||
from context_layer_management.models.layer import LayerStyle | ||
|
||
|
||
class StyleOfLayerSerializer(serializers.ModelSerializer): | ||
"""Serializer for layer.""" | ||
|
||
def get_style(self, obj: LayerStyle): | ||
"""Return style.""" | ||
style = obj.style | ||
layer = self.context.get('layer', None) | ||
request = self.context.get('request', None) | ||
if layer: | ||
# Append uuid to style | ||
if 'sources' not in style: | ||
style['sources'] = {} | ||
style['sources'][str(layer.unique_id)] = { | ||
"tiles": [ | ||
request.build_absolute_uri('/')[:-1] + layer.tile_url | ||
], | ||
"type": "vector" | ||
} | ||
style = json.dumps(style).replace( | ||
'<uuid>', str(layer.unique_id) | ||
) | ||
style = json.loads(style) | ||
|
||
# Append version | ||
if 'version' not in style: | ||
style['version'] = 8 | ||
return style | ||
|
||
def to_representation(self, instance): | ||
data = super(StyleOfLayerSerializer, self).to_representation(instance) | ||
data.update(self.get_style(obj=instance)) | ||
return data | ||
|
||
class Meta: # noqa: D106 | ||
model = LayerStyle | ||
fields = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters