Changes between Version 9 and Version 10 of DeveloperGuidelines/GIS


Ignore:
Timestamp:
01/05/09 20:36:28 (13 years ago)
Author:
Fran Boon
Comment:

Updated for ,52

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/GIS

    v9 v10  
    1313
    1414== How to add a new Layer type ==
    15 
     15Assuming that !OpenLayers supports the layertype:
    1616=== Model ===
    1717{{{models/_gis.py}}}
    1818{{{
    1919gis_layer_types=['newlayertype','...']
    20 
    21 # Provide layer-specific options in it's own table:
    22 db.define_table('gis_layer_newlayertype',
    23                                 SQLField('modified_on','datetime',default=now),
    24                                 SQLField('layer',length=64),
    25                                 SQLField('newfield'))
    26 db.gis_layer_newlayertype.layer.requires=IS_IN_DB(db,'gis_layer.uuid','gis_layer.name')
     20gis_layer_newlayertype_subtypes=['Satellite','Maps','Hybrid']
     21# Base table from which the rest inherit
     22gis_layer=SQLTable(db,'gis_layer',
     23            db.Field('modified_on','datetime',default=now),
     24            #db.Field('uuid',length=64,default=uuid.uuid4()),   # Layers like OpenStreetMap, Google, etc shouldn't sync
     25            db.Field('name'),
     26            db.Field('description',length=256),
     27            #db.Field('priority','integer'),    # System default priority is set in ol_layers_all.js. User priorities are set in WMC.
     28            db.Field('enabled','boolean',default=True))
     29gis_layer.name.requires=IS_NOT_EMPTY()
     30for layertype in gis_layer_types:
     31    resource='layer_'+layertype
     32    table=module+'_'+resource
     33    title_create=T('Add Layer')
     34    title_display=T('Layer Details')
     35    title_list=T('List Layers')
     36    title_update=T('Edit Layer')
     37    subtitle_create=T('Add New Layer')
     38    subtitle_list=T('Layers')
     39    label_list_button=T('List Layers')
     40    label_create_button=T('Add Layer')
     41    msg_record_created=T('Layer added')
     42    msg_record_modified=T('Layer updated')
     43    msg_record_deleted=T('Layer deleted')
     44    msg_list_empty=T('No Layers currently defined')
     45    # Create Type-specific Layer tables
     46    if layertype=="newlayertype":
     47        t=SQLTable(db,table,
     48            db.Field('subtype'),
     49            gis_layer)
     50        t.subtype.requires=IS_IN_SET(gis_layer_newlayertype_subtypes)
     51        db.define_table(table,t)
     52        db['%s' % table].represent=lambda table:shn_list_item(table,resource='layer_newlayertype',action='display',extra=str(table.enabled))
     53        if not len(db().select(db['%s' % table].ALL)):
     54            # Populate table
     55            for subtype in gis_layer_newlayertype_subtypes:
     56                db['%s' % table].insert(
     57                        name='New Layer Type '+subtype,
     58                        subtype=subtype
     59                    )
     60        # Customise CRUD strings if-desired
     61        msg_list_empty=T('No New Layer Type Layers currently defined')
     62        exec('crud_strings.%s=Storage(title_create=title_create, title_display=title_display, title_list=title_list, title_update=title_update, subtitle_create=subtitle_create, subtitle_list=subtitle_list, label_list_button=label_list_button, label_create_button=label_create_button, msg_record_created=msg_record_created, msg_record_modified=msg_record_modified, msg_record_deleted=msg_record_deleted, msg_list_empty=msg_list_empty)' % resource)
    2763}}}
    2864
    2965=== Controller ===
    30 New Layer Types & their Fields need adding to several places in the Controller:[[BR]]
     66New Layer Types & their Fields need adding to 2 places in the Controller:[[BR]]
    3167{{{controllers/gis.py}}}
    3268{{{
    33 def layer():
    34     # Display method
    35     elif type=="newlayertype":
    36         newfield=db(db['gis_layer_%s' % type].layer==t2.id).select(db['gis_layer_%s' % type].ALL)[0].newfield
     69def layer_newlayertype():
     70    "RESTlike CRUD controller"
     71    return shn_rest_controller(module,'layer_newlayertype')
    3772
    38 def shn_gis_create_layer():
    39     customform=FORM(
    40             INPUT(_name="newfield"),
    41     elif type_new=="newlayertype":
    42         db['gis_layer_%s' % type_new].insert(
    43             layer=id,
    44             newfield=customform.vars.newfield
    45         )
     73def map_viewing_client():
     74newlayertype=Storage()
     75    layers_newlayertype=db(db.gis_layer_newlayertype.enabled==True).select(db.gis_layer_newlayertype.ALL)
     76    for layer in layers_newlayertype:
     77        for subtype in gis_layer_newlayertype_subtypes:
     78            if layer.subtype==subtype:
     79                newlayertype['%s' % subtype]=layer.name
     80   
     81    # Add the Layers to the Return
     82    output.update(dict(newlayertype=newlayertype))
     83}}}
     84Note that these functions are now deprecated as of [changeset:,52]:
     85 * {{{layer()}}}
     86 * {{{shn_gis_create_layer()}}}
     87 * {{{shn_gis_update_layer()}}}
    4688
    47 def shn_gis_update_layer():
    48     elif type=="newlayertype":
    49         newfield=db(db['gis_layer_%s' % type].layer==t2.id).select(db['gis_layer_%s' % type].ALL)[0].newfield
    50     customform=FORM(
    51             INPUT(_name="newfield"),
    52     elif type_new=="newlayertype":
    53         db['gis_layer_%s' % type_new].insert(
    54             layer=id,
    55             newfield=customform.vars.newfield
    56         )
    57 }}}
    58 If loading custom JS files when the new Layer is active:
    59 {{{
    60 def map_viewing_client():
    61     # Check for enabled Virtual Earth layers
    62     virtualearth=0
    63     for row in layers:
    64         if row.type=="virtualearth":
    65             virtualearth=1
    66     return dict(virtualearth=virtualearth)
    67 }}}
    6889=== View ===
    69 Custom fields need form views creating:[[BR]]
    70 {{{views/gis/form_field.html}}}
    71 {{{
    72 <tr><td><label>{{=T("field_label")}}</label></td>
    73 <td><input name="field" type="text" value="{{try:}}{{=resource.field}}{{except:}}{{pass}}" />
    74 {{if customform.errors.field:}}<div class="error">{{=customform.errors.field}}</div>{{pass}}</td></tr>
    75 }}}
    76 Then adding to the layer CRUD views, such as {{{views/gis/update_layer.html}}}:
    77 {{{
    78 {{include 'gis/form_field.html'}}
    79 }}}
    80 {{{static/scripts/gis_layers.js}}}
    81 {{{
    82 } else if (type=="newlayertype") {
    83         var fields_hide=["key"];
    84 
    85 } else if (type=="newlayertype") {
    86             var fields_hide=["subtype","key"];
    87             var fields_show=["field"];
    88 }}}
    8990{{{views/gis/ol_layers_all.js}}}
    9091{{{
    91 {{elif layer.type=="newlayertype":}}
    92     var newlayertype = new OpenLayers.Layer.newlayertype( "{{=layer.name}}" );
    93     map.addLayer(newlayertype);
     92{{if newlayertype:}}
     93    {{include 'gis/ol_layers_newlayertype.js'}}
     94{{pass}}
     95}}}
     96{{{views/gis/ol_layers_newlayertype.js}}}
     97{{{
     98{{if newlayertype.Satellite:}}
     99    var newlayertypesat = new OpenLayers.Layer.NewLayerType( "{{=newlayertype.Satellite}}" , {type: NewLayerType.Aerial, 'sphericalMercator': true } );
     100    map.addLayer(newlayertypesat);
    94101{{pass}}
    95102}}}
     
    101108{{pass}}
    102109}}}
     110Note that these files are now deprecated as of [changeset:,52]:
     111 * {{{views/gis/form_*.html}}}
     112 * {{{views/gis/create_layer.html}}}:
     113 * {{{views/gis/list_create_layer.html}}}:
     114 * {{{views/gis/update_layer.html}}}:
     115 * {{{static/scripts/gis_layers.js}}}
    103116----
    104117DeveloperGuidelines