forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alessio Fabiani
committed
Feb 22, 2018
0 parents
commit e6c2967
Showing
480 changed files
with
37,558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules/ | ||
build/ | ||
_build/ | ||
*.swp | ||
geonode_mapstore_client/static/geonode_mapstore_client | ||
dist/ | ||
.tmp | ||
coverage/ | ||
reports/ | ||
django_geonode_mapstore_client.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mapstore2.geo-solutions.it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2015-2018, GeoSolutions Sas | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of | ||
conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
of conditions and the following disclaimer in the documentation and/or other materials | ||
provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
The views and conclusions contained in the software and documentation are those | ||
of the authors and should not be interpreted as representing official policies, | ||
either expressed or implied, of the MapStore2 Project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include README.md | ||
include VERSION | ||
recursive-include geonode-mapstore-client/static * | ||
recursive-include geonode-mapstore-client/templates *.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FILE=VERSION | ||
VERSION=`cat $(FILE)` | ||
|
||
.PHONY: build geonode package release | ||
|
||
build: | ||
npm run dist | ||
|
||
geonode: build | ||
npm run geonode:deploy | ||
|
||
package: geonode | ||
python setup.py sdist bdist_wheel | ||
|
||
release: package | ||
twine upload dist/django-geonode-mapstore-client-$(VERSION).tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# geonode-client [](https://travis-ci.org/GeoNode/geonode-mapstore-client) [](https://codeclimate.com/github/GeoNode/geonode-viewer) [](https://codeclimate.com/github/GeoNode/geonode-mapstore-client/coverage) | ||
|
||
MapStore - React map viewer for GeoNode | ||
|
||
## Installation | ||
|
||
Install `node` and `npm`. We would encourage you to use [nvm](https://github.com/creationix/nvm) a version manager for node. | ||
|
||
You need `node > 5` | ||
|
||
Run `npm install` to install all dependencies. | ||
|
||
## Development Server | ||
|
||
Run `npm start` to start the development server. Visit your browser at `http://localhost:8080` to see the result. | ||
|
||
## Testing | ||
|
||
During development run `npm run test:watch` to run tests on every file change. | ||
|
||
Run `npm test` to run the full test suite with code coverage report. | ||
|
||
## Building | ||
|
||
Building is done via webpack and the command is `npm build` | ||
The dist folder is where the minified versions of these files are stored. | ||
|
||
## Deployment to GH-pages | ||
|
||
Automated deployment via travis is enabled for the master branch. | ||
|
||
If you want to deploy manually to gh-pages use `npm run deploy` | ||
|
||
### Important | ||
The deplyoment uses the `index-gh.html` please keep this file in sync with `index.html` and change the path once the repo changes it's name. The `.travis.yml` needs to be changed as well. | ||
|
||
## Integrating into GeoNode/Django | ||
|
||
Add `django-geonode-mapstore-client` to your requirements.txt | ||
Add `geonode-mapstore-client` to your `INSTALLED_APPS` | ||
|
||
### For GeoNode | ||
@DEPRECATED | ||
Change the `LAYER_PREVIEW_LIBRARY` to `mapstore2` | ||
|
||
### For Django | ||
We added templatetags you can use in your templates | ||
|
||
Add `{% client_viewer_js %}` to include the viewer javasricpt | ||
Add `{% client_composer_js %}` to include the composer javasricpt | ||
|
||
The following templates are available: | ||
`client_map_view_html` for the full map view | ||
`client_map_detail_view_html` for a smaller map view (as in the map preview) | ||
`client_map_new_html` create a new map with composer | ||
`client_layer_map_html` smaller map view for the layer preview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
######################################################################### | ||
# | ||
# Copyright 2015-2018, 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. | ||
# | ||
######################################################################### |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
# -*- coding: utf-8 -*- | ||
######################################################################### | ||
# | ||
# Copyright 2015-2018, 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. | ||
# | ||
######################################################################### | ||
import json | ||
import math | ||
import logging | ||
import traceback | ||
|
||
from .utils import GoogleZoom | ||
from .settings import (MAP_BASELAYERS, | ||
GEONODE_CATALOGUE_SERVICE, | ||
CATALOGUE_SERVICES, | ||
CATALOGUE_SELECTED_SERVICE) | ||
|
||
from django.core.serializers.json import DjangoJSONEncoder | ||
|
||
from django.contrib.gis.geos import Polygon | ||
from django.contrib.gis.gdal import SpatialReference, CoordTransform | ||
|
||
logger = logging.getLogger("geonode_mapstore_client.converters") | ||
|
||
|
||
class MapStore2GeoExtConfigConverter(object): | ||
|
||
def convert(self, viewer, request): | ||
data = {} | ||
data['version'] = 2 | ||
data['widgetsConfig'] = {} # TODO | ||
|
||
try: | ||
viewer_obj = json.loads(viewer) | ||
|
||
# Map Definition | ||
ms2_map = {} | ||
ms2_map['projection'] = viewer_obj['map']['projection'] | ||
ms2_map['units'] = viewer_obj['map']['units'] | ||
ms2_map['zoom'] = viewer_obj['map']['zoom'] | ||
ms2_map['maxExtent'] = viewer_obj['map']['maxExtent'] | ||
ms2_map['maxResolution'] = viewer_obj['map']['maxResolution'] | ||
|
||
# Backgrouns | ||
ms2_map['layers'] = MAP_BASELAYERS + [ | ||
# TODO: covnert Viewer Backgroun Layers | ||
# Add here more backgrounds e.g.: | ||
# { | ||
# "type": "wms", | ||
# "url": "https://demo.geo-solutions.it/geoserver/wms", | ||
# "visibility": True, | ||
# "opacity": 0.5, | ||
# "title": "Weather data", | ||
# "name": "nurc:Arc_Sample", | ||
# "group": "Meteo", | ||
# "format": "image/png", | ||
# "bbox": { | ||
# "bounds": { | ||
# "minx": -25.6640625, | ||
# "miny": 26.194876675795218, | ||
# "maxx": 48.1640625, | ||
# "maxy": 56.80087831233043 | ||
# }, | ||
# "crs": "EPSG:4326" | ||
# } | ||
# }, ... | ||
] | ||
|
||
# Overlays | ||
overlays, selected = self.get_overlays(viewer) | ||
|
||
if selected: | ||
center, zoom = self.get_center_and_zoom(viewer_obj['map'], selected) | ||
ms2_map['center'] = center | ||
ms2_map['zoom'] = zoom | ||
else: | ||
ms2_map['center'] = { | ||
"x": self.get_valid_number(viewer_obj['map']['center'][0]), | ||
"y": self.get_valid_number(viewer_obj['map']['center'][1]), | ||
"crs": viewer_obj['map']['projection'] | ||
} | ||
|
||
for overlay in overlays: | ||
ms2_map['layers'].append(overlay) | ||
|
||
data['map'] = ms2_map | ||
|
||
# Catalogue Services Definition | ||
ms2_catalogue = {} | ||
ms2_catalogue['selectedService'] = CATALOGUE_SELECTED_SERVICE | ||
if GEONODE_CATALOGUE_SERVICE: | ||
ms2_catalogue['services'] = dict(CATALOGUE_SERVICES.items() + GEONODE_CATALOGUE_SERVICE.items()) | ||
else: | ||
ms2_catalogue['services'] = CATALOGUE_SERVICES | ||
|
||
data['catalogServices'] = ms2_catalogue | ||
except: | ||
traceback.print_exc() | ||
tb = traceback.format_exc() | ||
logger.error(tb) | ||
|
||
return json.dumps(data, cls=DjangoJSONEncoder, sort_keys=True) | ||
|
||
def get_valid_number(self, number, default=None, complementar=False): | ||
x = float(number) | ||
is_nan = math.isnan(x) | ||
is_inf = math.isinf(x) | ||
if not is_nan and not is_inf: | ||
return x | ||
elif default: | ||
return default if not complementar else -default | ||
return 0 | ||
|
||
def get_overlays(self, viewer): | ||
overlays = [] | ||
selected = None | ||
try: | ||
viewer_obj = json.loads(viewer) | ||
layers = viewer_obj['map']['layers'] | ||
sources = viewer_obj['sources'] | ||
|
||
for layer in layers: | ||
if 'group' not in layer or layer['group'] != "background": | ||
source = sources[layer['source']] | ||
if 'ptype' in source and 'gxp_wmscsource' == source['ptype']: | ||
overlay = {} | ||
overlay['type'] = "wms" | ||
overlay['url'] = source['url'] | ||
overlay['visibility'] = layer['visibility'] if 'visibility' in layer else True | ||
overlay['opacity'] = layer['opacity'] if 'opacity' in layer else 1.0 | ||
overlay['title'] = layer['title'] if 'title' in layer else '' | ||
overlay['name'] = layer['name'] if 'name' in layer else '' | ||
overlay['group'] = layer['group'] if 'group' in layer else '' | ||
overlay['format'] = layer['format'] if 'format' in layer else "image/png" | ||
|
||
overlay['bbox'] = {} | ||
if 'bbox' in layer: | ||
overlay['bbox']['bounds'] = { | ||
"minx": self.get_valid_number(layer['bbox'][0], default=layer['bbox'][2], complementar=True), | ||
"miny": self.get_valid_number(layer['bbox'][1], default=layer['bbox'][3], complementar=True), | ||
"maxx": self.get_valid_number(layer['bbox'][2], default=layer['bbox'][0], complementar=True), | ||
"maxy": self.get_valid_number(layer['bbox'][3], default=layer['bbox'][1], complementar=True) | ||
} | ||
overlay['bbox']['crs'] = layer['srs'] if 'srs' in layer else viewer_obj['map']['projection'] | ||
|
||
overlays.append(overlay) | ||
if not selected or ('selected' in layer and layer['selected']): | ||
selected = overlay | ||
except: | ||
traceback.print_exc() | ||
tb = traceback.format_exc() | ||
logger.error(tb) | ||
|
||
return (overlays, selected) | ||
|
||
def get_center_and_zoom(self, view_map, overlay): | ||
center = { | ||
"x": self.get_valid_number(overlay['bbox']['bounds']['minx'] + | ||
(overlay['bbox']['bounds']['maxx'] - | ||
overlay['bbox']['bounds']['minx']) / 2), | ||
"y": self.get_valid_number(overlay['bbox']['bounds']['miny'] + | ||
(overlay['bbox']['bounds']['maxy'] - | ||
overlay['bbox']['bounds']['miny']) / 2), | ||
"crs": overlay['bbox']['crs'] | ||
} | ||
zoom = view_map['zoom'] | ||
# max_extent = view_map['maxExtent'] | ||
# map_crs = view_map['projection'] | ||
try: | ||
ov_bbox = [self.get_valid_number(overlay['bbox']['bounds']['minx']), | ||
self.get_valid_number(overlay['bbox']['bounds']['miny']), | ||
self.get_valid_number(overlay['bbox']['bounds']['maxx']), | ||
self.get_valid_number(overlay['bbox']['bounds']['maxy']),] | ||
ov_crs = overlay['bbox']['crs'] | ||
srid = int(ov_crs.split(':')[1]) | ||
srid = 3857 if srid == 900913 else srid | ||
poly = Polygon(( | ||
(ov_bbox[0], ov_bbox[1]), | ||
(ov_bbox[0], ov_bbox[3]), | ||
(ov_bbox[2], ov_bbox[3]), | ||
(ov_bbox[2], ov_bbox[1]), | ||
(ov_bbox[0], ov_bbox[1])), srid=srid) | ||
gcoord = SpatialReference(4326) | ||
ycoord = SpatialReference(srid) | ||
trans = CoordTransform(ycoord, gcoord) | ||
poly.transform(trans) | ||
zoom = GoogleZoom().get_zoom(poly) | ||
except: | ||
traceback.print_exc() | ||
tb = traceback.format_exc() | ||
logger.error(tb) | ||
|
||
return (center, zoom) | ||
|
||
|
||
ms2_config_converter = MapStore2GeoExtConfigConverter() |
Binary file not shown.
Oops, something went wrong.