<s> """<STR_LIT>""" <EOL> from __future__ import ( absolute_import , division , print_function ) <EOL> from . etree import etree <EOL> context_ns_uri = '<STR_LIT>' <EOL> context_schemas_uri = '<STR_LIT>' <EOL> def WMCElement ( tag ) : <EOL> """<STR_LIT>""" <EOL> return etree . Element ( "<STR_LIT>" % context_ns_uri + tag ) <EOL> class MapContext : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , map_ ) : <EOL> self . _map = map_ <EOL> def _getRootElement ( self ) : <EOL> root = WMCElement ( '<STR_LIT>' ) <EOL> attrs = { <EOL> '<STR_LIT>' : <EOL> context_ns_uri + '<STR_LIT:U+0020>' + context_schemas_uri , <EOL> '<STR_LIT:id>' : self . _map . id , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> } <EOL> for k , v in attrs . items ( ) : <EOL> root . attrib [ k ] = v <EOL> return root <EOL> def _getGeneralElement ( self ) : <EOL> general = WMCElement ( '<STR_LIT>' ) <EOL> general . append ( self . _getWindowElement ( ) ) <EOL> general . append ( self . _getBoundingBoxElement ( ) ) <EOL> return general <EOL> def _getWindowElement ( self ) : <EOL> window = WMCElement ( '<STR_LIT>' ) <EOL> window . attrib [ '<STR_LIT:width>' ] = str ( self . _map . size [ <NUM_LIT:0> ] ) <EOL> window . attrib [ '<STR_LIT>' ] = str ( self . _map . size [ <NUM_LIT:1> ] ) <EOL> return window <EOL> def _getBoundingBoxElement ( self ) : <EOL> bbox = WMCElement ( '<STR_LIT>' ) <EOL> bbox . attrib [ '<STR_LIT>' ] = str ( self . _map . srs . split ( ) [ <NUM_LIT:0> ] ) <EOL> bbox . attrib [ '<STR_LIT>' ] = str ( self . _map . bounds [ <NUM_LIT:0> ] ) <EOL> bbox . attrib [ '<STR_LIT>' ] = str ( self . _map . bounds [ <NUM_LIT:1> ] ) <EOL> bbox . attrib [ '<STR_LIT>' ] = str ( self . _map . bounds [ <NUM_LIT:2> ] ) <EOL> bbox . attrib [ '<STR_LIT>' ] = str ( self . _map . bounds [ <NUM_LIT:3> ] ) <EOL> return bbox <EOL> def _getLayerListElement ( self ) : <EOL> layerlist = WMCElement ( '<STR_LIT>' ) <EOL> layering = zip ( self . _map . layernames , self . _map . layertitles ) <EOL> layer_infos = self . _map . getLayerInfos ( ) <EOL> for name , title in layering : <EOL> layer = WMCElement ( '<STR_LIT>' ) <EOL> layer . attrib [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> layer . attrib [ '<STR_LIT>' ] = str ( <EOL> int ( name not in self . _map . visible_layers ) ) <EOL> if layer_infos and layer_infos . get ( title ) : <EOL> stylelist = WMCElement ( '<STR_LIT>' ) <EOL> for e_style in layer_infos . get ( title ) : <EOL> e_style . attrib [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> for node in e_style . getiterator ( ) : <EOL> tag_name = node . tag [ node . tag . rfind ( '<STR_LIT:}>' ) + <NUM_LIT:1> : ] <EOL> node . tag = "<STR_LIT>" % context_ns_uri + tag_name <EOL> stylelist . append ( e_style ) <EOL> layer . append ( stylelist ) <EOL> server = WMCElement ( '<STR_LIT>' ) <EOL> server . attrib [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> server . attrib [ '<STR_LIT:version>' ] = '<STR_LIT>' <EOL> server . attrib [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> oressource = WMCElement ( '<STR_LIT>' ) <EOL> oressource . attrib [ <EOL> '<STR_LIT>' ] = '<STR_LIT>' <EOL> oressource . attrib [ <EOL> '<STR_LIT>' ] = self . _map . url <EOL> server . append ( oressource ) <EOL> layer . append ( server ) <EOL> e_name = WMCElement ( '<STR_LIT:Name>' ) <EOL> e_name . text = name <EOL> layer . append ( e_name ) <EOL> e_title = WMCElement ( '<STR_LIT>' ) <EOL> e_title . text = title <EOL> layer . append ( e_title ) <EOL> formatlist = WMCElement ( '<STR_LIT>' ) <EOL> format = WMCElement ( '<STR_LIT>' ) <EOL> format . attrib [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> format . text = self . _map . format <EOL> formatlist . append ( format ) <EOL> layer . append ( formatlist ) <EOL> layerlist . append ( layer ) <EOL> return layerlist <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> wmc_doc_tree = self . _getRootElement ( ) <EOL> wmc_doc_tree . append ( self . _getGeneralElement ( ) ) <EOL> wmc_doc_tree . append ( self . _getLayerListElement ( ) ) <EOL> return etree . tostring ( wmc_doc_tree ) <EOL> class AggregateMapContext ( MapContext ) : <EOL> """<STR_LIT>""" <EOL> def _getLayerListElement ( self ) : <EOL> layerlist = WMCElement ( '<STR_LIT>' ) <EOL> layer_infos = self . _map . getLayerInfos ( ) <EOL> layer = WMCElement ( '<STR_LIT>' ) <EOL> layer . attrib [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> layer . attrib [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> server = WMCElement ( '<STR_LIT>' ) <EOL> server . attrib [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> server . attrib [ '<STR_LIT:version>' ] = '<STR_LIT>' <EOL> server . attrib [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> oressource = WMCElement ( '<STR_LIT>' ) <EOL> oressource . attrib [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oressource . attrib [ '<STR_LIT>' ] = self . _map . url <EOL> server . append ( oressource ) <EOL> layer . append ( server ) <EOL> e_name = WMCElement ( '<STR_LIT:Name>' ) <EOL> e_name . text = '<STR_LIT:U+002C>' . join ( self . _map . layernames ) <EOL> layer . append ( e_name ) <EOL> e_title = WMCElement ( '<STR_LIT>' ) <EOL> e_title . text = '<STR_LIT>' <EOL> layer . append ( e_title ) <EOL> formatlist = WMCElement ( '<STR_LIT>' ) <EOL> format = WMCElement ( '<STR_LIT>' ) <EOL> format . attrib [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> format . text = self . _map . format <EOL> formatlist . append ( format ) <EOL> layer . append ( formatlist ) <EOL> layerlist . append ( layer ) <EOL> return layerlist <EOL> def mapToWebMapContext ( map , aggregate_layers = False ) : <EOL> """<STR_LIT>""" <EOL> if aggregate_layers : <EOL> return AggregateMapContext ( map ) ( ) <EOL> else : <EOL> return MapContext ( map ) ( ) </s>
