我正在尝试在路径中添加一个变量来映射图层。
mypath='MyApp'
var Finals = L.tileLayer.wms("http://localhost:8080/geoserver/'+mypath+'/wms", {
layers: 'MyApp:finalVector',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});
如何在 Finals 变量中添加 mypath 变量。
添加后应如下所示
var Finals = L.tileLayer.wms("http://localhost:8080/geoserver/MyApp/wms", {
layers: 'MyApp:finalVector',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});
答案 0 :(得分:1)
mypath='MyApp'
var Finals = L.tileLayer.wms("http://localhost:8080/geoserver/" + mypath + "/wms", {
layers: 'MyApp:finalVector',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});
答案 1 :(得分:1)
您可以使用模板文字将变量传递给字符串。
var Finals = L.tileLayer.wms(`http://localhost:8080/geoserver/${mypath}/wms`, {
layers: 'MyApp:finalVector',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});