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

feat(map): normalize the dpi to 96 #468

Merged
merged 2 commits into from
Oct 11, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { OgcFilterableDataSourceOptions } from '../../../filter/shared/ogc-filte
import { QueryHtmlTarget } from '../../../query/shared/query.enums';
import {
formatWFSQueryString,
defaultWfsVersion,
checkWfsParams,
defaultFieldNameGeometry
} from './wms-wfs.utils';
Expand Down Expand Up @@ -73,6 +72,11 @@ export class WMSDataSource extends DataSource {
sourceParams.info_format = sourceParams.INFO_FORMAT;
}

const dpi = sourceParams.dpi || 96;
sourceParams.DPI = dpi;
sourceParams.MAP_RESOLUTION = dpi;
sourceParams.FORMAT_OPTIONS = 'dpi:' + dpi;

if (options.refreshIntervalSec && options.refreshIntervalSec > 0) {
setInterval(() => {
this.refresh();
Expand All @@ -93,6 +97,7 @@ export class WMSDataSource extends DataSource {
dynamicUrl: this.buildDynamicDownloadUrlFromParamsWFS(options)
});
} // #### END if paramsWFS

if (!options.sourceFields || options.sourceFields.length === 0) {
options.sourceFields = [];
} else {
Expand All @@ -118,6 +123,7 @@ export class WMSDataSource extends DataSource {
? false
: true;
}

if (
sourceParams.layers.split(',').length > 1 &&
initOgcFilters &&
Expand Down Expand Up @@ -187,7 +193,7 @@ export class WMSDataSource extends DataSource {
}

legend = layers.map((layer: string) => {
const separator = baseUrl.match( /\?/m) ? '&' : '?'
const separator = baseUrl.match(/\?/) ? '&' : '?';
return {
url: `${baseUrl}${separator}${params.join('&')}&LAYER=${layer}`,
title: layers.length > 1 ? layer : undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/geo/src/lib/datasource/utils/esri-style-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class EsriStyleGenerator {
}

static _getResolutionForScale(scale, units) {
const dpi = 25.4 / 0.28;
const dpi = 96;
const mpu = olproj.METERS_PER_UNIT[units];
const inchesPerMeter = 39.37;
const inchesPerMeter = 39.3701;
return parseFloat(scale) / (mpu * inchesPerMeter * dpi);
}

Expand Down
17 changes: 12 additions & 5 deletions packages/geo/src/lib/layer/shared/layers/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export abstract class Layer {
return resolution >= minResolution && resolution <= maxResolution;
}

get showInLayerList(): boolean { return this.options.showInLayerList !== false; }
get showInLayerList(): boolean {
return this.options.showInLayerList !== false;
}

constructor(options: LayerOptions) {
this.options = options;
Expand All @@ -98,13 +100,18 @@ export abstract class Layer {
this.opacity =
this.options.opacity === undefined ? 1 : this.options.opacity;

if (this.options.legendOptions && (this.options.legendOptions.url || this.options.legendOptions.html)) {
if (
this.options.legendOptions &&
(this.options.legendOptions.url || this.options.legendOptions.html)
) {
this.legend = this.dataSource.setLegend(this.options.legendOptions);
}

this.legendCollapsed = this.options.legendOptions ?
this.options.legendOptions.collapsed ? this.options.legendOptions.collapsed : true :
true;
this.legendCollapsed = this.options.legendOptions
? this.options.legendOptions.collapsed
? this.options.legendOptions.collapsed
: true
: true;

this.ol.set('_layer', this, true);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/map/shared/controllers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class MapViewController extends MapController {
* @param dpi Dot per inches
* @returns View scale
*/
getScale(dpi = 72) {
getScale(dpi = 96) {
return getScaleFromResolution(
this.getResolution(),
this.getOlProjection().getUnits(),
Expand Down
10 changes: 6 additions & 4 deletions packages/geo/src/lib/map/shared/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,19 @@ export function formatScale(scale) {
* @param dpi DPI
* @returns Resolution
*/
export function getResolutionFromScale(scale: number, dpi: number = 72): number {
return scale / (39.37 * dpi);
export function getResolutionFromScale(scale: number, dpi: number = 96): number {
const inchesPerMeter = 39.3701;
return scale / (inchesPerMeter * dpi);
}

/**
* Return the resolution from a scale denom
* @param Scale denom
* @returns Resolution
*/
export function getScaleFromResolution(resolution: number, unit: string = 'm', dpi: number = 72): number {
return resolution * olproj.METERS_PER_UNIT[unit] * 39.37 * dpi;
export function getScaleFromResolution(resolution: number, unit: string = 'm', dpi: number = 96): number {
const inchesPerMeter = 39.3701;
return resolution * olproj.METERS_PER_UNIT[unit] * inchesPerMeter * dpi;
}

/**
Expand Down