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

start on thumbnail implementation (WIP) #144

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/components/geonode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions src/services/geonode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
};
16 changes: 15 additions & 1 deletion src/state/map/actions.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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());
});
};
}