Re: mapserver слои
Добавлено: 17 апр 2012, 11:47
Что значит локально лежащий, map-файл лежит на web-сервере.
Геоинформационные системы (ГИС) и Дистанционное зондирование Земли
https://gis-lab.info/forum/
Код: Выделить всё
http://my.host.com:8880/cgi-bin/mapserv?map=/var/www/map2/hrllo.map&mode=mapВот реальный пример из одного проекта, использующий python MapScript. Враппер (view_ows()) принимает на входе 2 параметра - SETTINGS и ITEMS_CLICKED, затем использует эти параметры для формирования map-файла (configure()) и используя таким образом сформированный map-файл выдаем ответ клиенту:Frank Warmerdam писал(а):For the WMS service itself MapServer already handles the GET and POST requests for the various requests (GetCapabilities, GetMap, etc). The wrapper script is basically to predefine a few things like the location of the map file that you might not want to normally expose to the end user.
There are situations in which you might want to customize your map definition based on additional parameters passed to your service or otherwise do special stuff for some kinds of WMS requests. To support some of these use cases I implemented the so called "WxS mapscript wrapper" mechanism. This makes it possible to write a python wrapper that customizes WMS, WFS, and other services to some degree or even radically transorms incoming request into something like a WMS request with interactions with the map object.
Код: Выделить всё
def configure(settings, **kwargs):
template_file = settings['mapserver.mapfile']
_temp_mapfile = NamedTemporaryFile(suffix=".map",delete=False)
template = Template(filename=template_file)
buf = StringIO()
ctx = Context(buf,
onlineresource=settings['mapserver.onlineresource'],
connection=settings['mapserver.connection'],
symbolset = settings['mapserver.symbolset'],
map_settings=kwargs['map_settings'],
items_clicked=kwargs['items_clicked'])
template.render_context(ctx)
_temp_mapfile.write(buf.getvalue())
_temp_mapfile.flush()
return _temp_mapfile.name
@view_config(route_name="mapserver.ows")
def view_ows(request):
import mapscript
ows_req = mapscript.OWSRequest()
for k,v in request.params.items():
ows_req.setParameter(k, urllib.unquote(v))
_settings = request.params.get('SETTINGS', '[]')
_items_clicked = request.params.get('ITEMS_CLICKED', '[]')
map_obj = mapscript.mapObj(configure(request.registry.settings,\
items_clicked=json.loads(_items_clicked),\
map_settings=json.loads(_settings)))
mapscript.msIO_installStdoutToBuffer()
map_obj.OWSDispatch(ows_req)
content_type = mapscript.msIO_stripStdoutBufferContentType()
content = mapscript.msIO_getStdoutBufferBytes()
return Response(content, content_type=content_type)Код: Выделить всё
http://192.168.56.193/cgi-bin/mapserv?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&map=/var/www/map2/fldwms.mapКод: Выделить всё
layer = new OpenLayers.Layer.MapServer( "World Map","http://192.168.56.193/cgi-bin/mapserv", {map: '/var/www/map2/fldwms.map'} );
layer = new OpenLayers.Layer.WMS( "NYC","http://192.168.56.193/cgi-bin/mapserv?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&map=/var/www/map2/fldwms.map",{layers: "'fld,rd,rstr'"});Код: Выделить всё
http://192.168.56.193/cgi-bin/mapserv?map=/var/www/map2/fldwms.mapКод: Выделить всё
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{type: G_PHYSICAL_MAP}
);Код: Выделить всё
var lay_goo = new OpenLayers.Layer.Google('Google', {
type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22, sphericalMercator: true, opacity: 0.5
});

Код: Выделить всё
http://maps.google.com/maps/api/js?v=3.6&sensor=false