从Google Maps Engine发布的WMS不显示 [英] WMS published from Google Maps Engine not displaying

查看:154
本文介绍了从Google Maps Engine发布的WMS不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我有因为WMS似乎没有显示任何东西,所以被下面的代码卡住了。

我遗失的是Google Maps Engine WMS的baseURL和我为这个特定地图使用资产ID的'图层'变量。我很迷茫,希望得到任何帮助。

 函数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);

//用户将在此输入公共WMS图层的地址。数据必须为WGS84
var baseURL =https://mapsengine.google.com/17306057122701807517-17234028967417318364-4/wms/?;
var version =1.1.1;
var request =GetMap;
var format =image / jpeg; //返回的图像类型或image / jpeg

//图层ID。在ArcMap中使用图层属性工具时可以找到
var layers =17306057122701807517-17234028967417318364;
var srs =EPSG:4326; //投影显示。这是谷歌地图的投影。除非你知道你在做什么,否则不要改变。
var bbox = ulw.lng()+,+ ulw.lat()+,+ lrw.lng()+,+ lrw.lat();

//拼贴的大小,必须为256x256
var width =256;
var height =256;

var styles =default;

//建立baseURL。
var url = baseURL +version =+ version +& request =+ request +& Layers =+ layers +& Styles =+ styles +& SRS =+ srs +& BBOX =+ bbox +& width =+ width +& height =+ height +& format =+ format;

返回网址;


解决方案

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

现在针对您的第二个问题,这是比较微妙的。以上示例中使用的EPSG代码是4326,即WGS84,而Google地图是在Google Web墨卡托中发布的,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,它允许你做属性过滤,空间查询等。


I am new to JS and Google Maps API...I acquired some JS code to hopefully display a WMS that I created in Google Maps Engine.

I have got stuck with the below code as the WMS seems to not display anything.

Where I get lost is the baseURL for the Google Maps Engine WMS and the 'layers' variable which I used the Asset ID for this particular map. I'm quite lost here and would appreciate any help.

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

解决方案

You've got 2 problems with your code. The first is obvious. You're using your map ID as your layer ID. They're two separate things. In GME, go in to the layer detail screen and click "Access Links" and pick up the layer ID. It'll start with 17306057122701807517- but the second half will be different. Also, don't forget to append -4 to the end. This indicates it's a published layer as opposed to one in preview. Tip: If you make it -2 you can see the preview version e.g. the updated but unpublished one.

Now for your second problem which is way more subtle. The EPSG code used in the above example is 4326 which is WGS84 while Google Maps are published in Google Web Mercator which is EPSG:900913. You can't just swap out the EPSG code as the coordinate system used is different. This really means that unless you rewrite the code to generate the bounding box then you can't use that javascript.

What I'd recommend is using the code from http://www.sigacts.com/html5/google-maps-api-with-wms-overlay/ which uses the correct coordinate system. The example actually uses a MapsEngine map as well. Just download the code and modify vars.js to suit and you're away. I've downloaded and validated that it works with my own map as well so you should have no problems. Hint: The code is a little old and references earthbuilder.google.com which is the old name for MapsEngine. Make sure you change both the domain name and the Map ID.

EDIT: WMS is a clunky way of getting content on to the Map. You should be looking to use MapsEngineLayer which is part of the Google Maps API or for more fine-grained things you can use the Maps Engine API which allows you to do attribute filtering, spatial queries etc.

这篇关于从Google Maps Engine发布的WMS不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