Skip to content

Commit

Permalink
Worked on demo page
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenplieger committed Feb 9, 2018
1 parent 675eed0 commit 1e02c29
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 146 deletions.
112 changes: 7 additions & 105 deletions src/components/ADAGUCViewerComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { getConfig } from '../getConfig';
import { debounce } from 'throttle-debounce';
import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, Alert, Card, CardText, CardBody, CardTitle, CardSubtitle } from 'reactstrap';
import Icon from 'react-fa';
import ReactWebMapJS from './ReactWebMapJS';


const WMJSTileRendererTileSettings = require('../../config/basemaps');
let config = getConfig();
console.log(config);

Expand Down Expand Up @@ -60,107 +61,6 @@ const mapTypeConfiguration = [
];


class ReactWebMapJS extends Component {
constructor (props) {
super(props);
this.webMapJSCreated = false;
this.resize = this.resize.bind(this);
this._handleWindowResize = this._handleWindowResize.bind(this);
}
_handleWindowResize () {
this.resize();
}
componentDidMount () {
if (this.webMapJSCreated) return;
this.webMapJSCreated = true;
this.webMapJS = new WMJSMap(this.refs.adagucwebmapjs);
this.webMapJS.setBaseURL('./adagucwebmapjs/');
this.webMapJS.setProjection({ srs:this.props.srs || 'EPSG:3857', bbox:this.props.bbox || [-19000000, -19000000, 19000000, 19000000] });
this.webMapJS.setWMJSTileRendererTileSettings(WMJSTileRendererTileSettings);
let baselayers = [
// new WMJSLayer({ 'name': 'OSM', type: 'twms' }),
new WMJSLayer({
service: config.backendHost + '/wms?dataset=baselayers&',
name:'baselayer',
format:'image/png',
title:'Basemap',
enabled: true,
keepOnTop:false
}),
new WMJSLayer({
service: config.backendHost + '/wms?dataset=baselayers&',
name:'overlay',
format:'image/png',
title:'World country borders',
enabled: true,
keepOnTop:true
})
];
console.log(baselayers);
this.webMapJS.setBaseLayers(baselayers);
if (this.props.layers.length > 0 && this.props.layers[0]) {
this.webMapJS.addLayer(this.props.layers[0]);
if (this.props.wmjsRegistry) {
this.props.wmjsRegistry(this.props.layers[0].name, this.webMapJS, true);
}
}

if (this.props.listeners) {
this.props.listeners.forEach((listener) => {
this.webMapJS.addListener(listener.name, (data) => { listener.callbackfunction(this.webMapJS, data); }, listener.keep);
});
}
this.resize();
this.webMapJS.draw();

window.addEventListener('resize', this._handleWindowResize);
}

componentWillUnMount () {
window.removeEventListener('resize', this._handleWindowResize);
if (this.props.wmjsRegistry) {
this.props.wmjsRegistry(this.props.layers[0].name, this.webMapJS, false);
}
}
resize () {
const element = this.refs.adaguccontainer;
if (element) {
this.webMapJS.setSize(element.clientWidth, element.clientHeight);
}
}
render () {
if (this.container) {
this.width = parseInt(this.container.clientWidth);
this.height = parseInt(this.container.clientHeight);
}

// console.log(this.refs.adaguccontainer.clientWidth);
// console.log('ReactWebMapJS render ', this.props);
return (<div className='ReactWebMapJS' ref={(container) => { this.container = container; }}
style={{ height:'100%', width:'100%', border:'none', display:'block', overflow:'hidden' }} >
<div ref='adaguccontainer' style={{
minWidth:'inherit',
minHeight:'inherit',
width: 'inherit',
height: 'inherit',
overflow: 'hidden',
display:'block',
border: 'none'
}}>
<div style={{ overflow: 'visible' }} >
<div ref='adagucwebmapjs' />
</div>
</div>
</div>);
}
};
ReactWebMapJS.propTypes = {
layers: PropTypes.array,
listeners: PropTypes.array,
bbox: PropTypes.object,
wmjsRegistry: PropTypes.func,
srs: PropTypes.string
};

