我可以将wms栅格显示到Google地图中,但它会错位。图像的坐标系是正确的,似乎一切正常,但是光栅不合适。这是我的代码:

            SLPLayer =
   new google.maps.ImageMapType (
   {
    getTileUrl:
      function (coord, zoom) {
        var proj = map.getProjection();
        var zfactor = Math.pow(2, zoom);
         // get Long Lat coordinates
        var top = proj.fromPointToLatLng(
               new google.maps.Point(coord.x * 256 / zfactor, coord.y * 256 / zfactor) );
        var bot = proj.fromPointToLatLng(
              new google.maps.Point((coord.x + 1) * 256 / zfactor, (coord.y + 1) * 256 / zfactor));
        //corrections for the slight shift of the SLP (mapserver)
         var deltaX = 0.0013;
         var deltaY = 0.00058;

        //create the Bounding box string
         var bbox = (top.lng() + deltaX) + "," +(bot.lat() + deltaY) +","
                             +(bot.lng() + deltaX) +"," +(top.lat() + deltaY);

         //base WMS URL
         var url ="http://209.41.76.52:8080/geoserver/Caragua/wms?";
         url +="&REQUEST=GetMap"; //WMS operation
         url +="&SERVICE=WMS"; //WMS service
         url +="&VERSION=1.1.0"; //WMS version
         url +="&LAYERS=" + "Caragua:caraguaauto11gcpsp2merged_transparent_mosaic_group1"; //WMS layers
         url +="&FORMAT=image/png"; //WMS format
         url +="&BGCOLOR=0xFFFFFF" ;
         url +="&TRANSPARENT=TRUE" ;
         url +="&SRS=EPSG:4326"; //set WGS84 3349 ou 4326
         url +="&BBOX="+ bbox; // set bounding box
         url +="&WIDTH=256"; //tile size in google
         url +="&HEIGHT=256" ;
         console.log(url);
         return url; // return URL for the tile

       }, //getTileURL
   tileSize: new google.maps.Size(256, 256),
   isPng: true
   });
   //add WMS layer
   map.overlayMapTypes.push(SLPLayer);

最佳答案

只需用以下几行替换前20行代码:



            SLPLayer =
   new google.maps.ImageMapType (
   {
    getTileUrl:
      function (coord, zoom) {
        var proj = map.getProjection();
        var zfactor = Math.pow(2, zoom);
        var ul = new google.maps.Point(coord.x * 256.0 / zfactor , (coord.y + 1) * 256.0 / zfactor );
        var lr = new google.maps.Point((coord.x + 1) * 256.0 / zfactor , (coord.y) * 256.0 / zfactor );
        var ulw = proj.fromPointToLatLng(ul);
        var lrw = proj.fromPointToLatLng(lr);
        var bbox = ulw.lng() + "," + ulw.lat() + "," + lrw.lng() + "," + lrw.lat();

关于javascript - WMS叠加层在Google Maps API中移位,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32571746/

10-11 11:12