Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 9e88a14

Browse files
authored
Merge pull request #161 from bartvde/baselayers
Take base layers from geonode settings
2 parents 89f8f2e + 1d68e5b commit 9e88a14

File tree

5 files changed

+14
-27
lines changed

5 files changed

+14
-27
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% load static %}
2-
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=default,Object.assign,URLSearchParams"></script>
2+
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=default,Object.assign"></script>
33
<script type="text/javascript" src="{% static 'geonode-client/js/composer.min.js' %}"></script>
44
<script type="text/javascript" src="{% static 'geonode-client/cesium/Cesium.js' %}"></script>

geonode-client/templates/geonode-client/map_new.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
tools: [{ptype: "gxp_getfeedfeatureinfo"}],
4848
};
4949
var config = Object.assign( defaultConfig, {{ config|safe }});
50-
var options = {baseUrl: "{{ GEOSERVER_BASE_URL }}", sources: config.sources, server: "{{SITEURL}}", wmsServer: "{{ GEOSERVER_BASE_URL }}ows/", layer: new URLSearchParams(window.location.search).get('layer')};
50+
var options = {mapConfig: config, baseUrl: "{{ GEOSERVER_BASE_URL }}", sources: config.sources, server: "{{SITEURL}}", wmsServer: "{{ GEOSERVER_BASE_URL }}ows/"};
5151
{% if user.is_authenticated %}
5252
options.userLoggedIn = true;
5353
{% endif %}

