Version 9 (modified by 16 years ago) ( diff ) | ,
---|
GIS Module
OpenLayers
The GIS module uses OpenLayers for Display purposes, so a thorough understanding of this is a great foundation for what we do:
- http://trac.openlayers.org/wiki/Documentation#BeforeGettingStarted--TheTechnologiesBehindOpenLayers
- http://trac.openlayers.org/wiki/NewToOpenLayers
MapFish
The map window is wrapped in an Ext GUI based on MapFish client:
How to add a new Layer type
Model
models/_gis.py
gis_layer_types=['newlayertype','...'] # Provide layer-specific options in it's own table: db.define_table('gis_layer_newlayertype', SQLField('modified_on','datetime',default=now), SQLField('layer',length=64), SQLField('newfield')) db.gis_layer_newlayertype.layer.requires=IS_IN_DB(db,'gis_layer.uuid','gis_layer.name')
Controller
New Layer Types & their Fields need adding to several places in the Controller:
controllers/gis.py
def layer(): # Display method elif type=="newlayertype": newfield=db(db['gis_layer_%s' % type].layer==t2.id).select(db['gis_layer_%s' % type].ALL)[0].newfield def shn_gis_create_layer(): customform=FORM( INPUT(_name="newfield"), elif type_new=="newlayertype": db['gis_layer_%s' % type_new].insert( layer=id, newfield=customform.vars.newfield ) def shn_gis_update_layer(): elif type=="newlayertype": newfield=db(db['gis_layer_%s' % type].layer==t2.id).select(db['gis_layer_%s' % type].ALL)[0].newfield customform=FORM( INPUT(_name="newfield"), elif type_new=="newlayertype": db['gis_layer_%s' % type_new].insert( layer=id, newfield=customform.vars.newfield )
If loading custom JS files when the new Layer is active:
def map_viewing_client(): # Check for enabled Virtual Earth layers virtualearth=0 for row in layers: if row.type=="virtualearth": virtualearth=1 return dict(virtualearth=virtualearth)
View
Custom fields need form views creating:
views/gis/form_field.html
<tr><td><label>{{=T("field_label")}}</label></td> <td><input name="field" type="text" value="{{try:}}{{=resource.field}}{{except:}}{{pass}}" /> {{if customform.errors.field:}}<div class="error">{{=customform.errors.field}}</div>{{pass}}</td></tr>
Then adding to the layer CRUD views, such as views/gis/update_layer.html
:
{{include 'gis/form_field.html'}}
static/scripts/gis_layers.js
} else if (type=="newlayertype") { var fields_hide=["key"]; } else if (type=="newlayertype") { var fields_hide=["subtype","key"]; var fields_show=["field"];
views/gis/ol_layers_all.js
{{elif layer.type=="newlayertype":}} var newlayertype = new OpenLayers.Layer.newlayertype( "{{=layer.name}}" ); map.addLayer(newlayertype); {{pass}}
If loading custom JS files when the new Layer is active:
views/gis/ol_js_loaders.html
{{if virtualearth:}} <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script> {{pass}}