Java 使用JXMapViewer的WMS层不';t载荷
使用JXMapViewer sources()中的基本示例,我修改了源代码以从wms服务器加载磁贴。但是,尽管测试显示URL的格式正确,但Tilefactory无法正确加载Tile 唯一修改的部分是:Java 使用JXMapViewer的WMS层不';t载荷,java,wms,jxmapviewer,Java,Wms,Jxmapviewer,使用JXMapViewer sources()中的基本示例,我修改了源代码以从wms服务器加载磁贴。但是,尽管测试显示URL的格式正确,但Tilefactory无法正确加载Tile 唯一修改的部分是: TileFactoryInfo info = new WMSTileFactoryInfo(0, 10, 11, "https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi", "mrms_p48h"); DefaultTi
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);
通过测试,可以在webbrowser中加载格式正确的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:
但是,当我尝试在简单的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
他回来了吗
<AccessConstraints>None</AccessConstraints>
无
但这并不意味着服务器将接受来自任何源&appid的请求。我通过测试不同的公共和私有wms服务器解决了我的问题,问题不在代码中,(一些)服务器不接受来自我的应用程序的请求。如果有知识渊博的人能给你一个答案,我还是会很高兴的,但与此同时,也许这会帮助你遇到同样的问题