src/components/geonode.jsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ class GeoNodeViewer extends React.Component {
5454
constructor(props) {
5555
super(props);
5656
this.state = {
57+
tileServices: undefined,
5758
errors: [],
5859
errorOpen: false
5960
};
60-
this._local = getLocalGeoServer(props.sources, props.baseUrl);
61+
this._local = getLocalGeoServer(props.config.sources, props.baseUrl);
6162
}
6263
getChildContext() {
6364
return {
@@ -70,24 +71,19 @@ class GeoNodeViewer extends React.Component {
7071
this.updateMap(this.props);
7172
this.mode = this.props.mode || 'viewer';
7273
this.edit = (this.mode === 'composer');
73-
if (this.props.layer) {
74-
WMSService.createLayerFromGetCaps(this.props.wmsServer, this.props.layer, map.getView().getProjection(), function(layer) {
75-
map.addLayer(layer);
76-
map.getView().fit(ol.proj.transformExtent(layer.get('EX_GeographicBoundingBox'), 'EPSG:4326', map.getView().getProjection()), map.getSize(), {constrainResolution: false});
77-
}, this.props.proxy);
78-
}
7974
}
8075
componentWillReceiveProps(props) {
8176
this.updateMap(props);
8277
}
8378
updateMap(props) {
8479
if (props.config) {
80+
var tileServices = [];
8581
var errors = [];
8682
var filteredErrors = [];
8783
if (props.zoomToLayer && props.config.map.layers[props.config.map.layers.length - 1].bbox) {
8884
this._extent = props.config.map.layers[props.config.map.layers.length - 1].bbox;
8985
}
90-
MapConfigService.load(MapConfigTransformService.transform(props.config, errors), map, this.props.proxy);
86+
MapConfigService.load(MapConfigTransformService.transform(props.config, errors, tileServices), map, this.props.proxy);
9187
for (var i = 0, ii = errors.length; i < ii; ++i) {
9288
// ignore the empty baselayer since we have checkbox now for base layer group
9389
if (errors[i].layer.type !== 'OpenLayers.Layer') {
@@ -99,7 +95,8 @@ class GeoNodeViewer extends React.Component {
9995
}
10096
this.setState({
10197
errors: filteredErrors,
102-
errorOpen: true
98+
errorOpen: true,
99+
tileServices: tileServices
103100
});
104101
}
105102
}
@@ -152,7 +149,7 @@ class GeoNodeViewer extends React.Component {
152149
<div id='globe-button'><Globe tooltipPosition='right' map={map} /></div>
153150
<div id='print-button'><QGISPrint menu={false} map={map} layouts={this.props.printLayouts} /></div>
154151
<div id='home-button'><HomeButton extent={this._extent} tooltipPosition='right' map={map} /></div>
155-
<div><LayerList showZoomTo={true} addBaseMap={{tileServices: undefined}} addLayer={layerList} showTable={true} allowReordering={true} includeLegend={true} allowRemove={this.edit} tooltipPosition='left' allowStyling={this.edit || this.props.zoomToLayer} map={map} /></div>
152+
<div><LayerList showZoomTo={true} addBaseMap={{tileServices: this.state.tileServices}} addLayer={layerList} showTable={true} allowReordering={true} includeLegend={true} allowRemove={this.edit} tooltipPosition='left' allowStyling={this.edit || this.props.zoomToLayer} map={map} /></div>
156153
<div id='zoom-buttons'><Zoom tooltipPosition='right' map={map} /></div>
157154
<div id='rotate-button'><Rotate autoHide={true} tooltipPosition='right' map={map} /></div>
158155
<div id='popup' className='ol-popup'><InfoPopup toggleGroup='navigation' toolId='nav' infoFormat='application/vnd.ogc.gml' map={map} /></div>
@@ -165,13 +162,12 @@ class GeoNodeViewer extends React.Component {
165162

166163
GeoNodeViewer.props = {
167164
config: React.PropTypes.object,
165+
loadMapConfig: React.PropTypes.bool,
168166
proxy: React.PropTypes.string,
169167
theme: React.PropTypes.object,
170168
mode: React.PropTypes.string,
171169
server: React.PropTypes.string,
172-
printLayouts: React.PropTypes.array,
173-
wmsServer: React.PropTypes.string,
174-
layer: React.PropTypes.string
170+
printLayouts: React.PropTypes.array
175171
};
176172

177173
GeoNodeViewer.defaultProps = {

src/composer.jsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class Composer {
2222
this._checkLogin = options.checkLogin || false;
2323
this._printLayouts = options.printLayouts;
2424
this._theme = options.theme;
25-
this._layer = options.layer;
26-
this._wmsServer = options.wmsServer;
27-
this._sources = options.sources;
2825
this._baseUrl = options.baseUrl;
2926
}
3027
set server(value) {
@@ -45,19 +42,13 @@ class Composer {
4542
set theme(value) {
4643
this._theme = value;
4744
}
48-
set layer(value) {
49-
this._layer = value;
50-
}
51-
set wmsServer(value) {
52-
this._wmsServer = value;
53-
}
5445
compose() {
5546
store.dispatch(setServerUrl(this._server));
5647
store.dispatch(setMapId(this._mapId));
5748
store.dispatch(setMapConfig(this._mapConfig));
5849
store.dispatch(setCheckLogin(this._checkLogin));
5950
store.dispatch(setUserLoggedIn(this._userLoggedIn));
60-
ReactDOM.render(<Provider store={store}><IntlProvider locale='en' messages={enMessages}><GeonodeComposer baseUrl={this._baseUrl} sources={this._sources} theme={this._theme} wmsServer={this._wmsServer} layer={this._layer} printLayouts={this._printLayouts} mode='composer' config={this._mapConfig} proxy={this._proxy} /></IntlProvider></Provider>, document.getElementById(this._domId));
51+
ReactDOM.render(<Provider store={store}><IntlProvider locale='en' messages={enMessages}><GeonodeComposer baseUrl={this._baseUrl} theme={this._theme} printLayouts={this._printLayouts} mode='composer' config={this._mapConfig} proxy={this._proxy} /></IntlProvider></Provider>, document.getElementById(this._domId));
6152
}
6253
}
6354

tests/components/geonodeviewer.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ describe('GeoNodeViewer', () => {
122122
assert.deepEqual(wrapper.find(LayerList).prop('addLayer'),layerList);
123123
});
124124
it('as addLayer list', () => {
125-
const sources = {'0': { ptype: 'gxp_wmscsource', url: 'http://geonode.org?access_token=1', title: 'test'}}
125+
config.sources['0'] = {ptype: 'gxp_wmscsource', url: 'http://geonode.org?access_token=1', title: 'test'};
126126
const baseUrl = 'http://geonode.org'
127127
const layerList = {
128128
sources: [{title: 'test', url: 'http://geonode.org?access_token=1', type: 'WMS'}],
129129
allowUserInput: true
130130
};
131-
const wrapper = shallowWithIntl(<GeoNodeViewer mode='composer' sources={sources} baseUrl={baseUrl} config={config}/>, {});
131+
const wrapper = shallowWithIntl(<GeoNodeViewer mode='composer' baseUrl={baseUrl} config={config}/>, {});
132132
assert.deepEqual(wrapper.find(LayerList).prop('addLayer'),layerList);
133133
});
134134
});

0 commit comments

Comments
 (0)