Skip to content
Permalink
Browse files

Refactor adding of wms and vector layers

Support history directive for previous WMSes and more url textbox inside
wms or vector panel and out of main add-layers opanel.
Split function forcreation of vector source.
fixes #229
  • Loading branch information...
raitisbe committed Jul 21, 2019
1 parent 689e549 commit fa3dc398cc50434207d2e5b517e11222d35180e2
@@ -0,0 +1,18 @@
export default ['config', function (config) {
return {
template: require('./partials/add-layers-url.directive.html'),
scope: {
type: '@type',
url: '=url',
connect: '=connect',
field: '=field'
},
controller: ['$scope', 'hs.historyListService', function ($scope, historyListService) {
$scope.items = historyListService.readSourceHistory($scope.what);
$scope.historySelected = function(url){
$scope.url = url;
}
}]

};
}]
@@ -59,27 +59,22 @@ angular.module('hs.addLayersVector', ['hs.styles'])
url = utils.proxify(url);
}

switch (type.toLowerCase()) {
case "kml":
format = new KML({
extractStyles: extract_styles
});
definition.format = "ol.format.KML";
break;
case "gpx":
format = new GPX();
definition.format = "ol.format.GPX";
break;
case "geojson":
format = new GeoJSON();
definition.format = "ol.format.GeoJSON";
break;
case "wfs":
definition.format = "hs.format.WFS";
break;
case "sparql":
definition.format = "hs.format.Sparql";
break;
if(url.toLowerCase().endsWith('kml')){
format = new KML({
extractStyles: extract_styles
});
definition.format = "ol.format.KML";
}
if(url.toLowerCase().endsWith('geojson') || url.toLowerCase().endsWith('json')){
format = new GeoJSON();
definition.format = "ol.format.GeoJSON";
}
if(url.toLowerCase().endsWith('gpx')){
format = new GPX();
definition.format = "ol.format.GPX";
}
if(type.toLowerCase() == "sparql"){
definition.format = "hs.format.Sparql";
}
if (definition.format == 'hs.format.Sparql') {
src = new SparqlJson({
@@ -94,96 +89,12 @@ angular.module('hs.addLayersVector', ['hs.styles'])
} else if (definition.format == 'hs.format.WFS') {
src = new WfsSource(options.defOptions);
} else if (angular.isDefined(options.features)) {
src = new Vector({
projection: srs,
features: options.features
});

src.hasLine = false;
src.hasPoly = false;
src.hasPoint = false;
angular.forEach(src.getFeatures(), function (f) {
if (f.getGeometry()) {
switch (f.getGeometry().getType()) {
case 'LineString' || 'MultiLineString':
src.hasLine = true;
break;
case 'Polygon' || 'MultiPolygon':
src.hasPoly = true;
break;
case 'Point' || 'MultiPoint':
src.hasPoint = true;
break;
}
}
})

if (src.hasLine || src.hasPoly || src.hasPoint) {
src.styleAble = true;
}

src = createVectorSourceFromFeatures(srs, options);
OlMap.map.getView().fit(src.getExtent(), OlMap.map.getSize());

} else {
src = new Vector({
format: format,
url: url,
projection: getProj(srs),
extractStyles: extract_styles,
loader: function (extent, resolution, projection) {
this.set('loaded', false);
var me = this;
$http({ url: url }). //context: this?
then(function (response) {
var data = response.data;
if (data.type == 'GeometryCollection') {
var temp = {
type: "Feature",
geometry: data
};
data = temp;
}
me.addFeatures(format.readFeatures(data, {
dataProjection: srs,
featureProjection: OlMap.map.getView().getProjection().getCode()
}));

src.hasLine = false;
src.hasPoly = false;
src.hasPoint = false;
angular.forEach(src.getFeatures(), function (f) {
if (f.getGeometry()) {
switch (f.getGeometry().getType()) {
case 'LineString' || 'MultiLineString':
src.hasLine = true;
break;
case 'Polygon' || 'MultiPolygon':
src.hasPoly = true;
break;
case 'Point' || 'MultiPoint':
src.hasPoint = true;
break;
}
}
})

if (src.hasLine || src.hasPoly || src.hasPoint) {
src.styleAble = true;
}
me.set('loaded', true);


}, function (err) {
me.error = true;
me.errorMessage = err.status;
me.set('loaded', true);
});
},
strategy: loadingstrategy.all
});

src = createVectorSource(format, url, extract_styles, srs)
}
src.set('loaded', true);
//src.set('loaded', true); Should be set when ajax call finishes
src.set('from_composition', options.from_composition || false);
var lyr = new VectorLayer({
abstract: abstract,
@@ -221,6 +132,98 @@ angular.module('hs.addLayersVector', ['hs.styles'])
return lyr;
};

function createVectorSource(format, url, extract_styles, srs){
var src = new Vector({
format: format,
url: url,
projection: getProj(srs),
extractStyles: extract_styles,
loader: function (extent, resolution, projection) {
this.set('loaded', false);
var me = this;
$http({ url: url }). //context: this?
then(function (response) {
var data = response.data;
if (data.type == 'GeometryCollection') {
var temp = {
type: "Feature",
geometry: data
};
data = temp;
}
me.addFeatures(format.readFeatures(data, {
dataProjection: srs,
featureProjection: OlMap.map.getView().getProjection().getCode()
}));

//TODO probably we should not do this. Have to check when styler is operational
src.hasLine = false;
src.hasPoly = false;
src.hasPoint = false;
angular.forEach(src.getFeatures(), function (f) {
if (f.getGeometry()) {
switch (f.getGeometry().getType()) {
case 'LineString' || 'MultiLineString':
src.hasLine = true;
break;
case 'Polygon' || 'MultiPolygon':
src.hasPoly = true;
break;
case 'Point' || 'MultiPoint':
src.hasPoint = true;
break;
}
}
})

if (src.hasLine || src.hasPoly || src.hasPoint) {
src.styleAble = true;
}
me.set('loaded', true);


}, function (err) {
me.error = true;
me.errorMessage = err.status;
me.set('loaded', true);
});
},
strategy: loadingstrategy.all
});
return src;
}

function createVectorSourceFromFeatures(srs, options){
var src = new Vector({
projection: srs,
features: options.features
});

src.hasLine = false;
src.hasPoly = false;
src.hasPoint = false;
angular.forEach(src.getFeatures(), function (f) {
if (f.getGeometry()) {
switch (f.getGeometry().getType()) {
case 'LineString' || 'MultiLineString':
src.hasLine = true;
break;
case 'Polygon' || 'MultiPolygon':
src.hasPoly = true;
break;
case 'Point' || 'MultiPoint':
src.hasPoint = true;
break;
}
}
})

if (src.hasLine || src.hasPoly || src.hasPoint) {
src.styleAble = true;
}

return src;
}
/**
* (PRIVATE) Zoom to selected vector layer
* @memberof hs.addLayers
@@ -321,7 +324,7 @@ angular.module('hs.addLayersVector', ['hs.styles'])
*/
.controller('hs.addLayersVector.controller', ['$scope', 'hs.map.service', 'hs.styles.service', 'hs.addLayersVector.service', 'Core',
function ($scope, OlMap, styles, service, Core) {
$scope.srs = 'EPSG:3857';
$scope.srs = 'EPSG:4326';
$scope.title = "";
$scope.extract_styles = false;

@@ -67,6 +67,37 @@ export default {
}
});

/**
* Clear Url and hide detailsWms
* @memberof hs.addLayers
* @function clear
*/
$scope.clear = function () {
$scope.url = '';
$scope.showDetails = false;
}

$scope.connect = function () {
wfsGetCapabilitiesService.requestGetCapabilities($scope.url);
$scope.showDetails = true;
}

$scope.$on('ows.wfs_connecting', function (event, url) {
$scope.setUrlAndConnect(url);
});

/**
* Connect to service of specified Url
* @memberof hs.addLayersWms
* @function setUrlAndConnect
* @param {String} url Url of requested service
* @param {String} type Type of requested service
*/
$scope.setUrlAndConnect = function (url) {
$scope.url = url;
$scope.connect();
}

/**
* @function selectAllLayers
* @memberOf hs.addLayersWfs
@@ -9,9 +9,29 @@ export default {
require('components/add-layers/partials/add-wms-layer.md.directive.html') :
require('components/add-layers/partials/add-wms-layer.directive.html')
}],
controller: ['$scope', 'hs.map.service', 'Core', 'hs.addLayersWms.addLayerService', function ($scope, OlMap, Core, LayService) {
controller: ['$scope', 'hs.map.service', 'Core', 'hs.wms.getCapabilitiesService', 'hs.addLayersWms.addLayerService', 'hs.historyListService', function ($scope, OlMap, Core, wmsGetCapabilitiesService, LayService, historyListService) {
$scope.data = LayService.data;

/**
* Clear Url and hide detailsWms
* @memberof hs.addLayers
* @function clear
*/
$scope.clear = function () {
$scope.url = '';
$scope.showDetails = false;
}

$scope.connect = function () {
historyListService.addSourceHistory('Wms', $scope.url);
wmsGetCapabilitiesService.requestGetCapabilities($scope.url);
$scope.showDetails = true;
}

$scope.$on('ows.wms_connecting', function (event, wms) {
$scope.setUrlAndConnect(wms);
});

/**
* @function selectAllLayers
* @memberOf hs.addLayersWms.controller
@@ -38,6 +58,20 @@ export default {
LayService.srsChanged();
}

/**
* Connect to service of specified Url
* @memberof hs.addLayersWms
* @function setUrlAndConnect
* @param {String} url Url of requested service
* @param {String} type Type of requested service
*/
$scope.setUrlAndConnect = function (url) {
$scope.url = url;
$scope.connect();
}

$scope.sourceHistory = LayService.sourceHistory;

$scope.getDimensionValues = LayService.getDimensionValues;

$scope.hasNestedLayers = LayService.hasNestedLayers;
@@ -9,8 +9,9 @@ import { ImageWMS } from 'ol/source';
import { Attribution } from 'ol/control.js';
import { getPreferedFormat } from '../../common/format-utils';
import { addAnchors } from '../../common/attribution-utils';
import 'angular-cookies';

export default ['$rootScope', 'hs.map.service', 'hs.wms.getCapabilitiesService', 'Core', function ($rootScope, OlMap, WmsCapsService, Core) {
export default ['$rootScope', 'hs.map.service', 'hs.wms.getCapabilitiesService', 'Core', '$cookies', 'hs.permalink.urlService', function ($rootScope, OlMap, WmsCapsService, Core, $cookies, permalink) {
var me = this;

this.data = {

0 comments on commit fa3dc39

Please sign in to comment.
You can’t perform that action at this time.