Skip to content

Commit

Permalink
Merge pull request #221 from kekel87/fix_source_imagearcgisrest
Browse files Browse the repository at this point in the history
fix(source): update params ImageArcgisRest
  • Loading branch information
Yakoust committed Mar 13, 2019
2 parents cb8c9d0 + 3d0bc9c commit a523b2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, forwardRef, Host, Input, OnInit } from '@angular/core';
import { source, ProjectionLike, Attribution, ImageLoadFunctionType } from 'openlayers';
import { Component, forwardRef, Host, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { Attribution, ImageLoadFunctionType, ProjectionLike, source } from 'openlayers';

import { LayerImageComponent } from '../layers/layerimage.component';
import { SourceComponent } from './source.component';

Expand All @@ -10,7 +11,7 @@ import { SourceComponent } from './source.component';
`,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageArcGISRestComponent) }],
})
export class SourceImageArcGISRestComponent extends SourceComponent implements OnInit {
export class SourceImageArcGISRestComponent extends SourceComponent implements OnInit, OnChanges {
instance: source.ImageArcGISRest;

@Input() projection: ProjectionLike | string;
Expand All @@ -32,4 +33,10 @@ export class SourceImageArcGISRestComponent extends SourceComponent implements O
this.instance = new source.ImageArcGISRest(this);
this.host.instance.setSource(this.instance);
}

ngOnChanges(changes: SimpleChanges) {
if (this.instance && changes.hasOwnProperty('params')) {
this.instance.updateParams(this.params);
}
}
}
39 changes: 10 additions & 29 deletions src/app/raster/raster.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface RasterData {
threads="4"
operationType="image"
[operation]="operation"
[lib]="lib"
(beforeOperations)="beforeOperations($event)"
>
<aol-source-osm *ngIf="selectLayer === 'osm'"></aol-source-osm>
Expand Down Expand Up @@ -79,10 +78,7 @@ interface RasterData {
],
})
export class RasterComponent {
lib: any = {
brightness: brightness,
contrast: contrast,
};
operation = rasterOperation;
brightness = 0;
contrast = 0;

Expand All @@ -96,42 +92,27 @@ export class RasterComponent {
data.contrast = this.contrast;
}

operation(imageDatas: [ImageData], data: RasterData) {
let [imageData] = imageDatas;
imageData = brightness(imageData, data.brightness);
imageData = contrast(imageData, data.contrast);
return imageData;
}

updateRaster() {
this.rasterSource.instance.refresh();
}
}

/**
* @see https://github.com/canastro/image-filter-brightness/blob/master/src/transform.js
*/
function brightness(imageData: ImageData, adjustment: number) {
const pixels = imageData.data,
pixelsLength = pixels.length;

for (let i = 0; i < pixelsLength; i += 4) {
pixels[i] += adjustment;
pixels[i + 1] += adjustment;
pixels[i + 2] += adjustment;
}
return imageData;
}

/**
* @see https://github.com/canastro/image-filter-contrast/blob/master/src/transform.js
*/
function contrast(imageData: ImageData, adjustment: number) {
export function rasterOperation(imageDatas: [ImageData], data: RasterData): ImageData {
const [imageData] = imageDatas;

const pixels = imageData.data,
factor = (259 * (adjustment + 255)) / (255 * (259 - adjustment)),
pixelsLength = pixels.length;
pixelsLength = pixels.length,
factor = (259 * (data.contrast + 255)) / (255 * (259 - data.contrast));

for (let i = 0; i < pixelsLength; i += 4) {
pixels[i] += data.brightness;
pixels[i + 1] += data.brightness;
pixels[i + 2] += data.brightness;

pixels[i] = factor * (pixels[i] - 128) + 128;
pixels[i + 1] = factor * (pixels[i + 1] - 128) + 128;
pixels[i + 2] = factor * (pixels[i + 2] - 128) + 128;
Expand Down

0 comments on commit a523b2b

Please sign in to comment.