首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

MapServer+OpenLayer 显示简单map不成功

2013-09-13 
MapServer+OpenLayer 显示简单地图不成功,求助直接访问本机的MapServer服务器可以正确看到地图,但,使用Ope

MapServer+OpenLayer 显示简单地图不成功,求助
直接访问本机的MapServer服务器可以正确看到地图,
但,使用OpenLayer写个简单的页面却看不到地图,请指教哇。
用IE直接访问MapServer可以显示地图:
http://127.0.0.1/cgi-bin/mapserv.exe?MAP=C:/OSGeo4W/apache/htdocs/SZMAP/sz.map&LAYERS=ALL&MODE=MAP
MapServer+OpenLayer 显示简单map不成功

通过OpenLayer的网页访问无法显示地图:
http://127.0.0.1/szmap/openlayerTT.html
MapServer+OpenLayer 显示简单map不成功

openlayerTT.html如下:

<!DOCTYPE html>
<html>
  <head>
    <title>OpenLayers Tutorial - Basic Map Setup</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    <script type="text/javascript">
        var map, baseLayer;
        function init(){
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.MapServer( "region",
"http://127.0.0.1/cgi-bin/mapserv.exe", 
{map: 'C:/OSGeo4W/apache/htdocs/SZMAP/sz.map'});
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(114,22));
        }
    </script>
 
    <style>
    @media screen
    {
        #map{width: 500px; height:250px; border: 2px solid black;}
    }
    </style>
  </head>
  <body onload="init()">
    <h3>OpenLayers Tutorial - Basic Map Setup</h3>
    <div id="map"></div>
  </body>
</html>


sz.map 内容如下:
# Map file created from QGIS project file 
# Edit this file to customize for your map interface
# (Created with PyQgis MapServer Export plugin)
MAP
  NAME "QGIS-MAP"
  # Map image size
  SIZE 600 400
  UNITS dd

  EXTENT 114.055799 22.537858 114.108519 22.561268
  FONTSET './fonts/fonts.txt'
  SYMBOLSET './symbols/symbols.txt'
  PROJECTION
    'proj=longlat'
    'datum=WGS84'
    'no_defs'
  END



  # Background color for the map canvas -- change as desired
  IMAGECOLOR 255 255 255
  IMAGEQUALITY 95
  IMAGETYPE png

  OUTPUTFORMAT
    NAME png
    DRIVER 'GD/PNG'
    MIMETYPE 'image/png'
    IMAGEMODE RGBA
    EXTENSION 'png'
  END
  # Legend
  LEGEND
      IMAGECOLOR 255 255 255
    STATUS ON
    KEYSIZE 18 12
    LABEL
      TYPE BITMAP
      SIZE MEDIUM
      COLOR 0 0 89
    END
  END

  # Web interface definition. Only the template parameter
  # is required to display a map. See MapServer documentation
  WEB
    # Set IMAGEPATH to the path where MapServer should
    # write its output.
    IMAGEPATH '/tmp/'

    # Set IMAGEURL to the url that points to IMAGEPATH
    # as defined in your web server configuration
    IMAGEURL '/tmp/'

    # WMS server settings
    METADATA
      'ows_title'           'QGIS-MAP'
      'ows_onlineresource'  'http://127.0.0.1/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/SZMAP/sz.map'
      'ows_srs'             'EPSG:4326'
    END

    #Scale range at which web interface will operate
    # Template and header/footer settings
    # Only the template parameter is required to display a map. See MapServer documentation
    TEMPLATE 'fooOnlyForWMSGetFeatureInfo'
  END

  LAYER
    NAME 'region'
    TYPE POLYGON


    DUMP true
    TEMPLATE fooOnlyForWMSGetFeatureInfo
  EXTENT 114.055799 22.537858 114.108519 22.561268
    DATA './region.shp'
    METADATA
      'ows_title' 'region'
    END
    STATUS OFF
    TRANSPARENCY 100
    PROJECTION
    'proj=longlat'
    'datum=WGS84'
    'no_defs'
    END
    CLASS
       NAME 'region' 
       STYLE
         WIDTH 0.91 
         OUTLINECOLOR 0 0 0
         COLOR 103 170 188
       END
    END
  END

  LAYER
    NAME 'polyline'
    TYPE LINE
    DUMP true
    TEMPLATE fooOnlyForWMSGetFeatureInfo
  EXTENT 114.055799 22.537858 114.108519 22.561268
    DATA './polyline.shp'
    METADATA
      'ows_title' 'polyline'
    END
    STATUS OFF
    TRANSPARENCY 100
    PROJECTION
    'proj=longlat'
    'datum=WGS84'
    'no_defs'
    END
    CLASS
       NAME 'polyline' 
       STYLE
         WIDTH 0.91 
         COLOR 162 139 23
       END
    END
  END

END



WebGis MapServer OpenLayer


[解决办法]
jf, thanks~

热点排行