使用JXMapViewer源代码(link to github)中的基本示例,我修改了源代码以从wms服务器加载切片。但是,尽管测试显示URL已正确形成,但Tilefactory并未正确加载磁贴。
唯一修改的部分是:
TileFactoryInfo info = new WMSTileFactoryInfo(0, 10, 11, "https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi", "mrms_p48h");
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
mapViewer.setTileFactory(tileFactory);
并测试产生正确形成的url,可以在webbrowser中加载:
//Test: Created URLs work. 10 = max zoom
System.out.println(info.getTileUrl(0, 0, 10));
System.out.println(info.getTileUrl(0, 1, 9));
System.out.println(info.getTileUrl(1, 1, 9));
但是,当我尝试在简单的JFrame中显示它时(除了不同的中心位置Des Moins(与OSM一起使用)之外的代码未更改),瓷砖将不会加载。
以下是我测试的完整代码:
import javax.swing.JFrame;
import org.jxmapviewer.viewer.DefaultTileFactory;
import org.jxmapviewer.viewer.GeoPosition;
import org.jxmapviewer.JXMapViewer;
import org.jxmapviewer.WMSTileFactoryInfo;
import org.jxmapviewer.viewer.TileFactoryInfo;
public class WMSTest {
public static void main(String[] args) {
JXMapViewer mapViewer = new JXMapViewer();
// Create a TileFactoryInfo for WMS
//WMSTileFactoryInfo int minZoom, int maxZoom, int totalMapZoom, java.lang.String baseURL, java.lang.String layers)
TileFactoryInfo info = new WMSTileFactoryInfo(0, 10, 11, "https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi", "mrms_p48h");
//Test: Do created URLs work? 10 = max zoom, 9 = 1 level lower -> OK.
System.out.println(info.getTileUrl(0, 0, 10));
System.out.println(info.getTileUrl(0, 1, 9));
System.out.println(info.getTileUrl(1, 1, 9));
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
mapViewer.setTileFactory(tileFactory);
// Create a TileFactoryInfo for OpenStreetMap
//TileFactoryInfo info2 = new OSMTileFactoryInfo();
//DefaultTileFactory tileFactory2 = new DefaultTileFactory(info2);
//mapViewer.setTileFactory(tileFactory2);
// Use 8 threads in parallel to load the tiles
tileFactory.setThreadPoolSize(8);
// Set the focus
GeoPosition desMoines = new GeoPosition(41.590833, -93.620833);
mapViewer.setZoom(9);
mapViewer.setAddressLocation(desMoines);
// Display the viewer in a JFrame
JFrame frame = new JFrame("JXMapviewer2 Example 1");
frame.getContentPane().add(mapViewer);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
答案 0 :(得分:0)
所以错误就是服务器响应。使用
?SERVICE=WMS&REQUEST=GetCapabilities
确实返回
<AccessConstraints>None</AccessConstraints>
但这并不意味着服务器会接受来自任何来源的请求。 APPID。我通过使用不同的公共和私有wms服务器测试解决了我的问题,问题不在代码中,(某些)服务器只是不接受来自我的应用程序的请求。仍然会对知识渊博的人的回答感到高兴,但与此同时 - 也许这有助于某些人遇到同样的问题。