从Google Maps Engine发布的WMS未显示

时间:2014-05-20 12:18:46

标签: javascript google-maps-api-3 wms

我是JS和Google Maps API的新手...我获得了一些JS代码,希望能够显示我在Google Maps Engine中创建的WMS。

我遇到了以下代码,因为WMS似乎没有显示任何内容。

我丢失的地方是Google Maps Engine WMS的baseURL和我使用此特定地图的资产ID的'layers'变量。我很迷失在这里,并感谢任何帮助。

function WMSGetTileUrl1(tile, zoom) {
    var projection = window.mapA.getProjection();
    var zpow = Math.pow(2, zoom);
    var ul = new google.maps.Point(tile.x * 256.0 / zpow, (tile.y + 1) * 256.0 / zpow);
    var lr = new google.maps.Point((tile.x + 1) * 256.0 / zpow, (tile.y) * 256.0 / zpow);
    var ulw = projection.fromPointToLatLng(ul);
    var lrw = projection.fromPointToLatLng(lr);

    //The user will enter the address to the public WMS layer here.  The data must be in WGS84
    var baseURL = "https://mapsengine.google.com/17306057122701807517-17234028967417318364-4/wms/?";
    var version = "1.1.1";
    var request = "GetMap";
    var format = "image/jpeg"; //type of image returned  or image/jpeg

    //The layer ID.  Can be found when using the layers properties tool in ArcMap
    var layers = "17306057122701807517-17234028967417318364"; 
    var srs = "EPSG:4326"; //projection to display. This is the projection of google map. Don't change unless you know what you are doing.
    var bbox = ulw.lng() + "," + ulw.lat() + "," + lrw.lng() + "," + lrw.lat();

    //the size of the tile, must be 256x256
    var width = "256";
    var height = "256";

    var styles = "default";

    //Establish the baseURL.
    var url = baseURL + "version=" + version + "&request=" + request + "&Layers=" + layers + "&Styles=" + styles + "&SRS=" + srs + "&BBOX=" + bbox + "&width=" + width + "&height=" + height + "&format=" + format;

    return url;
}

1 个答案:

答案 0 :(得分:1)

您的代码存在2个问题。第一个是显而易见的。您已将地图ID用作图层ID。它们是两个不同的东西。在GME中,进入图层详细信息屏幕,然后单击"访问链接"并获取图层ID。它将从17306057122701807517开始 - 但下半场将有所不同。另外,不要忘记将-4附加到最后。这表明它是已发布的图层,而不是预览图层。提示:如果您将其设为-2,则可以看到预览版本,例如更新但未发表的。

现在你的第二个问题更加微妙。上面例子中使用的EPSG代码是4326,它是WGS84,而谷歌地图是在Google Web Mercator中发布的,即EPSG:900913。由于使用的坐标系不同,您无法更换EPSG代码。这实际上意味着除非您重写代码以生成边界框,否则您无法使用该javascript。

我建议使用http://www.sigacts.com/html5/google-maps-api-with-wms-overlay/中使用正确坐标系的代码。该示例实际上也使用了MapsEngine地图。只需下载代码并修改vars.js以适应您的需要即可。 我已经下载并验证了它与我自己的地图一起工作,所以你应该没有问题。提示:代码有点陈旧,并引用了earthbuilder.google.com,这是MapsEngine的旧名称。确保您更改了域名和地图ID。

编辑:WMS是一种将内容添加到地图上的笨重方式。您应该使用MapsEngineLayer这是Google Maps API的一部分,或者您可以使用Maps Engine API进行更精细的操作,以便进行属性过滤,空间查询等。