Skip to content

Commit

Permalink
fix(sharemap): Limit sharemap url length, Coord precision & skip defa…
Browse files Browse the repository at this point in the history
…ult context (#367)

* refactor(share)Coord precision & skip default context

* Delete launch.json

* Delete settings.json

* Delete 3-Deployer_lib_vers_IGO2.bat

* Delete proxy.conf.json

* typo(proxy) delete file by mistake

* refactor(sharemap) moving to viewcontroller instead of map.*

* refactor(sharemap) remove unused settings from url & url clean up

* Delete proxy.conf.json

* proxy
  • Loading branch information
pelord authored and mbarbeau committed Jul 24, 2019
1 parent d2e33ae commit 4c4fb3c
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions packages/context/src/lib/share-map/shared/share-map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class ShareMapService {
!this.route ||
!this.route.options.visibleOnLayersKey ||
!this.route.options.visibleOffLayersKey ||
!map.getZoom()
!map.viewController.getZoom()
) {
return;
}
const llc = publicShareOption.layerlistControls.querystring;

const visibleKey = this.route.options.visibleOnLayersKey;
const invisibleKey = this.route.options.visibleOffLayersKey;
let visibleKey = this.route.options.visibleOnLayersKey;
let invisibleKey = this.route.options.visibleOffLayersKey;
const layers = map.layers;

const routingKey = this.route.options.routingCoordKey;
Expand All @@ -77,6 +77,13 @@ export class ShareMapService {
const visibleLayers = layers.filter(lay => lay.visible);
const invisibleLayers = layers.filter(lay => !lay.visible);

if (visibleLayers.length === 0) {
visibleKey = '';
}
if (invisibleLayers.length === 0) {
invisibleKey = '';
}

let layersUrl = '';
let layersToLoop = [];
if (visibleLayers.length > invisibleLayers.length) {
Expand All @@ -94,16 +101,33 @@ export class ShareMapService {
}
layersUrl = layersUrl.substr(0, layersUrl.length - 1);

const zoom = 'zoom=' + map.getZoom();
const arrayCenter = map.getCenter('EPSG:4326') || [];
const center = 'center=' + arrayCenter.toString();
let zoom = 'zoom=' + map.viewController.getZoom();
const arrayCenter = map.viewController.getCenter('EPSG:4326') || [];
const long = arrayCenter[0].toFixed(5).replace(/\.([^0]+)0+$/,".$1")
const lat = arrayCenter[1].toFixed(5).replace(/\.([^0]+)0+$/,".$1")
const center = `center=${long},${lat}`.replace(/.00000/g, '');
let context = '';
if (this.contextService.context$.value) {
context = 'context=' + this.contextService.context$.value.uri;
if (this.contextService.context$.value.uri !== '_default') {
context = 'context=' + this.contextService.context$.value.uri;
}
if (this.contextService.context$.value.map.view.zoom) {
zoom = this.contextService.context$.value.map.view.zoom === map.viewController.getZoom() ? '' : 'zoom=' + map.viewController.getZoom();
}
}

return `${location.origin}${
let url = `${location.origin}${
location.pathname
}?${context}&${zoom}&${center}&${layersUrl}&${llc}&${routingUrl}`.replace(/&&/g, '&');
}?${context}&${zoom}&${center}&${layersUrl}&${llc}&${routingUrl}`

for (let i = 0; i < 5; i++) {
url = url.replace(/&&/g, '&');
url = url.endsWith('&') ? url.slice(0, -1) : url;
}
url = url.endsWith('&') ? url.slice(0, -1) : url;
url = url.replace('?&', '?')

return url;
}

}

0 comments on commit 4c4fb3c

Please sign in to comment.