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

geosolutions-it / MapStore2 / 13456178088

21 Feb 2025 11:49AM UTC coverage: 76.734% (+0.05%) from 76.688%
13456178088

Pull #10813

github

web-flow
Merge 7ffa6d126 into 1e493c5d2
Pull Request #10813: Fix #10805 JAXBException while updating an existing dashboard

31263 of 48901 branches covered (63.93%)

5 of 8 new or added lines in 2 files covered. (62.5%)

318 existing lines in 24 files now uncovered.

38808 of 50575 relevant lines covered (76.73%)

34.46 hits per line

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

96.88
/web/client/components/map/BaseMap.jsx
1
/*
2
 * Copyright 2018, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
 */
8
import React from 'react';
9

10
import PropTypes from 'prop-types';
11
import { isString } from 'lodash';
12
import { createVectorFeatureFilter } from '../../utils/FilterUtils';
13

14
/**
15
 * Base map component that renders a map.
16
 * It is implementation independent.
17
 * The implementation of the layer is provided by the `plugins` property
18
 * @prop {string} id the id of the map div
19
 * @prop {object} options. Options to pass to the map component (generically constant)
20
 * @prop {object} map the map properties (projection...) This is generically the dynamic part of the map options.
21
 * @prop {object[]} layers the layers to add to the map
22
 * @prop {object} plugins specific implementation of the components to render.
23
 * Must contain implementations for:
24
 *  - Map React component for Map
25
 *  - Layer React component for Layer
26
 *  - Feature (optional) React component for vector Feature
27
 *  - tools (optional) any support tool you want to use
28
 * @prop {array} tools. A list of tools (string name or object with `name` and other options as attribute) to add to the map.
29
 * @prop {object} eventHandlers handlers for map events
30
 * Each tool must be implemented in plugins.tools
31
 *
32
 */
33
class BaseMap extends React.Component {
34
    static propTypes = {
1✔
35
        id: PropTypes.string,
36
        options: PropTypes.object,
37
        map: PropTypes.object,
38
        mapStateSource: PropTypes.string,
39
        eventHandlers: PropTypes.object,
40
        styleMap: PropTypes.object,
41
        layers: PropTypes.array,
42
        hookRegister: PropTypes.object,
43
        projectionDefs: PropTypes.array,
44
        plugins: PropTypes.any,
45
        tools: PropTypes.array,
46
        getLayerProps: PropTypes.func,
47
        env: PropTypes.array,
48
        zoomControl: PropTypes.bool
49
    };
50

51
    static defaultProps = {
1✔
52
        id: '__base_map__',
53
        options: {},
54
        map: {},
55
        styleMap: {},
56
        tools: [],
57
        projectionDefs: [],
58
        eventHandlers: {
59
            onMapViewChanges: () => {},
60
            onClick: () => {},
61
            onMouseMove: () => {},
62
            onLayerLoading: () => {},
63
            onLayerError: () => {}
64
        },
65
        env: [],
66
        zoomControl: false
67
    };
68

69
    getTool = (tool) => {
37✔
70
        const { plugins } = this.props;
1✔
71
        if (isString(tool)) {
1!
72
            return {
1✔
73
                name: tool,
74
                impl: plugins.tools[tool]
75
            };
76
        }
UNCOV
77
        return {
×
78
            name: tool.name,
79
            impl: plugins.tools[tool.name],
80
            ...tool
81
        };
82
    };
83

84
    renderLayers = () => {
37✔
85
        const projection = this.props.map && this.props.map.projection || "EPSG:3857";
47✔
86
        const { plugins } = this.props;
47✔
87
        const { Layer } = plugins;
47✔
88
        return this.props.layers.map((layer, index) => {
47✔
89
            return (
78✔
90
                <Layer
91
                    type={layer.type}
92
                    srs={projection}
93
                    position={index}
94
                    key={layer.id || layer.name}
78!
95
                    options={layer}
96
                    env={layer.localizedLayerStyles ? this.props.env : []}
78!
97
                >
98
                    {this.renderLayerContent(layer, projection)}
99
                </Layer>
100
            );
101
        });
102
    };
103

104
    renderLayerContent = (layer, projection) => {
37✔
105
        if (layer.features && layer.type === "vector") {
78✔
106
            const { plugins } = this.props;
48✔
107
            const { Feature } = plugins;
48✔
108
            const vectorFeatureFilter = createVectorFeatureFilter(layer);
48✔
109
            return layer.features.filter(vectorFeatureFilter).map((feature) => {
48✔
110
                return (
22✔
111
                    <Feature
112
                        key={feature.id}
113
                        msId={feature.id}
114
                        type={feature.type}
115
                        crs={projection}
116
                        geometry={feature.geometry}
117
                        features={feature.features}
118
                        featuresCrs={layer.featuresCrs || 'EPSG:4326'}
44✔
119
                        // FEATURE STYLE OVERWRITE LAYER STYLE
120
                        layerStyle={layer.style}
121
                        style={feature.style || layer.style || null}
56✔
122
                        properties={feature.properties} />
123
                );
124
            });
125
        }
126
        return null;
30✔
127
    };
128

129
    renderTools = () => {
37✔
130
        return this.props.tools
47✔
131
            .filter((tool) => {
132
                return this.props?.plugins?.tools?.[isString(tool) ? tool : tool?.name];
1!
133
            })
134
            .map((tool) => {
135
                const {impl: Tool, name, ...options} = this.getTool(tool);
1✔
136
                return <Tool key={name} {...options} />;
1✔
137
            });
138
    };
139

140
    render() {
141
        const {plugins} = this.props;
84✔
142
        const {Map} = plugins;
84✔
143
        const projection = this.props.map && this.props.map.projection || "EPSG:3857";
84✔
144
        if (this.props.map && Map) {
84✔
145
            return (
47✔
146
                <Map
147
                    projectionDefs={this.props.projectionDefs}
148
                    style={this.props.styleMap}
149
                    id={this.props.id}
150
                    zoomControl={this.props.zoomControl}
151
                    center={{ x: 0, y: 0 }}
152
                    zoom={1}
153
                    hookRegister={this.props.hookRegister}
154
                    mapStateSource={this.props.mapStateSource || this.props.id}
94✔
155
                    {...this.props.options}
156
                    {...this.props.map}
157
                    projection={projection}
158
                    {...this.props.eventHandlers}
159
                >
160
                    {this.renderLayers()}
161
                    {this.renderTools()}
162
                    {this.props.children}
163
                </Map>
164
            );
165
        }
166
        return null;
37✔
167
    }
168
}
169

170

171
export default BaseMap;
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