Skip to content

Commit

Permalink
Optimized chunks size (geosolutions-it#748)
Browse files Browse the repository at this point in the history
* Fixes geosolutions-it#740: optimized chunks size

* Small fix

* Fixed never ending loop with locate button

* Better fix for neverending loop
  • Loading branch information
mbarto committed Jun 27, 2016
1 parent 88d2bbe commit c1a0dbb
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 332 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"babel-eslint": "4.1.8",
"babel-loader": "6.2.4",
"babel-plugin-add-module-exports": "0.1.4",
"babel-plugin-object-assign": "1.2.1",
"babel-plugin-react-transform": "2.0.2",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"babel-preset-stage-0": "6.5.0",
"babel-plugin-object-assign": "1.2.1",
"babel-plugin-react-transform": "2.0.2",
"css-loader": "0.19.0",
"download-cli": "1.0.1",
"escope": "3.2.0",
Expand Down Expand Up @@ -43,8 +43,8 @@
"mocha": "2.4.5",
"ncp": "2.0.0",
"parallelshell": "1.2.0",
"react-addons-test-utils": "0.14.8",
"react-addons-css-transition-group": "0.14.8",
"react-addons-test-utils": "0.14.8",
"react-hot-loader": "1.3.0",
"react-router": "2.4.0",
"react-router-redux": "2.1.0",
Expand All @@ -59,6 +59,7 @@
"style-loader": "0.12.4",
"url-loader": "0.5.7",
"webpack": "1.12.15",
"webpack-bundle-size-analyzer": "2.0.2",
"webpack-dev-server": "1.14.1"
},
"//": "replace react-sortable-items with official on npm when 0.0.10 with remove_deprecated PR in included",
Expand Down Expand Up @@ -129,6 +130,7 @@
"postinstall": "node checkCesium.js && mkdirp ./web/client/libs/Cesium && download --extract --out ./web/client/libs/Cesium https://cesiumjs.org/releases/Cesium-1.17.zip || echo Cesium already installed",
"clean": "rimraf ./web/client/dist",
"compile": "npm run clean && mkdirp ./web/client/dist && webpack --config prod-webpack.config.js",
"analyze": "npm run clean && mkdirp ./web/client/dist && webpack --json | webpack-bundle-size-analyzer",
"start": "webpack-dev-server --progress --colors --port 8081 --hot --inline --content-base web/client",
"examples": "webpack-dev-server --progress --colors --port 8081 --hot --inline --content-base web/client --config examples-webpack.config.js",
"test": "karma start ./karma.conf.single-run.js",
Expand Down
212 changes: 106 additions & 106 deletions web/client/api/CSW.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,131 +7,131 @@
*/
const axios = require('../libs/ajax');

const {CSW, marshaller, unmarshaller} = require('../utils/ogc/CSW');
const {Filter} = require('../utils/ogc/Filter');

const _ = require('lodash');


