MapServer и OpenLayers: не открывается карта

Mapserver, GeoServer, MapGuide, Google и другое ПО для веб-картографии
Ответить
Аватара пользователя
dakotta
Новоприбывший
Сообщения: 12
Зарегистрирован: 04 апр 2013, 12:22
Репутация: 0
Откуда: Томск
Контактная информация:

MapServer и OpenLayers: не открывается карта

Сообщение dakotta »

Здравствуйте!
Помогите, пожалуйста! Не получается отобразить карту через WMS на OpenLayers

Создала map-файл для поддержки WMS (sip.map):

Код: Выделить всё

MAP
  NAME           "WMS"
  STATUS         ON
  IMAGETYPE      PNG
  EXTENT         667190.161507 5580041.069265 719229.643505 5623106.149870
  SIZE           800 500
  SHAPEPATH      "/ms4w/apps/sip/shp/" 
  IMAGECOLOR     255 255 255
 PROJECTION
   "proj=latlong"
   "ellps=WGS84"
   "datum=WGS84"
END
  WEB
    TEMPLATE  './templates/template.html'
    IMAGEPATH '/ms4w/tmp/ms_tmp/'
    IMAGEURL  '/ms_tmp/'
	METADATA
		wms_title                  "Test"
		wms_abstract               "This is the test"
		wms_onlineresource         "http://localhost/cgi-bin/mapserv.exe?map=d:/ms4w/apps/sip/sip.map&"
		wms_srs                    "EPSG:4326"
		wms_getfeatureinfo         "http://localhost/cgi-bin/mapserv.exe?map=d:/ms4w/apps/sip/sip.map&"
		wms_featureinfoformat      "text/plain"
		wms_enable_request "*"
	END
  END
  LAYER 
    NAME         "relief"
    DATA         relief
    STATUS       ON
	PROJECTION
		"proj=latlong"
		"ellps=WGS84"
		"datum=WGS84"
    END
	 TYPE         LINE
    CLASS
      NAME       "Рельеф"
      STYLE
        COLOR        12 12 12 
      END
    END
	METADATA
		wms_title         "Countries 1"
		wms_abstract      "Countries 1 test"
		wms_srs           "EPSG:4326"
		wms_include_items "all"
		wms_enable_request "*"
	END
  END 
END
В браузере карта открывается по ссылке http://localhost/cgi-bin/mapserv.exe?ma ... f&mode=map

WMS-сервис дает следующий ответ, т.е. вроде бы работает.

Код: Выделить всё

<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd"
 [
 <!ELEMENT VendorSpecificCapabilities EMPTY>
 ]>  <!-- end of DOCTYPE declaration -->

<WMT_MS_Capabilities version="1.1.1">

<!-- MapServer version 6.0.3 (MS4W 3.0.6) OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE -->

<Service>
  <Name>OGC:WMS</Name>
  <Title>GIS-LAB Demo</Title>
  <Abstract>This is the WMS demo from GIS-Lab</Abstract>
  <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/>
  <ContactInformation>
  </ContactInformation>
</Service>

<Capability>
  <Request>
    <GetCapabilities>
      <Format>application/vnd.ogc.wms_xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </GetCapabilities>
    <GetMap>
      <Format>image/png</Format>
      <Format>image/jpeg</Format>
      <Format>image/gif</Format>
      <Format>image/png; mode=8bit</Format>
      <Format>application/x-pdf</Format>
      <Format>image/svg+xml</Format>
      <Format>image/tiff</Format>
      <Format>application/vnd.google-earth.kml+xml</Format>
      <Format>application/vnd.google-earth.kmz</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </GetMap>
    <GetFeatureInfo>
      <Format>text/plain</Format>
      <Format>application/vnd.ogc.gml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </GetFeatureInfo>
    <DescribeLayer>
      <Format>text/xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </DescribeLayer>
    <GetLegendGraphic>
      <Format>image/png</Format>
      <Format>image/jpeg</Format>
      <Format>image/gif</Format>
      <Format>image/png; mode=8bit</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </GetLegendGraphic>
    <GetStyles>
      <Format>text/xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&"/></Post>
        </HTTP>
      </DCPType>
    </GetStyles>
  </Request>
  <Exception>
    <Format>application/vnd.ogc.se_xml</Format>
    <Format>application/vnd.ogc.se_inimage</Format>
    <Format>application/vnd.ogc.se_blank</Format>
  </Exception>
  <VendorSpecificCapabilities />
  <UserDefinedSymbolization SupportSLD="1" UserLayer="0" UserStyle="1" RemoteWFS="0"/>
  <Layer>
    <Name>WMS</Name>
    <Title>GIS-LAB Demo</Title>
    <Abstract>This is the WMS demo from GIS-Lab</Abstract>
    <SRS>EPSG:4326</SRS>
    <LatLonBoundingBox minx="667190" miny="5.58004e+006" maxx="719230" maxy="5.62311e+006" />
    <BoundingBox SRS=""
                minx="667190" miny="5.58004e+006" maxx="719230" maxy="5.62311e+006" />
    <Layer queryable="0" opaque="0" cascaded="0">
        <Name>relief</Name>
        <Title>Countries 1</Title>
        <Abstract>Countries 1 test</Abstract>
        <SRS>EPSG:4326</SRS>
        <LatLonBoundingBox minx="667190" miny="5.58004e+006" maxx="719230" maxy="5.62311e+006" />
        <BoundingBox SRS="EPSG:4326"
                    minx="667190" miny="5.58004e+006" maxx="719230" maxy="5.62311e+006" />
        <Style>
          <Name>default</Name>
          <Title>default</Title>
          <LegendURL width="71" height="21">
             <Format>image/png</Format>
             <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv.exe??map=d:/ms4w/apps/sip/sip.map&version=1.1.1&service=WMS&request=GetLegendGraphic&layer=relief&format=image/png&STYLE=default"/>
          </LegendURL>
        </Style>
    </Layer>
  </Layer>
