Skip to content

Commit 99a8d56

Browse files
authored
Merge pull request #144 from maptiler/21_1_bugfixes
21/1 bugfixes
2 parents 76f4927 + 5531a35 commit 99a8d56

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

browser_mapitem.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ def _is_apikey_valid(self):
111111

112112
def _is_vector_json(self, json_url: str) -> bool:
113113
url_endpoint = json_url.split("?")[0]
114-
if url_endpoint.endswith("style.json"):
115-
return True
114+
if url_endpoint.endswith(".json"):
115+
style_json_data = converter.get_style_json(json_url)
116+
if "sources" in style_json_data and "layers" in style_json_data:
117+
return True
116118
# tiles.json
117119
else:
118120
json_data = json.loads(requests.get(json_url).text)

gl2qgis/converter.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
import io
1717
import os
1818

19-
from PIL import Image
20-
2119
from .gl2qgis import parse_layers, parse_background, parse_interpolate_list_by_zoom
2220
from .gl2qgis import parse_interpolate_opacity_by_zoom, PropertyType
21+
from qgis.PyQt.QtWidgets import QMessageBox
2322

2423

2524
def get_sources_dict_from_style_json(style_json_data: dict) -> dict:
@@ -84,7 +83,7 @@ def get_sources_dict_from_style_json(style_json_data: dict) -> dict:
8483

8584
def get_style_json(style_json_url: str) -> dict:
8685
url_endpoint = style_json_url.split("?")[0]
87-
if url_endpoint.endswith("style.json"):
86+
if url_endpoint.endswith(".json"):
8887
style_json_data = json.loads(requests.get(style_json_url).text)
8988
return style_json_data
9089
elif url_endpoint.endswith(".pbf"):
@@ -178,18 +177,25 @@ def write_sprite_imgs_from_style_json(style_json_data: dict, output_path: str):
178177
sprite_url = style_json_data.get("sprite")
179178
if sprite_url is None:
180179
return {}
181-
182-
sprite_json_dict = json.loads(requests.get(sprite_url + '.json').text)
183-
sprite_img = Image.open(io.BytesIO(requests.get(sprite_url + '.png').content))
184-
sprite_imgs_dict = {}
185-
186-
for key, value in sprite_json_dict.items():
187-
left = int(value["x"])
188-
top = int(value["y"])
189-
right = left + int(value["width"])
190-
bottom = top + int(value["height"])
191-
cropped = sprite_img.crop((left, top, right, bottom))
192-
sprite_imgs_dict[key] = cropped
193-
194-
for key, value in sprite_imgs_dict.items():
195-
value.save(os.path.join(output_path, key + ".png"))
180+
try:
181+
from PIL import Image
182+
sprite_json_dict = json.loads(requests.get(sprite_url + '.json').text)
183+
sprite_img = Image.open(io.BytesIO(requests.get(sprite_url + '.png').content))
184+
sprite_imgs_dict = {}
185+
186+
for key, value in sprite_json_dict.items():
187+
left = int(value["x"])
188+
top = int(value["y"])
189+
right = left + int(value["width"])
190+
bottom = top + int(value["height"])
191+
cropped = sprite_img.crop((left, top, right, bottom))
192+
sprite_imgs_dict[key] = cropped
193+
194+
for key, value in sprite_imgs_dict.items():
195+
value.save(os.path.join(output_path, key + ".png"))
196+
except ImportError:
197+
import_error_message = "You do not have PIL/Pillow library installed on your system. "\
198+
"Sprites will not be supported.\n"\
199+
"MacOS users: To install Pillow library, run following code in terminal:\n"\
200+
"/Applications/QGIS.app/Contents/MacOS/bin/pip3 install pillow -U"
201+
QMessageBox.warning(None, 'Missing PIL/Pillow library', import_error_message)

gl2qgis/gl2qgis.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from PyQt5.QtGui import QColor, QFont
1919
from qgis.core import *
2020
from qgis.gui import *
21+
from qgis.PyQt.QtWidgets import QMessageBox
2122

2223
# SCREEN SETTING
2324
screen = QgsApplication.primaryScreen()
@@ -67,7 +68,18 @@ def parse_color(json_color: str):
6768
assert len(lst) == 3
6869
return QColor(int(lst[0]), int(lst[1]), int(lst[2]))
6970
else:
70-
raise ValueError("unknown color syntax", json_color)
71+
try:
72+
from PIL import ImageColor
73+
image_color = ImageColor.getrgb(json_color)
74+
return QColor(int(image_color[0]), int(image_color[1]), int(image_color[2]))
75+
except ImportError:
76+
import_error_message = "You do not have PIL/Pillow library installed on your system. " \
77+
"Proper color name parsing might not be supported.\n" \
78+
"MacOS users: To install Pillow library, run following code in terminal:\n" \
79+
"/Applications/QGIS.app/Contents/MacOS/bin/pip3 install pillow -U"
80+
QMessageBox.warning(None, 'Missing PIL/Pillow library', import_error_message)
81+
except ValueError as e:
82+
print(e("unknown color syntax", json_color))
7183

7284

7385
def parse_line_cap(json_line_cap):

metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
name=MapTiler
77
qgisMinimumVersion=3.0
88
description=Street and satellite base maps with vector tiles
9-
version=1.1.3
9+
version=1.1.4
1010
author=MapTiler
1111
email=info@maptiler.com
1212

0 commit comments

Comments
 (0)