/**
* API for local config
*/
var Api = {
getRecords: function(url, startPosition, maxRecords, filter) {
let body = marshaller.marshalString({
name: "csw:GetRecords",
value: CSW.getRecords(startPosition, maxRecords, filter)
});
return axios.post(url, body, { headers: {
'Content-Type': 'application/xml'
}}).then(
(response) => {
if (response ) {
let json = unmarshaller.unmarshalString(response.data);
if (json && json.name && json.name.localPart === "GetRecordsResponse" && json.value && json.value.searchResults) {
let rawResult = json.value;
let rawRecords = rawResult.searchResults.abstractRecord || rawResult.searchResults.any;
let result = {
numberOfRecordsMatched: rawResult.searchResults.numberOfRecordsMatched,
numberOfRecordsReturned: rawResult.searchResults.numberOfRecordsReturned,
nextRecord: rawResult.searchResults.nextRecord
// searchStatus: rawResult.searchStatus
};
let records = [];
return new Promise((resolve) => {
require.ensure(['../utils/ogc/CSW', '../utils/ogc/Filter'], () => {
const {CSW, marshaller, unmarshaller} = require('../utils/ogc/CSW');

if (rawRecords) {
for (let i = 0; i < rawRecords.length; i++) {
let rawRec = rawRecords[i].value;
let obj = {
dateStamp: rawRec.dateStamp && rawRec.dateStamp.date,
fileIdentifier: rawRec.fileIdentifier && rawRec.fileIdentifier.characterString && rawRec.fileIdentifier.characterString.value,
identificationInfo: rawRec.abstractMDIdentification && rawRec.abstractMDIdentification.value
let body = marshaller.marshalString({
name: "csw:GetRecords",
value: CSW.getRecords(startPosition, maxRecords, filter)
});
resolve(axios.post(url, body, { headers: {
'Content-Type': 'application/xml'
}}).then(
(response) => {
if (response ) {
let json = unmarshaller.unmarshalString(response.data);
if (json && json.name && json.name.localPart === "GetRecordsResponse" && json.value && json.value.searchResults) {
let rawResult = json.value;
let rawRecords = rawResult.searchResults.abstractRecord || rawResult.searchResults.any;
let result = {
numberOfRecordsMatched: rawResult.searchResults.numberOfRecordsMatched,
numberOfRecordsReturned: rawResult.searchResults.numberOfRecordsReturned,
nextRecord: rawResult.searchResults.nextRecord
// searchStatus: rawResult.searchStatus
};
if (rawRec.boundingBox) {
let bbox;
let crs;
let el;
if (Array.isArray(rawRec.boundingBox)) {
el = _.head(rawRec.boundingBox);
} else {
el = rawRec.boundingBox;
}
if (el && el.value) {
let lc = el.value.lowerCorner;
let uc = el.value.upperCorner;
bbox = [lc[1], lc[0], uc[1], uc[0]];
// TODO parse the extent's crs
let crsCode = el.value.crs.split(":::")[1];
if (crsCode === "WGS 1984") {
crs = "EPSG:4326";
} else if (crsCode) {
// TODO check is valid EPSG code
crs = "EPSG:" + crsCode;
} else {
crs = "EPSG:4326";
}
}
obj.boundingBox = {
extent: bbox,
crs: crs
};

}
let dcElement = rawRec.dcElement;
if (dcElement) {
let dc = {
};
for (let j = 0; j < dcElement.length; j++) {
let dcel = dcElement[j];
let elName = dcel.name.localPart;
let finalEl = {};
/* Some services (e.g. GeoServer ) support http://schemas.opengis.net/csw/2.0.2/record.xsd only
* Usually they publish the WMS URL at dct:"references" with scheme=OGC:WMS
* So we place references as they are.
*/
if (elName === "references" && dcel.value) {
let urlString = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value;

finalEl = {
value: urlString,
scheme: dcel.value.scheme
let records = [];
if (rawRecords) {
for (let i = 0; i < rawRecords.length; i++) {
let rawRec = rawRecords[i].value;
let obj = {
dateStamp: rawRec.dateStamp && rawRec.dateStamp.date,
fileIdentifier: rawRec.fileIdentifier && rawRec.fileIdentifier.characterString && rawRec.fileIdentifier.characterString.value,
identificationInfo: rawRec.abstractMDIdentification && rawRec.abstractMDIdentification.value
};
if (rawRec.boundingBox) {
let bbox;
let crs;
let el;
if (Array.isArray(rawRec.boundingBox)) {
el = _.head(rawRec.boundingBox);
} else {
el = rawRec.boundingBox;
}
if (el && el.value) {
let lc = el.value.lowerCorner;
let uc = el.value.upperCorner;
bbox = [lc[1], lc[0], uc[1], uc[0]];
// TODO parse the extent's crs
let crsCode = el.value.crs.split(":::")[1];
if (crsCode === "WGS 1984") {
crs = "EPSG:4326";
} else if (crsCode) {
// TODO check is valid EPSG code
crs = "EPSG:" + crsCode;
} else {
crs = "EPSG:4326";
}
}
obj.boundingBox = {
extent: bbox,
crs: crs
};
} else {
finalEl = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value;
}

if (dc[elName] && Array.isArray(dc[elName])) {
dc[elName].push(finalEl);
} else if (dc[elName]) {
dc[elName] = [dc[elName], finalEl];
} else {
dc[elName] = finalEl;
let dcElement = rawRec.dcElement;
if (dcElement) {
let dc = {
};
for (let j = 0; j < dcElement.length; j++) {
let dcel = dcElement[j];
let elName = dcel.name.localPart;
let finalEl = {};
/* Some services (e.g. GeoServer ) support http://schemas.opengis.net/csw/2.0.2/record.xsd only
* Usually they publish the WMS URL at dct:"references" with scheme=OGC:WMS
* So we place references as they are.
*/
if (elName === "references" && dcel.value) {
let urlString = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value;
finalEl = {
value: urlString,
scheme: dcel.value.scheme
};
} else {
finalEl = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value;
}
if (dc[elName] && Array.isArray(dc[elName])) {
dc[elName].push(finalEl);
} else if (dc[elName]) {
dc[elName] = [dc[elName], finalEl];
} else {
dc[elName] = finalEl;
}
}
obj.dc = dc;
}
records.push(obj);
}
obj.dc = dc;

}
records.push(obj);

result.records = records;
return result;
}
}
result.records = records;
return result;
}
}
return null;

return null;
}));
});
});
},
textSearch: function(url, startPosition, maxRecords, text) {
// creates a request like this:
// <ogc:PropertyName>apiso:AnyText</ogc:PropertyName><ogc:Literal>%a%</ogc:Literal></ogc:PropertyIsLike>
let filter = null;
if (text) {
let ops = Filter.propertyIsLike("csw:AnyText", "%" + text + "%");
filter = Filter.filter(ops);
}
return Api.getRecords(url, startPosition, maxRecords, filter);
return new Promise((resolve) => {
require.ensure(['../utils/ogc/CSW', '../utils/ogc/Filter'], () => {
const {Filter} = require('../utils/ogc/Filter');
// creates a request like this:
// <ogc:PropertyName>apiso:AnyText</ogc:PropertyName><ogc:Literal>%a%</ogc:Literal></ogc:PropertyIsLike>
let filter = null;
if (text) {
let ops = Filter.propertyIsLike("csw:AnyText", "%" + text + "%");
filter = Filter.filter(ops);
}
resolve(Api.getRecords(url, startPosition, maxRecords, filter));
});
});
}
};

Expand Down
14 changes: 8 additions & 6 deletions web/client/components/mapcontrols/locate/LocateBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ var LocateBtn = React.createClass({
);
},
componentWillMount() {
// check if we are allowed to use geolocation feature
navigator.geolocation.getCurrentPosition(() => {}, (error) => {
if (error.code === 1) {
this.props.onClick("PERMISSION_DENIED");
}
});
if (this.props.locate !== 'PERMISSION_DENIED') {
// check if we are allowed to use geolocation feature
navigator.geolocation.getCurrentPosition(() => {}, (error) => {
if (error.code === 1) {
this.props.onClick("PERMISSION_DENIED");
}
});
}
},
render() {
var retval;
Expand Down
39 changes: 36 additions & 3 deletions web/client/components/plugins/PluginsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const React = require('react');

const PluginsUtils = require('../../utils/PluginsUtils');

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

const PluginsContainer = React.createClass({
propTypes: {
mode: React.PropTypes.string,
Expand All @@ -17,7 +19,8 @@ const PluginsContainer = React.createClass({
pluginsConfig: React.PropTypes.object,
id: React.PropTypes.string,
className: React.PropTypes.string,
style: React.PropTypes.object
style: React.PropTypes.object,
pluginsState: React.PropTypes.object
},
getDefaultProps() {
return {
Expand All @@ -27,17 +30,30 @@ const PluginsContainer = React.createClass({
pluginsConfig: {},
id: "plugins-container",
className: "plugins-container",
style: {}
style: {},
pluginsState: {}
};
},
getInitialState() {
return {
loadedPlugins: {}
};
},
componentWillMount() {
this.loadPlugins(this.props.pluginsState);
},
componentWillReceiveProps(newProps) {
this.loadPlugins(newProps.pluginsState);
},
getPluginDescriptor(plugin) {
return PluginsUtils.getPluginDescriptor(this.props.plugins,
this.props.pluginsConfig[this.props.mode], plugin);
this.props.pluginsConfig[this.props.mode], plugin, this.state.loadedPlugins);
},
renderPlugins(plugins) {
return plugins
.filter((Plugin) => !Plugin.hide)
.map(this.getPluginDescriptor)
.filter((Plugin) => !Plugin.impl.loadPlugin)
.map((Plugin) => <Plugin.impl key={Plugin.id}
{...this.props.params} {...Plugin.cfg} items={Plugin.items}/>);
},
Expand All @@ -50,6 +66,23 @@ const PluginsContainer = React.createClass({
);
}
return null;
},
loadPlugins(state) {
(this.props.pluginsConfig && this.props.pluginsConfig[this.props.mode] || [])
.map((plugin) => PluginsUtils.getPluginDescriptor(this.props.plugins,
this.props.pluginsConfig[this.props.mode], plugin, this.state.loadedPlugins))
.filter((plugin) => plugin.impl.loadPlugin).forEach((plugin) => {
if (!this.state.loadedPlugins[plugin.name]) {
if (!plugin.impl.enabler || plugin.impl.enabler(state)) {
plugin.impl.loadPlugin((impl) => this.loadPlugin(plugin, impl));
}
}
});
},
loadPlugin(plugin, impl) {
this.setState({
loadedPlugins: assign({}, this.state.loadedPlugins, {[plugin.name]: impl})
});
}
});

Expand Down
3 changes: 2 additions & 1 deletion web/client/containers/MapViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const ConfigUtils = require('../utils/ConfigUtils');

const PluginsContainer = connect((state) => ({
pluginsConfig: state.plugins || ConfigUtils.getConfigProp('plugins') || null,
mode: (urlQuery.mobile || (state.browser && state.browser.mobile)) ? 'mobile' : 'desktop'
mode: (urlQuery.mobile || (state.browser && state.browser.mobile)) ? 'mobile' : 'desktop',
pluginsState: state && state.controls || {}
}))(require('../components/plugins/PluginsContainer'));

const MapViewer = React.createClass({
Expand Down

0 comments on commit c1a0dbb

Please sign in to comment.