使用 JXMapViewer 的 WMS 层不加载

WMS Layer using JXMapViewer doesn't load

使用来自 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:

    //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));
第一个图块的

URL: https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi?version=1.1.1&request=GetMap&layers=mrms_p48h&format=image/jpeg&bbox=-180.0,0.0,0.0,85.05112877980659&width=255&height=255&srs=EPSG:4326&styles=&bgcolor=0xAFDAF6

但是,当我尝试在简单的 JFrame 中显示它时(除了与 OSM 一起工作的不同中心位置 Des Moins 之外,示例中的代码没有变化),图块将不会加载。

这是我测试的完整代码:

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);
}
}

所以错误是服务器响应。使用

   ?SERVICE=WMS&REQUEST=GetCapabilities

return

   <AccessConstraints>None</AccessConstraints>

但这并不意味着服务器将接受来自任何来源和appid 的请求。我通过使用不同的 public 和私有 wms 服务器进行测试解决了我的问题,问题不在代码中,(某些)服务器只是不接受来自我的应用程序的请求。仍然会对知识渊博的人的回答感到高兴,但与此同时 - 也许这可以帮助 运行 遇到同样的问题。