def wmts_remove(id): wmts = WMTS.by_id(id) if wmts: db.session.delete(wmts) db.session.commit() flash( _('WMTS removed'), 'success') return redirect(url_for('admin.wmts_list'))
def wmts_edit(id=None): wmts = WMTS.by_id(id) if id else None if wmts: form = WMTSForm(request.form, wmts) else: form = WMTSForm(request.form) if form.validate_on_submit(): if not wmts: wmts = WMTS() db.session.add(wmts) wmts.url = form.data['url'] wmts.username = form.data['username'] wmts.password = form.data['password'] wmts.is_protected = form.data['is_protected'] wmts.name = form.data['name'] wmts.title = form.data['title'] wmts.format = form.data['format'] wmts.max_tiles = form.data['max_tiles'] or None try: view_coverage = json.loads(form.data['view_coverage']) only_first_geometry = False view_geometry = None # check if we have a feature colleciton than load only first geometry if 'features' in view_coverage: for feature in view_coverage['features']: if 'geometry' in feature: if view_geometry: only_first_geometry = True break view_geometry = feature['geometry'] if view_geometry: view_coverage = view_geometry if only_first_geometry: flash(_('Only the first geometry was used for view coverage'), 'success') wmts.view_coverage = from_shape(asShape(view_coverage), srid=4326) except: db.session.rollback() flash(_('Geometry not correct'), 'error') return render_template('admin/wmts_edit.html', form=form, id=id) wmts.view_level_start = form.data['view_level_start'] wmts.view_level_end = form.data['view_level_end'] wmts.is_background_layer = form.data['is_background_layer'] wmts.is_overlay = form.data['is_transparent'] wmts.is_transparent = form.data['is_transparent'] wmts.is_visible = form.data['is_visible'] wmts.is_public = form.data['is_public'] wmts.is_accessible = form.data['is_accessible'] try: db.session.commit() write_mapproxy_config(current_app) flash(_('Saved WMTS'), 'success') return redirect(url_for('admin.wmts_list')) except IntegrityError: db.session.rollback() flash(_('WMTS with this name already exist'), 'error') # load wmts_coverage as json if wmts: view_coverage = to_shape(wmts.view_coverage) form.view_coverage.data = json.dumps(mapping(view_coverage)) return render_template('admin/wmts_edit.html', form=form, id=id)
def wmts_edit(id=None): wmts = db.session.query(WMTS, pg_functions.geojson(WMTS.view_coverage.transform(3857))).filter_by(id=id).first() if id else None if wmts: wmts[0].view_coverage = wmts[1] wmts = wmts[0] form = WMTSForm(request.form, wmts) else: form = WMTSForm(request.form) if form.validate_on_submit(): if not wmts: wmts = WMTS() db.session.add(wmts) if form.data['is_background_layer']: old_background_layer = WMTS.query.filter_by(is_background_layer=True).first() if old_background_layer: old_background_layer.is_background_layer = False wmts.url = form.data['url'] wmts.username = form.data['username'] wmts.password = form.data['password'] wmts.name = form.data['name'] wmts.title = form.data['title'] wmts.layer = form.data['layer'] wmts.format = form.data['format'] wmts.srs = form.data['srs'] wmts.matrix_set = form.data['matrix_set'] geom = asShape(loads(form.data['view_coverage'])) wmts.view_coverage = WKTSpatialElement(geom.wkt, srid=3857, geometry_type='POLYGON') wmts.view_level_start = form.data['view_level_start'] wmts.view_level_end = form.data['view_level_end'] wmts.is_background_layer = form.data['is_background_layer'] wmts.is_baselayer = not form.data['is_transparent'] wmts.is_overlay = form.data['is_transparent'] wmts.is_transparent = form.data['is_transparent'] wmts.is_visible = form.data['is_visible'] wmts.is_public = form.data['is_public'] try: db.session.commit() write_mapproxy_config(current_app) flash( _('Saved WMTS'), 'success') return redirect(url_for('admin.wmts_list')) except IntegrityError: db.session.rollback() flash(_('WMTS with this name already exist'), 'error') return render_template('admin/wmts_edit.html', form=form, id=id)
def wmts_remove(id): wmts = WMTS.by_id(id) db.session.delete(wmts) db.session.commit() flash(_('WMTS removed'), 'success') return redirect(url_for('admin.wmts_list'))