</Capability>
</WMT_MS_Capabilities> 
Подключаю WMS через OpenLayers, слой называется relief (подложки нет, пытаюсь получить только один этот слой):

Код: Выделить всё

<html>
    <head>
        <title>OpenLayers</title>
        <script
        src="http://openlayers.org/api/OpenLayers.js"></script>
    </head>
    <body>
        <div style="width:100%; height:100%" id="map"></div>
        <script defer="defer" type="text/javascript">
            var map = new OpenLayers.Map('map');
            var wms = new OpenLayers.Layer.WMS(
            "wms",
            "http://localhost/cgi-bin/mapserv.exe?map=d:/ms4w/apps/sip/sip.map",
            {map: '/ms4w/apps/sip/sip.map', layers: 'relief', transparent: 'true', format: 'image/png'});
            map.addLayer(wms);
        </script>
    </body>
</html>
В результате вижу только белый экран

Подскажите, пожалуйста, в чем ошибка

Все описанные файлы и шейп-файлы прилагаю во вложении
Вложения
temp.zip
(33.14 КБ) 335 скачиваний
Последний раз редактировалось dakotta 10 апр 2013, 09:12, всего редактировалось 1 раз.
Аватара пользователя
Denis Rykov
Гуру
Сообщения: 3376
Зарегистрирован: 11 апр 2008, 21:09
Репутация: 529
Ваше звание: Author
Контактная информация:

Re: MapServer и OpenLayers: не открывается карта

Сообщение Denis Rykov »

Не охота разбираться с вашими конфигами, мне быстрее накидать рабочий вариант.

map-файл:

Код: Выделить всё

MAP

  NAME "dakotta WMS Server"

  SHAPEPATH      "./shp/"

  OUTPUTFORMAT
      NAME          "png"
      EXTENSION     "png"
      MIMETYPE      "image/png"
      DRIVER         AGG/PNG
      IMAGEMODE      RGBA
      FORMATOPTION  "INTERLACE=OFF"
  END

  PROJECTION
      "init=epsg:3857"
  END

  WEB
    METADATA
      "wms_title"          "WMS Demo Server for MapServer"
      "wms_onlineresource" "http://10.22.0.9/cgi-bin/mapserv?map=/home/rykovd/_ctms/dakotta/wms.map&"
      "wms_srs"            "EPSG:4326 EPSG:3857"
      "wms_abstract"       "dakotta demo WMS"
      "wms_enable_request" "*"
      "wms_encoding"       "utf-8"
     END
  END

  LAYER
    NAME "relief"
    METADATA
      "wms_title"         "Рельеф"
      "gml_include_items" "all"
      "wms_enable_request" "*"
      "wms_extent"         "667190.161507 5580041.069265 719229.643505 5623106.149870"
    END
    TYPE LINE
    DATA          "relief"
    CLASS
        STYLE
            COLOR 181 210 214
        END
    END
  END

END
html-файл:

Код: Выделить всё

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Title</title> 
<script src="http://openlayers.org/dev/OpenLayers.js"></script>

<script type="text/javascript">
function init(){

    options = {
        div: "map",
        maxExtent: new OpenLayers.Bounds(667190.161507, 5580041.069265, 719229.643505, 5623106.149870),
        projection: new OpenLayers.Projection("EPSG:3857"),
        layers: [
            new OpenLayers.Layer.WMS( "WMS merc",
            "http://10.22.0.9/cgi-bin/mapserv?map=/home/rykovd/_ctms/dakotta/wms.map&",
            {
                layers: "relief",
                srs:"EPSG:3857",
                transparent: true
            },
            {
                singleTile: true,
                ratio: 1,
                isBaseLayer: true
            })
        ]
    };
    map = new OpenLayers.Map(options);
    map.zoomToMaxExtent();
}
</script> 
</head> 
<body onload="init()"> 
    <div id="map" style="width:640px; height:480px;"></div> 
</body> 
</html>
Сравните со своим и разберитесь почему у вас не работало. Пути только поменяйте раз вы в Windows работаете. Рекомендую перед тем как публиковать WMS в Web-клиенте проверить его в настольном приложении (например, QGIS).
Spatial is now, more than ever, just another column- The Geometry Column.
Аватара пользователя
dakotta
Новоприбывший
Сообщения: 12
Зарегистрирован: 04 апр 2013, 12:22
Репутация: 0
Откуда: Томск
Контактная информация:

Re: MapServer и OpenLayers: не открывается карта

Сообщение dakotta »

Спасибо большое, вы мне очень помогли! Все получилось.

[ Сообщение с мобильного устройства ]
Ответить

Вернуться в «Веб-картография»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 4 гостя