- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我可以使用下面的代码检索和设置 WMSLayer,但我想将一些额外的选项传递给服务器(特别是使用对数标度并设置颜色标度范围)。 WMSLayer
构造函数采用 options
参数,但这必须是 (unicode) 字符串列表,而且我无法设置与参数对应的值。
也就是说,我可以传递 options=['logscale']
(如下所示),但尝试将其设置为 True 或 False(或“true”或“false”)失败,尝试了这样的变体作为 options=['logscale', 'true']
或 options=['logscale=true']
。
检查发送到服务器的参数(JS 控制台将显示错误)表明使用了“logscale”,但始终设置为未定义。也就是说,类似于 https://some-server.domain.tld/thredds/wms/somefile.nc?service=WMS&request=...&logscale=undefined&...
。
如何在 WMSLayer 构造函数中传递额外选项的值?
是否确实有一种方法可以从 ipyleaflet 到底层的 leaflet.js 中获得额外的选项?
import ipyleaflet
from owslib.wms import WebMapService
wms_url = "https://some-server.domain.tld/thredds/wms/somefile.nc"
wms_layers = list(WebMapService(wms_url).contents.keys())
wms = ipyleaflet.WMSLayer(url=wms_url, layers=wms_layers[0], transparent=True,
format='image/png', opacity=0.33, options=['logscale'])
m = ipyleaflet.Map(zoom=3)
m.add_layer(wms)
# fetch map and display in Jupyter cell
m
最佳答案
您可以继承 WMSLayer
以添加新选项,如下所示:
from ipyleaflet import WMSLayer
from traitlets import Bool
class WMSLayerCustom (WMSLayer):
# Additional options
logscale = Bool(True).tag(sync=True, o=True)
然后不使用 ipyleaflet.WMSLayer
,而是使用子类 WMSLayerCustom
:
wms = WMSLayerCustom(url=wms_url, layers=wms_layers[0], transparent=True,
format='image/png', opacity=0.33, logscale=True)
生成的 url 将包含:
...&version=1.1.1&logscale=true&width=256&...
options
关键字参数没有记录,而且它似乎不能用于设置其他选项。
我还注意到构造函数中接受任何关键字参数,因为 WMSLayer
类继承自 traitlets
模块中的 HasTraits
。设置参数 options=['logscale']
只是覆盖 WMSLayer
实例的 options
属性。
例如,如果您调用:
wms = ipyleaflet.WMSLayer(url=wms_url, layers=wms_layers[0], transparent=True,
format='image/png', opacity=0.33, options=['max_zoom'])
你得到一个带有 &layers=&...&transparent=false&...
的 url,这是 layer
和 transparent
的默认值选项,从而在调用 WMSLayer
时忽略 layers=wms_layers[0]
和 transparent=True
。
关于python - 如何在 ipyleaflet 中为 WMS 层设置额外选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54482665/
我有多个坐标(纬度和经度),我想创建一个热图。我已经在线检查了所有文档和示例,但找不到任何可以帮助我在 ipyleaflet map 上创建热图的内容。 请有人建议我如何生成热图图层并将其添加到 ip
我可以使用下面的代码检索和设置 WMSLayer,但我想将一些额外的选项传递给服务器(特别是使用对数标度并设置颜色标度范围)。 WMSLayer 构造函数采用 options 参数,但这必须是 (un
我正在使用 ipyleaflet 在 map 上显示拥堵情况。 出于某种原因,我无法让热图图层显示在我选择的坐标上。不确定我做错了什么。 from ipyleaflet import Map, Hea
我尝试使用 ipyleaflet 将数据可视化导出为 PNG 或任何其他文件格式,但我找不到有效的方法。例如在 folium 中有 map.save(path)。 ipyleaflet 中是否有我在研
各位, 当我尝试在 ipyleafltet 中创建 map 时出现错误,因此我尝试了以下步骤以完全重新安装 jupyter 和 ipyleaflet。现在我没有收到错误,但 ipywidget 只是挂
我是一名优秀的程序员,十分优秀!