我正在使用传单来渲染政府 Map 并通过Python后端添加自定义标记 . 这些标记是使用
var markers = {
{% for marker in markers.all %}
'{{ marker.slug }}': L.icon({
iconUrl: '{{ marker.icon.get_absolute_url }}',
{% if marker.shadow %}
shadowUrl: '{{ marker.shadow.get_absolute_url }}',
{% endif %}
}),
{% endfor %}
我试图以类似Google Map 支持的方式发送图像base64编码(Marker Using base64 encoded string)但没有成功, Map 渲染中止了"Uncaught SyntaxError: Unexpected token ILLEGAL" .
编辑:
一种可能的解决方案:扩展Leaflet的Icon类https://github.com/cavis/leafpile/blob/master/src/LeafpileIcon.js#L28
1 回答
问题是由我将图像转换为base64的方式引起的 .
代替
我用的是:
它插入新行字符('\ n')导致“Unexpected token ILLEGAL”Javascript错误 . Leaflet 0.7正确支持base64编码标记图标 .