Editing

There is one special branch within HSLayers, which is not free and Open Source, but might be interesting. It contains vector editing functionalities, based on OpenLayers and UMN MapServer. It is not WFS-T, but proprietary.

Idea is: Identify one single object within the MapServer layer, it will be downloaded and displayed as vector object within the map. You can edit it or add new objects to it, after geometry is done, you can add/change attributes and afterwards, you can store everything to the server, so edit only one object at once.

There are also snapping settings, which enables the user to snap on server-deployed layers, displayed in the map as normal raster images.

For example see EditPanel example

The layer

Editing is binded to HSLayers.Layer.TreeLayer

Note

Why TreeLayer? Now, TreeLayer is based on MapServer layer. In the future it’s supposed to be able to handle WMS trees as well.

The TreeLayer must contain one sublayer, which is marked as editable. It also needs attribute, marking snapping layers (on the server):

...
linie2: {
    attribution: {
        title:MěÚ Turnov,
        href: "http://www.turnov.cz",
        logo: {
            href:http://gis.turnov.cz/hslayers/common/img/logo_turnov.gif,
            width:100,
            height:30,
            format:image/gif
        }
    },
    edit: {
        type:line,
        snapLayers:{
            parc_edit:Parcely
        }
    },
    isLayer: true,
    legendURL: "http://gis.turnov.cz/mapserv/hsmap/index.php?project=turnov_editace&mode=legend&layers=linie2&scale=2000",
    queryable: 1,
    title: "Editace - linie"
}
...

As you can see, edit structure contains: type of the data (line) and snapLayers structure with identifier:title format.

The MapServer layer (or HSLayers.Layer.TreeLayer) looks like this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
             var layer = new HSLayers.Layer.TreeLayer("Test editing",
                "http://dev.bnhelp.cz/mapserv/hsmap/index.php",
                {
                    project:"testedit",
                    layers:"linie body plochy",
                    transparent: true,
                    map_imagetype: "gif"
                },
                {
                    visibility:true, 
                    queryable:true,
                    saveWMC: false,
                    isBaseLayer: true,
                    buffer:2
                });

Service url, project and initial layers are most important configuration options.

The editing panel

HSLayers.EditPanel needs URL of the editing service, configuration for HSLayers.Control.Snapping control (url, and other parameteres) and some other attributes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
            editPanel = new HSLayers.EditPanel({
                height: 500,
                editorUrl: 'http://dev.bnhelp.cz/mapserv/hsmap/editor.php', 
                listeners: {
                            // deactivate all controls within all toolbars
                            // when editing is activated
                            "beforeLoadForm":function() {
                                for (var i = 0; i < geoportal.mapToolBar.controls.length; i++){
                                geoportal.mapToolBar.controls[i].deactivate()}
                            },
                            // deactivate editing when other tool is deactivatd
                            "deactivate": function(){
                                if (editPanel.editing) {
                                    editPanel.editing.deactivate();
                                    editPanel.editing.layer.setVisibility(false);
                                    map.removeControl(editPanel.editing);
                                    editPanel.editing.div = null;
                                }
                            },
                            // add editing panel and editing layer when the
                            // whole panel is activated
                            "activate": function(){
                                if (editPanel.editing) {
                                    map.addControl(editPanel.editing);
                                    editPanel.editing.layer.setVisibility(true);
                                }
                            },

                            // when feature is selected, clear content of the
                            // infoPanel
                            "featuredeleted": function(){
                                infoPanel.clearPanel();
                            }
                        },

                // use editing layer as base layer for the editing panel
                layer: layer,

                // add snapping options, which will be pased to
                // HSLayers.Control.Snapping
                snappingOptions: {
                        serverSnapScript: "http://dev.bnhelp.cz/mapserv/hsmap/snap.php",
                        units: "px",
                        snapParams:{
                            lyrs:"linie,body,plochy",
                            tol:10, 
                            active: true
                        }
                }
            });

Because of HSLayers.Control.Query tool, two handlers have to be defined, which are dealing with mouse clicks on edit and delete icons, when MapServer layer is queried.

            /* Call HSLayers.EditPanel.edit when 'edit' button is clicked in the query
             */
            HSLayers.Control.Editing.edit = function () {
                geoportal.toolsPanel.activate(3); // activate editPanel
                editPanel.edit.apply(editPanel,arguments); call it's edit method
            }

            /* Call HSLayers.EditPanel.deleteFeature when 'delete' button is clicked in the query
             */
            HSLayers.Control.Editing.deleteFeature = function () {
                editPanel.deleteFeature.apply(editPanel,arguments); 
            }

Main Menu


Table Of Contents

Previous topic

HSLayers.Layer.TreeLayer

Next topic

HSLayers.Permalink

This Page