Skip to content

Commit

Permalink
Merge branch 'master' into api_refinements
Browse files Browse the repository at this point in the history
Conflicts:
	web/client/jsapi/MapStore2.js
	web/client/product/pluginsEmbedded.js
  • Loading branch information
mbarto committed Apr 7, 2017
2 parents cb381fe + f7437a4 commit fd4b0e5
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/geosolutions-it/MapStore2.svg?branch=master)](https://travis-ci.org/geosolutions-it/MapStore2)
[![Coverage Status](https://coveralls.io/repos/geosolutions-it/MapStore2/badge.svg?branch=master&service=github)](https://coveralls.io/github/geosolutions-it/MapStore2?branch=master)
[![Codacy Badge](https://www.codacy.com/project/badge/1648d484427346e2877006dc287379b6)](https://www.codacy.com/app/simone-giannecchini/MapStore2)
[![Inline docs](http://inch-ci.org/github/geosolutions-it/MapStore2.svg?branch=master)](http://inch-ci.org/github/geosolutions-it/MapStore2)
[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20%40mapstore2)](https://twitter.com/mapstore2)

MapStore 2
Expand Down
2 changes: 2 additions & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"framework" : [
"web/client/components/index.jsdoc",
"web/client/components/buttons/FullScreenButton.jsx",
"web/client/components/buttons/GoFullButton.jsx",
"web/client/components/mapcontrols/search/SearchBar.jsx",
"web/client/components/buttons/ToggleButton.jsx",

Expand All @@ -131,6 +132,7 @@
"plugins": [
"web/client/plugins/index.jsdoc",
"web/client/plugins/BackgroundSwitcher.jsx",
"web/client/plugins/GoFull.jsx",
"web/client/plugins/Map.jsx",
"web/client/plugins/FullScreen.jsx",
"web/client/plugins/Identify.jsx",
Expand Down
5 changes: 3 additions & 2 deletions web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const CHANGE_MAP_STYLE = 'CHANGE_MAP_STYLE';
const CHANGE_ROTATION = 'CHANGE_ROTATION';


function changeMapView(center, zoom, bbox, size, mapStateSource, projection) {
function changeMapView(center, zoom, bbox, size, mapStateSource, projection, viewerOptions) {
return {
type: CHANGE_MAP_VIEW,
center,
zoom,
bbox,
size,
mapStateSource,
projection
projection,
viewerOptions
};
}

Expand Down
4 changes: 3 additions & 1 deletion web/client/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
<script id="ms2-api" src="dist/ms2-api.js"></script>
<script type="text/javascript">
function init() {
MapStore2.create('container');
MapStore2.create('container', {
originalUrl: "./#viewer/leaflet/0"
});
}
</script>
</body>
Expand Down
76 changes: 76 additions & 0 deletions web/client/components/buttons/GoFullButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const React = require('react');

const {Button, Glyphicon, Tooltip} = require('react-bootstrap');
const OverlayTrigger = require('../misc/OverlayTrigger');
const Message = require('../I18N/Message');

const ConfigUtils = require('../../utils/ConfigUtils');
/**
* Button for Go to Full MapStore2.
* @prop {string} cfg.glyph the glyph icon for the button
* @prop {string} cfg.tooltip messageId of the tooltip to use
* @prop {string} cfg.urlRegex. A regex to parse the current location.href. This regex must match if the originalUrl is not defined.
* @prop {string} cfg.urlReplaceString. The template to create the url link. Uses the `urlRegex` groups to create the final URL
* @memberof components.buttons
* @class
*/
const GoFullButton = React.createClass({
propTypes: {
glyph: React.PropTypes.string,
tooltip: React.PropTypes.string,
urlRegex: React.PropTypes.string,
urlReplaceString: React.PropTypes.string,
originalUrl: React.PropTypes.string
},
getDefaultProps() {
return {
glyph: "share",
tooltip: "fullscreen.viewLargerMap",
urlRegex: "^(.*?)embedded.html.*?#\\/(\\d?)",
urlReplaceString: "$1#/viewer/leaflet/$2"
};
},

render() {
if (!this.display()) return null;
return (<OverlayTrigger placement="left" overlay={<Tooltip id="gofull-tooltip"><Message msgId={this.props.tooltip}/></Tooltip>}>
<Button className="square-button" bsStyle="primary" onClick={() => this.openFull(this.generateUrl())}>
<Glyphicon glyph={this.props.glyph}/>
</Button>
</OverlayTrigger>);
},
display() {
let regex = this.generateRegex();
return this.props.originalUrl || ConfigUtils.getConfigProp("originalUrl") || location.href.match(regex);
},
openFull(url) {
if (url) {
window.open(url, '_blank');
}
},
generateRegex() {
return new RegExp(this.props.urlRegex);
},

generateUrl() {
let orig = this.props.originalUrl || ConfigUtils.getConfigProp("originalUrl");
if (orig) {
return orig;
}
let regex = this.generateRegex();
if (location.href.match(regex)) {
let next = location.href;
return next.replace(regex, this.props.urlReplaceString);
}
}
});

module.exports = GoFullButton;
46 changes: 46 additions & 0 deletions web/client/components/buttons/__tests__/GoFullButton-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var expect = require('expect');

var React = require('react');
var ReactDOM = require('react-dom');
var GoFullButton = require('../GoFullButton');

describe("test the GoFullButton", () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});

afterEach((done) => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
setTimeout(done);
});

it('test not showing', () => {
const tb = ReactDOM.render(<GoFullButton/>, document.getElementById("container"));
expect(tb).toExist();
const tbNode = ReactDOM.findDOMNode(tb);
expect(tbNode).toNotExist();
});
it('test showing on originalUrl property set', () => {
const tb = ReactDOM.render(<GoFullButton originalUrl={"TEST"}/>, document.getElementById("container"));
expect(tb).toExist();
const tbNode = ReactDOM.findDOMNode(tb);
expect(tbNode).toExist();
});
it('test showing on regex match', () => {
const href = location.href;
const tb = ReactDOM.render(<GoFullButton urlRegex={"(.*)"} urlReplaceString={"$1"}/>, document.getElementById("container"));
expect(tb).toExist();
expect(tb.generateUrl()).toBe(href);
const tbNode = ReactDOM.findDOMNode(tb);
expect(tbNode).toExist();
});
});
36 changes: 23 additions & 13 deletions web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ let CesiumMap = React.createClass({
standardWidth: React.PropTypes.number,
standardHeight: React.PropTypes.number,
mousePointer: React.PropTypes.string,
zoomToHeight: React.PropTypes.number
zoomToHeight: React.PropTypes.number,
viewerOptions: React.PropTypes.object
},
getDefaultProps() {
return {
Expand All @@ -38,7 +39,12 @@ let CesiumMap = React.createClass({
mapOptions: {},
standardWidth: 512,
standardHeight: 512,
zoomToHeight: 80000000
zoomToHeight: 80000000,
viewerOptions: {
heading: 0,
pitch: -1 * Math.PI / 2,
roll: 0
}
};
},
getInitialState() {
Expand Down Expand Up @@ -190,26 +196,24 @@ let CesiumMap = React.createClass({
if (a === undefined || b === undefined) {
return false;
}
return ( a.toFixed(12) - (b.toFixed(12))) === 0;
// avoid errors like 44.40641479 !== 44.40641478999999
return ( a.toFixed(12) - (b.toFixed(12))) <= 0.000000000001;
};
const centerIsUpdate = isNearlyEqual(newProps.center.x, currentCenter.longitude) &&
isNearlyEqual(newProps.center.y, currentCenter.latitude);
const centerIsUpdate = !isNearlyEqual(newProps.center.x, currentCenter.longitude) ||
!isNearlyEqual(newProps.center.y, currentCenter.latitude);
const zoomChanged = newProps.zoom !== currentZoom;

// Do the change at the same time, to avoid glitches
if (centerIsUpdate || zoomChanged) {
this.map.camera.setView({
const position = {
destination: Cesium.Cartesian3.fromDegrees(
newProps.center.x,
newProps.center.y,
this.getHeightFromZoom(newProps.zoom)
),
orientation: {
heading: this.map.camera.heading,
pitch: this.map.camera.pitch,
roll: this.map.camera.roll
}
});
orientation: newProps.viewerOptions.orientation
};
this.map.camera.flyTo(position, {duration: 1});
}
},

Expand All @@ -234,7 +238,13 @@ let CesiumMap = React.createClass({
},
crs: 'EPSG:4326',
rotation: 0
}, size, this.props.id, this.props.projection );
}, size, this.props.id, this.props.projection, {
orientation: {
heading: this.map.camera.heading,
pitch: this.map.camera.pitch,
roll: this.map.camera.roll
}
});
}
});

Expand Down
3 changes: 2 additions & 1 deletion web/client/components/share/ShareApi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const ShareApi = React.createClass({
render() {
const parsedCode = codeApi
.replace('__BASE__URL__', this.props.shareUrl)
.replace('__CONFIG__URL__', this.props.shareConfigUrl);
.replace('__CONFIG__URL__', this.props.shareConfigUrl)
.replace('__ORIGINAL_URL__', location.href);
const tooltip = (<Tooltip placement="bottom" className="in" id="tooltip-bottom" style={{zIndex: 2001}}>
{this.state.copied ? <Message msgId="share.msgCopiedUrl"/> : <Message msgId="share.msgToCopyUrl"/>}
</Tooltip>);
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/share/api-template.raw
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<script type="text/javascript">
function init() {
MapStore2.create('container',{
configUrl: "__CONFIG__URL__"
configUrl: "__CONFIG__URL__",
originalUrl: "__ORIGINAL_URL__"
});
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ describe('search Epics', () => {

done();
// setting 0 as delay arises script error
}, 100);
}, 300);
});
});
4 changes: 4 additions & 0 deletions web/client/jsapi/MapStore2.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const MapStore2 = {
* look at [Plugins documentation](./plugins-documentation) for further details
* * **config**: map configuration object for the application (look at [Map Configuration](./maps-configuration) for details)
* * **configUrl**: map configuration url for the application (look at [Map Configuration](./maps-configuration) for details)
* * **originalUrl**: url of the original instance of MapStore. If present it will be linked inside the map using the "GoFull" plugin, present by default.
* * **initialState**: allows setting the initial application state (look at [State Configuration](./app-state-configuration) for details)
*
* Styling can be configured either using a **theme**, or a complete custom **less stylesheet**, using the
Expand Down Expand Up @@ -217,6 +218,9 @@ const MapStore2 = {
if (options.translations) {
ConfigUtils.setConfigProp('translationsPath', options.translations);
}
if (options.originalUrl) {
ConfigUtils.setConfigProp('originalUrl', options.originalUrl);
}
ReactDOM.render(<StandardApp onStoreInit={onStoreInit} themeCfg={themeCfg} className="fill" {...appConfig}/>, document.getElementById(container));
},
buildPluginsCfg,
Expand Down
9 changes: 8 additions & 1 deletion web/client/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,14 @@
}
}
},
"OmniBar"
"OmniBar", {
"name": "GoFull",
"override": {
"Toolbar": {
"alwaysVisible": true
}
}
}
],
"common": [{
"name": "OmniBar",
Expand Down
37 changes: 37 additions & 0 deletions web/client/plugins/GoFull.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const {connect} = require('react-redux');

/**
* GoFull plugin. Shows a button that opens full MapStore2 in a new tab. Try to find the `originalUrl` in configuration or tries to guess the mapId and creates the proper URL.
* This plugins hides automatically if the originalUrl is not present in configuration and if the urlRegex do not match.
* @prop {string} cfg.glyph the glyph icon for the button
* @prop {string} cfg.tooltip messageId of the tooltip to use
* @prop {string} cfg.urlRegex. A regex to parse the current location.href. This regex must match if the originalUrl is not defined.
* @prop {string} cfg.urlReplaceString. The template to create the url link. Uses the `urlRegex` groups to create the final URL
* @memberof plugins
* @class GoFull
*/
const GoFullPlugin = connect(() => ({}))(require('../components/buttons/GoFullButton'));

const assign = require('object-assign');


module.exports = {
GoFullPlugin: assign(GoFullPlugin, {
Toolbar: {
name: 'gofull',
position: 1,
toolStyle: "primary",
tooltip: "fullscreen.viewLargerMap",
tool: true,
priority: 1
}
}),
reducers: {}
};
2 changes: 1 addition & 1 deletion web/client/plugins/ZoomIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ module.exports = {
priority: 1
}
}),
reducers: { zoomIn: require("../reducers/map")}
reducers: {}
};
2 changes: 1 addition & 1 deletion web/client/plugins/ZoomOut.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ module.exports = {
priority: 1
}
}),
reducers: {zoomOut: require("../reducers/map")}
reducers: {}
};
1 change: 1 addition & 0 deletions web/client/product/apiPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
LocatePlugin: require('../plugins/Locate'),
ZoomAllPlugin: require('../plugins/ZoomAll'),
MapLoadingPlugin: require('../plugins/MapLoading'),
GoFullPlugin: require('../plugins/GoFull'),
OmniBarPlugin: require('../plugins/OmniBar')
},
requires: {
Expand Down
3 changes: 2 additions & 1 deletion web/client/product/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module.exports = {
FeatureGridPlugin: require('../plugins/FeatureGrid'),
TutorialPlugin: require('../plugins/Tutorial'),
ThemeSwitcherPlugin: require('../plugins/ThemeSwitcher'),
ScrollTopPlugin: require('../plugins/ScrollTop')
ScrollTopPlugin: require('../plugins/ScrollTop'),
GoFull: require('../plugins/GoFull')
},
requires: {
ReactSwipe: require('react-swipeable-views').default,
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.de-DE
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@
},
"fullscreen": {
"tooltipActivate": "Umschalten auf Vollbild",
"tooltipDeactivate": "Vollbild verlassen"
"tooltipDeactivate": "Vollbild verlassen",
"viewLargerMap": "Größere Karte ansehen"
},
"helptexts": {
"scaleBox": "Das ist die Hilfe für die ScaleBox",
Expand Down
Loading

0 comments on commit fd4b0e5

Please sign in to comment.