Skip to content

Commit

Permalink
Properly serialize decimals to ensure lat/lng accuracy (Fixes #185)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanlister committed May 31, 2021
1 parent be12374 commit b5a2c60
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit b5a2c60

Please sign in to comment.