Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly serialize decimals to ensure lat/lng accuracy (Fixes #185) #186

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion mapboxgl/viz.py
@@ -1,4 +1,5 @@
import codecs
import decimal
import json
import os

Expand All @@ -15,6 +16,13 @@
GL_JS_VERSION = 'v1.5.0'


class FullJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o)
return super().default(o)


class VectorMixin(object):

def generate_vector_color_map(self):
Expand Down Expand Up @@ -278,7 +286,7 @@ def create_html(self, filename=None):
style=style,
center=list(self.center),
zoom=self.zoom,
geojson_data=json.dumps(self.data, ensure_ascii=False),
geojson_data=json.dumps(self.data, ensure_ascii=False, cls=FullJSONEncoder),
belowLayer=self.below_layer,
opacity=self.opacity,
minzoom=self.min_zoom,
Expand Down