Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing fix #345

Closed
wants to merge 4 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
53 changes: 53 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
language: python
sudo: false
cache: pip

python:
- "3.5"

addons:
postgresql: "9.6"
apt:
packages:
- expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow
- postgis postgresql-9.6-postgis-2.3 # travis doesn't know which one to install
- postgresql-9.6-postgis-2.3-scripts # pre-installed on travis but required for runbot

env:
global:
- VERSION="12.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0"

matrix:
- LINT_CHECK="1"
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1"
- TESTS="1" ODOO_REPO="OCA/OCB"

before_install:

install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
- pip install geojson Shapely sphinx sphinx_bootstrap_theme sphinx-intl odoo-sphinx-autodoc
# This is to solve an issue with stdout file descriptor
# raising a BlockingIOError while executing pylint and returns an exit -1
# seems related to the numerous lint errors on web_view_google_map module
# https://github.com/travis-ci/travis-ci/issues/8920
- /usr/bin/env python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"

before_script:
- if [ "$TESTS" -e "1" ] ; then psql -U postgres -d postgres -c "create extension postgis"; fi
- if [ "$TESTS" -e "1" ] ; then psql -U postgres -d postgres -c "create extension postgis_topology"; fi

script:
- if [ -z "$DOCS" ] ; then travis_run_tests; fi
- if [ -n "$DOCS" ] ; then ./.travis_build_doc; fi

after_success:
- if [ -z "$DOCS" ] ; then travis_after_tests_success; fi
- if [ -n "$DOCS" ] ; then ./.travis_push_doc; fi

branches:
except:
- /^merge-branch-.*$/
2 changes: 1 addition & 1 deletion base_geoengine/geo_view/geo_raster_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GeoRasterLayer(models.Model):
@api.depends('raster_type', 'is_wmts')
def _compute_has_type(self):
for rec in self:
rec.has_type = rec.raster_type == 'is_wmts'
rec.has_type = rec.raster_type

@api.multi
@api.depends('raster_type')
Expand Down
36 changes: 33 additions & 3 deletions geoengine_swisstopo/geo_view/geo_raster_layer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


BASE_URL = (
"https://wmts{{0-9}}.geo.admin.ch/1.0.0/{layername}/default/"
"{time}/{matrix_set}/{{TileMatrix}}/{{TileRow}}/{{TileCol}}.{ext}"
)

class GeoRasterLayer(models.Model):
_inherit = 'geoengine.raster.layer'

raster_type = fields.Selection(selection_add=[('swisstopo', 'Swisstopo')])
layername = fields.Char('Layer Machine Name')
time = fields.Char('Time Dimension')
projection = fields.Char('Projection', default="EPSG:21781")
layername = fields.Char("Layer Machine Name", default="ch.swisstopo.pixelkarte-farbe")
matrix_set = fields.Selection(
[
("2056", "LV95/CH1903+ (EPSG:2056)"),
("21781", "LV03/CH1903 (EPSG:21781)"),
("4326", "LV95/CH1903+ (EPSG:4326)"),
("3857", "LV95/CH1903+ (EPSG:3857, as used in OSM, Bing, Google Map)"),
],
default="21781",
string='TileMatrixSet',
)
time = fields.Char('Time Dimension', default="current")
wmts_url = fields.Char(compute="_compute_wmts_url", readonly=True, store=True)

@api.depends("raster_type", "layername", "time", "matrix_set", "format_suffix")
def _compute_wmts_url(self):
for record in self:
if record.raster_type == "swisstopo":
record.wmts_url = BASE_URL.format(
layername=record.layername or "ch.swisstopo.pixelkarte-farbe",
time=record.time or "current",
matrix_set=record.matrix_set or "21781",
ext=record.format_suffix or "jpeg",
)
else:
record.wmts_url = False
3 changes: 3 additions & 0 deletions geoengine_swisstopo/geo_view/geo_raster_layer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<field name="layername"/>
<field name="time"/>
<field name="format_suffix"/>
<field name="projection"/>
<field name="matrix_set"/>
<field name="wmts_url"/>
</group>
</xpath>
</field>
Expand Down
36 changes: 17 additions & 19 deletions geoengine_swisstopo/static/src/js/geoengine_swisstopo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ var RESOLUTIONS = [
0.25, 0.1
];

var BASE_URL = 'https://wmts{0-9}.geo.admin.ch/1.0.0/{Layer}/default/{Time}/21781/{TileMatrix}/{TileRow}/{TileCol}.{format}';

var ATTRIBUTIONS = '<a target="_blank" href="https://www.swisstopo.admin.ch">swisstopo</a>';

/**
* Extents of Swiss projections. (EPSG:21781)
*/
var EXTENT = [420000, 30000, 900000, 350000];

var PROJECTION_CODE = "EPSG:21781";
var PROJECTION_CODE_1 = "EPSG:21781";
var PROJECTION_CODE_2 = "EPSG:2056";
var PROJECTION_CODE_3 = "EPSG:4326";

var init_EPSG_21781 = function (self) {
var init_EPSG_PROJ = function (self) {
// Adding proj4
self.jsLibs.push(
'/geoengine_swisstopo/static/lib/proj4.js'
);
};

var define_EPSG_21781 = function () {
var define_EPSG_SUISSE = function () {
// add swiss projection to allow conversions
if (!ol.proj.get(PROJECTION_CODE)) {
if (!ol.proj.get(PROJECTION_CODE_1)) {
proj4.defs('EPSG:21781', '+proj=somerc +lat_0=46.95240555555556 ' +
'+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
'+towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs');
}
if (!ol.proj.get(PROJECTION_CODE_2)) {
proj4.defs("EPSG:2056","+proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs +type=crs");
}
proj4.defs("EPSG:4326","+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
};


Expand All @@ -46,21 +50,21 @@ odoo.define('geoengine_swisstopo.projection_EPSG_21781', function (require) {
GeoengineWidgets.FieldGeoEngineEditMap.include({
init: function (parent) {
this._super.apply(this, arguments);
init_EPSG_21781(this);
init_EPSG_PROJ(this);
},
_render: function (parent) {
define_EPSG_21781();
define_EPSG_SUISSE();
this._super.apply(this, arguments);
},

});
GeoengineView.include({
init: function (parent) {
this._super.apply(this, arguments);
init_EPSG_21781(this);
init_EPSG_PROJ(this);
},
_render: function (parent) {
define_EPSG_21781();
define_EPSG_SUISSE();
this._super.apply(this, arguments);
},

Expand Down Expand Up @@ -89,25 +93,19 @@ odoo.define('geoengine_swisstopo.BackgroundLayers', function (require) {
var out = this._super.apply(this, arguments);
if (l.raster_type == 'swisstopo') {
var format = l.format_suffix || 'jpeg';
var layer = l.layername || 'ch.swisstopo.pixelkarte-farbe';

var url = BASE_URL.replace('{format}', format);
var projection = ol.proj.get(PROJECTION_CODE);
var projection = ol.proj.get(l.projection || 'EPSG:21781');
var source = new ol.source.WMTS({
attributions: [
new ol.Attribution({
html: ATTRIBUTIONS,
})
],
url: url,
dimensions: {
'Time': l.time || 'current',
},
url: l.wmts_url,
projection: projection,
requestEncoding: 'REST',
layer: layer,
version: '1.0.0',
style: 'default',
matrixSet: '21781',
format: 'image/' + format,
tileGrid: this.createTileGrid(),
crossOrigin: 'anonymous',
Expand Down
Loading