• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geographika / cpsi-mapview / 12356785512

16 Dec 2024 04:17PM UTC coverage: 26.211% (+2.1%) from 24.092%
12356785512

push

github

geographika
Disable SSL

487 of 2328 branches covered (20.92%)

Branch coverage included in aggregate %.

1445 of 5043 relevant lines covered (28.65%)

1.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.09
/app/controller/MapController.js
1
/**
2
 * This class is the controller for the map view of cpsi mapview
3
 *
4
 */
5
Ext.define('CpsiMapview.controller.MapController', {
1✔
6
    extend: 'Ext.app.ViewController',
7

8
    alias: 'controller.cmv_map',
9

10
    requires: [
11
        'BasiGX.util.Map'
12
    ],
13

14
    mixins: {
15
        editWindowOpenerMixin: 'CpsiMapview.util.EditWindowOpenerMixin'
16
    },
17

18
    /**
19
    * A configuration object to store settings relating to opening forms when clicking on a feature.
20
    * This should be overridden in inherited projects and should be in the following form:
21
    *
22
    * {
23
    *   layerKeyName: {
24
    *       keyField: 'ObjectId', // the field containing the unique feature Id to open in a form
25
    *       modelClass: 'CpsiMapview.model.ModelName', // the name of the class used to load a model
26
    *       editWindowClass: 'CpsiMapview.view.EditWindow' // the name of the form view class to open when clicking on a feature
27
    *   }
28
    * }
29
    *
30
    * You also use a function to return a configuration object which returns an Id instead of a
31
    * keyField which allows custom logic to be applied. The function receives a single argument which
32
    * is the clicked ol.Feature
33
    * {
34
    *   layerKeyName: function (feat) {
35
    *       return {
36
    *           id: Math.abs(feat.get('ObjectId')), // the unique feature Id to open in a form
37
    *           modelClass: 'CpsiMapview.model.ModelName', // the name of the class used to load a model
38
    *           editWindowClass: 'CpsiMapview.view.EditWindow' // the name of the form view class to open when clicking on a feature
39
    *       }
40
    *   }
41
    * }
42
    *
43
    * Multiple configurations can be provided to support clicks on multiple layers
44
    */
45
    clickableLayerConfigs: {},
46

47
    /**
48
     * Handle map clicks so data entry forms can be opened by clicking directly
49
     * on vector features
50
     * @param {any} clickedFeatures
51
     */
52
    onMapClick: function (clickedFeatures) {
53

54
        var feat, recId;
55
        var me = this;
×
56

57
        // Prevent triggering other map events, if we click on the coordinate marker
58
        var coordinateMousePanel = Ext.ComponentQuery.query('basigx-panel-coordinatemouseposition')[0];
×
59
        if (coordinateMousePanel) {
×
60
            var coordinateMarker = Ext.Array.findBy(clickedFeatures, function (clickedFeature) {
×
61
                return coordinateMousePanel.fireEvent('isMapMarker', clickedFeature.feature);
×
62
            });
63
            if (coordinateMarker) {
×
64
                coordinateMousePanel.fireEvent('removeMarker');
×
65
                return false;
×
66
            }
67
        }
68
        // avoid opening the form if another tool is active (see CpsiMapview.util.ApplicationMixin)
69
        var map = me.getView().map;
×
70
        if (map.get('defaultClickEnabled') === false) {
×
71
            return;
×
72
        }
73

74
        // filter out any features without the layer we want
75
        var editableFeatures = [];
×
76

77
        Ext.each(clickedFeatures, function (f) {
×
78
            if (f.layer) {
×
79
                var layerKey = f.layer.get('layerKey');
×
80
                if (Object.prototype.hasOwnProperty.call(me.clickableLayerConfigs, layerKey)) {
×
81
                    editableFeatures.push(f);
×
82
                }
83
            }
84
        });
85

86
        if (editableFeatures.length > 0) {
×
87
            var editableFeature = editableFeatures[0].feature; // get the first feature
×
88
            var selectedLayerKey = editableFeatures[0].layer.get('layerKey'); // get layer for feature
×
89

90
            var featureCluster = editableFeature.getProperties().features;
×
91

92
            if (featureCluster) {
×
93
                feat = featureCluster[0];
×
94
            } else {
95
                feat = editableFeature;
×
96
            }
97

98
            // get the window and model types
99
            var selectedLayerConfig = me.clickableLayerConfigs[selectedLayerKey];
×
100
            var modelClass, editWindowClass, configObject;
101

102
            if (typeof selectedLayerConfig === 'function') {
×
103
                configObject = selectedLayerConfig(feat) || {};
×
104
                recId = configObject.id;
×
105
            } else {
106
                configObject = selectedLayerConfig;
×
107
                recId = feat.get(configObject.keyField);
×
108
            }
109

110
            if (!recId) {
×
111
                // return early and stop other map handlers
112
                return false;
×
113
            }
114

115
            modelClass = configObject.modelClass;
×
116
            editWindowClass = configObject.editWindowClass;
×
117

118
            var modelPrototype = Ext.ClassManager.get(modelClass);
×
119

120
            // check if the window is already open
121
            var win = me.getExistingEditingFormWindow(recId, editWindowClass);
×
122

123
            // if the record is not already opened, create a new window and load the record
124
            if (win === null) {
×
125
                win = Ext.create(editWindowClass);
×
126
                modelPrototype.load(recId, {
×
127
                    success: function (rec) {
128
                        var vm = win.getViewModel();
×
129
                        vm.set('currentRecord', rec);
×
130
                        win.show();
×
131
                    },
132
                    failure: function () {
133
                        Ext.toast({
×
134
                            html: 'Cannot load the record with id ' + recId,
135
                            title: 'Record Loading Failed',
136
                            width: 200,
137
                            align: 'br'
138
                        });
139
                    }
140
                });
141
            } else {
142
                // if the window is minimised make sure it is restored
143
                if (win.isMinimized) {
×
144
                    win.show();
×
145
                }
146
                Ext.WindowManager.bringToFront(win);
×
147
            }
148

149
            return false; // stop other map handlers
×
150
        }
151
    },
152

153
    /**
154
     * Function called after render of map component
155
     */
156
    afterMapRender: function () {
157
        var me = this;
×
158
        var mapPanel = me.getView();
×
159

160
        if (mapPanel.addScaleBarToMap) {
×
161
            var removeCtrls = [];
×
162
            // Cleanup existing controls first
163
            mapPanel.olMap.getControls().forEach(function (ctrl) {
×
164
                if (ctrl instanceof ol.control.ScaleLine) {
×
165
                    removeCtrls.push(ctrl);
×
166
                }
167
            });
168
            Ext.each(removeCtrls, function (removeCtrl) {
×
169
                mapPanel.olMap.removeControl(removeCtrl);
×
170
            });
171

172
            var sbTarget = (mapPanel.body && mapPanel.body.dom) ?
×
173
                mapPanel.body.dom :
174
                mapPanel.getEl().dom;
175
            var scaleLineCtrl = new ol.control.ScaleLine({
×
176
                target: sbTarget
177
            });
178
            mapPanel.olMap.addControl(scaleLineCtrl);
×
179
        }
180
    }
181
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc