Skip to content
Permalink
Browse files

Move adding of geojson from url param to add-layers.vector.service

  • Loading branch information...
raitisbe committed Jul 20, 2019
1 parent f6ff0ff commit 95a8fdea530d91ae6f8689074c79369298d2693e
@@ -30,8 +30,8 @@ angular.module('hs.addLayersVector', ['hs.styles'])
* @name hs.addLayersVector.service
* @description Service handling adding nonwms OWS services or files. Handles also drag and drop addition.
*/
.service('hs.addLayersVector.service', ['config', '$rootScope', 'hs.map.service', 'hs.styles.service', 'hs.utils.service', '$http', 'hs.save-map.service',
function (config, $rootScope, OlMap, styles, utils, $http, statusCreator) {
.service('hs.addLayersVector.service', ['config', 'Core', '$rootScope', 'hs.map.service', 'hs.styles.service', 'hs.utils.service', '$http', 'hs.save-map.service', 'hs.permalink.urlService',
function (config, Core, $rootScope, OlMap, styles, utils, $http, statusCreator, permalink) {
var me = this;

/**
@@ -221,6 +221,40 @@ angular.module('hs.addLayersVector', ['hs.styles'])
return lyr;
};

/**
* (PRIVATE) Zoom to selected vector layer
* @memberof hs.addLayers
* @function zoomToVectorLayer
* @param {ol.Layer} lyr New layer
*/
function zoomToVectorLayer(lyr) {
Core.setMainPanel('layermanager');
lyr.getSource().on('change', function () { //Event needed because features are loaded asynchronously
var extent = lyr.getSource().getExtent();
if (extent != null) OlMap.map.getView().fit(extent, OlMap.map.getSize());
});
}

me.checkUrlParamsAndAdd = function(){
var title = decodeURIComponent(permalink.getParamValue('title')) || 'Layer';
var abstract = decodeURIComponent(permalink.getParamValue('abstract'));

if (permalink.getParamValue('geojson_to_connect')) {
var url = permalink.getParamValue('geojson_to_connect');
var type = 'geojson';
if (url.indexOf('gpx') > 0) type = 'gpx';
if (url.indexOf('kml') > 0) type = 'kml';
var lyr = me.add(type, url, title, abstract, false, 'EPSG:4326');
zoomToVectorLayer(lyr);
}

if (permalink.getParamValue('kml_to_connect')) {
var url = permalink.getParamValue('kml_to_connect');
var lyr = me.add('kml', url, title, abstract, true, 'EPSG:4326');
zoomToVectorLayer(lyr);
}
}

var dragAndDrop = new DragAndDrop({
formatConstructors: [
GPX,
@@ -233,6 +267,7 @@ angular.module('hs.addLayersVector', ['hs.styles'])

$rootScope.$on('map.loaded', function () {
OlMap.map.addInteraction(dragAndDrop);
me.checkUrlParamsAndAdd()
});

dragAndDrop.on('addfeatures', function (event) {
@@ -101,20 +101,6 @@ export default {
$scope.showDetails = false;
}

/**
* (PRIVATE) Zoom to selected vector layer
* @memberof hs.addLayers
* @function zoomToVectorLayer
* @param {ol.Layer} lyr New layer
*/
function zoomToVectorLayer(lyr) {
Core.setMainPanel('layermanager');
lyr.getSource().on('change', function () { //Event needed because features are loaded asynchronously
var extent = lyr.getSource().getExtent();
if (extent != null) map.getView().fit(extent, map.getSize());
});
}

if (permalink.getParamValue('wms_to_connect')) {
var wms = permalink.getParamValue('wms_to_connect');
Core.setMainPanel(Core.singleDatasources ? 'datasource_selector' : 'ows');
@@ -129,24 +115,6 @@ export default {
if (Core.singleDatasources) $('.dss-tabs a[href="#OWS"]').tab('show');
}

var title = decodeURIComponent(permalink.getParamValue('title')) || 'Layer';
var abstract = decodeURIComponent(permalink.getParamValue('abstract'));

if (permalink.getParamValue('geojson_to_connect')) {
var url = permalink.getParamValue('geojson_to_connect');
var type = 'geojson';
if (url.indexOf('gpx') > 0) type = 'gpx';
if (url.indexOf('kml') > 0) type = 'kml';
var lyr = nonwmsservice.add(type, url, title, abstract, false, 'EPSG:4326');
zoomToVectorLayer(lyr);
}

if (permalink.getParamValue('kml_to_connect')) {
var url = permalink.getParamValue('kml_to_connect');
var lyr = nonwmsservice.add('kml', url, title, abstract, true, 'EPSG:4326');
zoomToVectorLayer(lyr);
}

$scope.$emit('scope_loaded', "Ows");
}
]
@@ -3,7 +3,7 @@ import { Vector } from 'ol/source';
import VectorLayer from 'ol/layer/Vector';
import SparqlJson from 'hs.source.SparqlJson'
import social from 'angular-socialshare';
import './config-parsers.module';
import './layer-parser.module';
import { transform, transformExtent } from 'ol/proj';
import { fromExtent as polygonFromExtent } from 'ol/geom/Polygon';
import Feature from 'ol/Feature';
@@ -343,6 +343,39 @@ export default ['$rootScope', '$q', '$location', '$http', 'hs.map.service', 'Cor
}
}

/**
* @function parsePermalinkLayers
* @memberof hs.compositions.service
* Load layers received through permalink to map
*/
me.parsePermalinkLayers = function () {
var layersUrl = utils.proxify(permalink.getParamValue('permalink'));
$http({ url: layersUrl }).
then(function (response) {
if (response.data.success == true) {
var data = {};
data.data = {};
data.data.layers = response.data.data;
compositionParser.removeCompositionLayers();
response.layers = response.data.data;
var layers = compositionParser.jsonToLayers(data);
for (var i = 0; i < layers.length; i++) {
OlMap.addLayer(layers[i]);
}
} else {
if (console) console.log('Error loading permalink layers');
}
}, function (err) {

});
};

$rootScope.$on('map.loaded', function () {
if (permalink.getParamValue('permalink')) {
permalink.parsePermalinkLayers();
}
})

me.loadComposition = function (url, overwrite) {
compositionParser.load(url, overwrite, me.data.useCallbackForEdit ? callbackForEdit : null);
}
@@ -53,9 +53,6 @@ function ($scope, OlMap, config, permalink, Core, $rootScope) {
OlMap.moveToAndZoom(parseFloat(hs_x), parseFloat(hs_y), parseInt(hs_z));
}

if (permalink.getParamValue('permalink')) {
permalink.parsePermalinkLayers();
}
if (permalink.getParamValue("puremap")) {
Core.puremapApp = true;
OlMap.puremap();
@@ -1,5 +1,5 @@
export default ['$rootScope', '$http', '$location', '$window', 'hs.map.service', 'Core', 'hs.utils.service', 'hs.save-map.service', 'hs.compositions.service_parser', 'config',
function ($rootScope, $http, $location, $window, OlMap, Core, utils, saveMap, compositions, config) {
export default ['$rootScope', '$http', '$location', '$window', 'hs.map.service', 'Core', 'hs.utils.service', 'hs.save-map.service', 'config',
function ($rootScope, $http, $location, $window, OlMap, Core, utils, saveMap, config) {

var url_generation = true;
//some of the code is taken from http://stackoverflow.com/questions/22258793/set-url-parameters-without-causing-page-refresh
@@ -124,33 +124,6 @@ export default ['$rootScope', '$http', '$location', '$window', 'hs.map.service',
}, {});
},

/**
* @function parsePermalinkLayers
* @memberof hs.permalink.urlService
* Load layers received through permalink to map
*/
parsePermalinkLayers: function () {
var layersUrl = utils.proxify(me.getParamValue('permalink'));
$http({ url: layersUrl }).
then(function (response) {
if (response.data.success == true) {
var data = {};
data.data = {};
data.data.layers = response.data.data;
compositions.removeCompositionLayers();
response.layers = response.data.data;
var layers = compositions.jsonToLayers(data);
for (var i = 0; i < layers.length; i++) {
OlMap.addLayer(layers[i]);
}
} else {
if (console) console.log('Error loading permalink layers');
}
}, function (err) {

});
},

/**
* @function stringify
* @memberof hs.permalink.urlService

0 comments on commit 95a8fde

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