export default class ADAGUCViewerComponent extends Component {
constructor (props) {
Expand Down Expand Up @@ -317,8 +217,10 @@ export default class ADAGUCViewerComponent extends Component {

render () {
const { title, error } = this.state;
console.log(this.state.wmsLayers);
console.log('layer0', this.state.wmsLayers[0]);
return (<div style={{ width:'100%' }}>
<Card body>

<CardBody>
{ title ? (<CardTitle>NetCDF file: {this.state.title}</CardTitle>) : null }
{ error ? (<Alert color='danger'>{this.state.error}</Alert>) : null }
Expand Down Expand Up @@ -365,7 +267,7 @@ export default class ADAGUCViewerComponent extends Component {
<CardBody>
<div style={{ width:'100%', height:'400px' }} >
<ReactWebMapJS
layers={[this.state.wmsLayers[0]]}
layers={this.state.wmsLayers}
listeners={this.listeners}
wmjsRegistry={(id, wmjs, appendOrRemove) => { if (appendOrRemove) this.wmjsRegistry[id] = wmjs; else delete this.wmjsRegistry[id]; }}
/>
Expand All @@ -374,7 +276,7 @@ export default class ADAGUCViewerComponent extends Component {
</Card>
}
</CardBody>
</Card>

</div>);
}
}
Expand Down
117 changes: 117 additions & 0 deletions src/components/ReactWebMapJS.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
const WMJSTileRendererTileSettings = require('../../config/basemaps');
export default class ReactWebMapJS extends Component {
constructor (props) {
super(props);
this.webMapJSCreated = false;
this.resize = this.resize.bind(this);
this._handleWindowResize = this._handleWindowResize.bind(this);
}
_handleWindowResize () {
this.resize();
}
componentDidUpdate () {
console.log('componentDidUpdate');
console.log('layers', this.props.layers);
if (this.props.layers && this.props.layers.length > 0 && this.props.layers[0]) {
this.webMapJS.removeAllLayers();
for (let j = 0;j < this.props.layers.length; j++) {
this.webMapJS.addLayer(this.props.layers[j]);
}
if (this.props.wmjsRegistry) {
this.props.wmjsRegistry(this.props.layers[0].name, this.webMapJS, true);
}
}
this.webMapJS.draw();
}
componentDidMount () {
console.log('componentDidMount');
if (this.webMapJSCreated) {
console.log('ok');
return;
}
this.webMapJSCreated = true;
this.webMapJS = new WMJSMap(this.refs.adagucwebmapjs);
this.webMapJS.setBaseURL('./adagucwebmapjs/');
this.webMapJS.setProjection({ srs:this.props.srs || 'EPSG:3857', bbox:this.props.bbox || [-19000000, -19000000, 19000000, 19000000] });
this.webMapJS.setWMJSTileRendererTileSettings(WMJSTileRendererTileSettings);
let baselayers = [
// new WMJSLayer({ 'name': 'OSM', type: 'twms' }),
new WMJSLayer({
service: config.backendHost + '/wms?dataset=baselayers&',
name:'baselayer',
format:'image/png',
title:'Basemap',
enabled: true,
keepOnTop:false
}),
new WMJSLayer({
service: config.backendHost + '/wms?dataset=baselayers&',
name:'overlay',
format:'image/png',
title:'World country borders',
enabled: true,
keepOnTop:true
})
];
console.log(baselayers);
this.webMapJS.setBaseLayers(baselayers);


if (this.props.listeners) {
this.props.listeners.forEach((listener) => {
this.webMapJS.addListener(listener.name, (data) => { listener.callbackfunction(this.webMapJS, data); }, listener.keep);
});
}
this.resize();
this.webMapJS.draw();

window.addEventListener('resize', this._handleWindowResize);
}

componentWillUnMount () {
window.removeEventListener('resize', this._handleWindowResize);
if (this.props.wmjsRegistry) {
this.props.wmjsRegistry(this.props.layers[0].name, this.webMapJS, false);
}
}
resize () {
const element = this.refs.adaguccontainer;
if (element) {
this.webMapJS.setSize(element.clientWidth, element.clientHeight);
}
}
render () {
if (this.container) {
this.width = parseInt(this.container.clientWidth);
this.height = parseInt(this.container.clientHeight);
}

// console.log(this.refs.adaguccontainer.clientWidth);
// console.log('ReactWebMapJS render ', this.props);
return (<div className='ReactWebMapJS' ref={(container) => { this.container = container; }}
style={{ height:'100%', width:'100%', border:'none', display:'block', overflow:'hidden' }} >
<div ref='adaguccontainer' style={{
minWidth:'inherit',
minHeight:'inherit',
width: 'inherit',
height: 'inherit',
overflow: 'hidden',
display:'block',
border: 'none'
}}>
<div style={{ overflow: 'visible' }} >
<div ref='adagucwebmapjs' />
</div>
</div>
</div>);
}
};
ReactWebMapJS.propTypes = {
layers: PropTypes.array,
listeners: PropTypes.array,
bbox: PropTypes.object,
wmjsRegistry: PropTypes.func,
srs: PropTypes.string
};
2 changes: 2 additions & 0 deletions src/components/WPSWranglerDemo.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import React, { Component } from 'react';
import ADAGUCViewerComponent from '../components/ADAGUCViewerComponent';
import PropTypes from 'prop-types';
import { Button, Input, ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem, Row, Col, Progress, Card } from 'reactstrap';

Expand Down Expand Up @@ -98,6 +99,7 @@ export default class WPSWranglerDemo extends Component {
return (
<div className='MainViewport'>
<h1>WPS Demo</h1>
<ADAGUCViewerComponent stacklayers={true} dapurl='https://localportal.c3s-magic.eu:9000/opendap/c0a5bcec-8db4-477f-930d-88923f6fe3eb/google.108664741257531327255/anomaly_agreement.nc' />
<Row>
<Col xs='2'><Input onChange={(event) => { this.handleChange('inputa', event.target.value); }} value={this.state.inputa} /></Col>
<Col xs='2'>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const createRoutes = (store) => {
<IndexRoute component={NavBarLayout} header={mainmenu} viewComponent={account} />
</Route>
<Route path='demo' title='Demo'>
<IndexRoute component={NavBarLayout} header={mainmenu} viewComponent={wpsdemo} />
<IndexRoute component={NavBarLayout} viewComponent={wpsdemo} />
</Route>
<Route path='basket' title='Basket'>
<IndexRoute component={NavBarLayout} header={mainmenu} viewComponent={basket} />
Expand Down
Loading

0 comments on commit 1e02c29

Please sign in to comment.