diff --git a/package.json b/package.json index 42c6fe2..22232cd 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "test:lint": "eslint src --ext .jsx,.js", "test:unit": "NODE_ENV=test ./node_modules/karma/bin/karma start --browsers PhantomJS --auto-watch", "deploy": "npm run build:gh-pages && git-directory-deploy --directory _build --branch gh-pages", - "geonode:mkdir": "mkdir -p geonode-client/static && mkdir -p geonode-client/static/geonode-client && mkdir -p geonode-client/static/geonode-client/js && mkdir -p geonode-client/static/geonode-client/cesium", - "geonode:cp": "cp dist/Viewer.min.js geonode-client/static/geonode-client/js/viewer.min.js && cp dist/Composer.min.js geonode-client/static/geonode-client/js/composer.min.js && cp -R dist/cesium/* geonode-client/static/geonode-client/cesium/", - "geonode:deploy": "npm run geonode:mkdir && npm run geonode:cp" + "geonode:mkdir": "mkdir -p geonode-client/static && mkdir -p geonode-client/static/geonode-client && mkdir -p geonode-client/static/geonode-client/js && mkdir -p geonode-client/static/geonode-client/cesium", + "geonode:cp": "cp dist/Viewer.min.js geonode-client/static/geonode-client/js/viewer.min.js && cp dist/Composer.min.js geonode-client/static/geonode-client/js/composer.min.js && cp -R dist/cesium/* geonode-client/static/geonode-client/cesium/", + "geonode:deploy": "npm run geonode:mkdir && npm run geonode:cp" }, "main": "dist/viewer.js", "browser": "dist/viewer.js", @@ -36,16 +36,17 @@ "node": ">6" }, "dependencies": { - "react": "15.3.2", - "react-dom": "15.3.2", - "react-intl": "^2.1.5", - "react-tap-event-plugin": "1.0.0", "boundless-sdk": "^0.10.20", "material-ui": "0.16.4", "ol3-cesium": "3.9.4", "openlayers": "3.19.0", + "react": "15.3.2", + "react-dom": "15.3.2", + "react-intl": "^2.1.5", "react-redux": "^5.0.0", + "react-tap-event-plugin": "1.0.0", "redux-thunk": "^2.1.0", + "url-parse": "^1.1.7", "whatwg-fetch": "^1.0.0" }, "devDependencies": { diff --git a/src/components/geonode.jsx b/src/components/geonode.jsx index b7643e9..edc8499 100644 --- a/src/components/geonode.jsx +++ b/src/components/geonode.jsx @@ -26,7 +26,7 @@ global.enMessages = enMessages; import Save from './save'; import MapUrlLink from '../containers/MapUrlLink'; -import {getLocalGeoServer} from '../services/geonode'; +import {getLocalGeoServer, saveThumbnail} from '../services/geonode'; import '../css/app.css' import 'boundless-sdk/dist/css/components.css'; @@ -49,6 +49,10 @@ var map = new ol.Map({ view: new ol.View({center: [0, 0], zoom: 3}) }); +global.createMapThumbnail = function() { + saveThumbnail(map); +}; + class GeoNodeViewer extends React.Component { constructor(props) { super(props); diff --git a/src/services/geonode.js b/src/services/geonode.js index 265be79..0c0a302 100644 --- a/src/services/geonode.js +++ b/src/services/geonode.js @@ -2,6 +2,7 @@ import MapConfigTransformService from 'boundless-sdk/services/MapConfigTransform import MapConfigService from 'boundless-sdk/services/MapConfigService'; import {getCRSFToken, removeTrailingSlash} from '../helper'; import {edit_map_endpoint, NEW_MAP_ENDPOINT} from '../constants/server' +import URL from 'url-parse'; import 'whatwg-fetch'; @@ -57,3 +58,24 @@ export const getLocalGeoServer = (sources, baseUrl) => { } } }; +export const saveThumbnail = (map, opt_id) => { + let url = new URL(window.location.href); + if (opt_id !== undefined) { + url.set('pathname', url.pathname.replace('new', opt_id)); + } + map.once('postcompose', function(event) { + let canvas = event.context.canvas; + let data = canvas.toDataURL('image/png'); + let config = { + image: true, + data: data + }; + var request = createRequestObject('POST', JSON.stringify(config)); + var requestPath = removeTrailingSlash(url.pathname) + '/thumbnail'; + return fetch(requestPath,request) + .then(checkStatus) + .then((response) => response.json()) + .catch((ex) => Promise.reject(ex)); + }); + map.renderSync(); +}; diff --git a/src/state/map/actions.js b/src/state/map/actions.js index 570db58..5e08756 100644 --- a/src/state/map/actions.js +++ b/src/state/map/actions.js @@ -1,5 +1,5 @@ import * as types from '../actiontypes'; -import {saveToGeonode, login} from '../../services/geonode'; +import {saveToGeonode, login, saveThumbnail} from '../../services/geonode'; export function getId() { @@ -63,3 +63,17 @@ export function saveMap() { .catch(ex => dispatch(saveMapError(ex))); }; } +export function saveThumbnail() { + return (dispatch, getState) => { + let state = getState(); + return saveThumbnail(state.olMap, state.map.id); + }; +} +export function saveMapAndThumbnail() { + return (dispatch, getState) => { + return dispatch(saveMap()).then(() => { + let state = getState(); + return dispatch(saveThumbnail()); + }); + }; +}