2006-03-31 10:32:02 +00:00
/*****************************************************************************
*
* This file is part of Mapnik ( c + + mapping toolkit )
2006-01-31 23:09:52 +00:00
*
2006-03-31 10:32:02 +00:00
* Copyright ( C ) 2006 Artem Pavlenko , Jean - Francois Doyon
2006-01-31 23:09:52 +00:00
*
2006-03-31 10:32:02 +00:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
2006-01-31 23:09:52 +00:00
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2006-03-31 10:32:02 +00:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
2006-01-31 23:09:52 +00:00
*
2006-03-31 10:32:02 +00:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-01-31 23:09:52 +00:00
//$Id: mapnik_layer.cc 17 2005-03-08 23:58:43Z pavlenko $
# include <boost/python.hpp>
# include <boost/python/detail/api_placeholder.hpp>
# include <boost/python/suite/indexing/vector_indexing_suite.hpp>
# include <mapnik.hpp>
using mapnik : : Layer ;
using mapnik : : parameters ;
struct layer_pickle_suite : boost : : python : : pickle_suite
{
static boost : : python : : tuple
getinitargs ( const Layer & l )
{
using namespace boost : : python ;
return boost : : python : : make_tuple ( l . params ( ) ) ;
}
static boost : : python : : tuple
getstate ( const Layer & l )
{
using namespace boost : : python ;
std : : vector < std : : string > const & styles = l . styles ( ) ;
std : : vector < std : : string > : : const_iterator itr = styles . begin ( ) ;
boost : : python : : list py_styles ;
while ( itr ! = styles . end ( ) )
{
py_styles . append ( * itr + + ) ;
}
return boost : : python : : make_tuple ( l . getMinZoom ( ) ,
l . getMaxZoom ( ) ,
py_styles ) ;
}
static void
setstate ( Layer & l , boost : : python : : tuple state )
{
using namespace boost : : python ;
if ( len ( state ) ! = 3 )
{
PyErr_SetObject ( PyExc_ValueError ,
( " expected 3-item tuple in call to __setstate__; got %s "
% state ) . ptr ( )
) ;
throw_error_already_set ( ) ;
}
l . setMinZoom ( extract < double > ( state [ 0 ] ) ) ;
l . setMaxZoom ( extract < double > ( state [ 1 ] ) ) ;
boost : : python : : list styles = extract < boost : : python : : list > ( state [ 2 ] ) ;
for ( int i = 0 ; i < len ( styles ) ; + + i )
{
l . add_style ( extract < std : : string > ( styles [ i ] ) ) ;
}
}
} ;
namespace
{
2006-03-01 15:15:37 +00:00
//user-friendly wrapper that uses Python dictionary
2006-01-31 23:09:52 +00:00
using namespace boost : : python ;
2006-03-01 15:34:23 +00:00
Layer create_layer ( const dict & d )
2006-01-31 23:09:52 +00:00
{
parameters params ;
2006-03-01 15:15:37 +00:00
boost : : python : : list keys = d . keys ( ) ;
for ( int i = 0 ; i < len ( keys ) ; + + i )
{
std : : string key = extract < std : : string > ( keys [ i ] ) ;
std : : string value = extract < std : : string > ( d [ key ] ) ;
params [ key ] = value ;
}
2006-01-31 23:09:52 +00:00
return Layer ( params ) ;
}
}
void export_layer ( )
{
using namespace boost : : python ;
2006-02-20 01:34:02 +00:00
class_ < std : : vector < std : : string > > ( " Styles " )
2006-01-31 23:09:52 +00:00
. def ( vector_indexing_suite < std : : vector < std : : string > , true > ( ) )
;
2006-02-25 11:03:30 +00:00
2006-02-26 21:47:35 +00:00
class_ < Layer > ( " Layer " , " A map layer. " , no_init )
2006-03-22 00:13:14 +00:00
. def ( " name " , & Layer : : name , return_value_policy < copy_const_reference > ( ) , " Return the name of the layer. " )
2006-05-22 17:00:35 +00:00
. def ( " title " , & Layer : : title , return_value_policy < copy_const_reference > ( ) , " Return the title of the layer. " )
. def ( " abstract " , & Layer : : abstract , return_value_policy < copy_const_reference > ( ) , " Return the abstract of the layer. " )
2006-03-28 01:01:00 +00:00
. def ( " params " , & Layer : : params , return_value_policy < reference_existing_object > ( ) , " The configuration parameters of the layer. These vary depending on the type of data source. " )
2006-03-22 00:13:14 +00:00
. def ( " envelope " , & Layer : : envelope , " Return the geographic envelope/bounding box of the data in the layer. " )
2006-01-31 23:09:52 +00:00
. add_property ( " minzoom " , & Layer : : getMinZoom , & Layer : : setMinZoom )
. add_property ( " maxzoom " , & Layer : : getMaxZoom , & Layer : : setMaxZoom )
. add_property ( " styles " , make_function
( & Layer : : styles , return_value_policy < reference_existing_object > ( ) ) )
. def_pickle ( layer_pickle_suite ( ) )
;
2006-03-01 15:34:23 +00:00
def ( " CreateLayer " , & create_layer ) ;
2006-01-31 23:09:52 +00:00
}