<commit_before>import {
	BaseImageryPlugin,
	getPolygonIntersectionRatioWithMultiPolygon,
	ImageryMapPosition,
	ImageryPlugin
} from '@ansyn/imagery';
import { OpenLayersDisabledMap, OpenLayersMap } from '@ansyn/ol';
import { select, Store } from '@ngrx/store';
import { combineLatest, Observable } from 'rxjs';
import { selectMapPositionByMapId, selectOverlayByMapId } from '@ansyn/map-facade';
import { filter, map, switchMap, tap } from 'rxjs/operators';
import { AutoSubscription } from 'auto-subscriptions';
import { AlertMsgTypesEnum } from '../../../alerts/model';
import { AddAlertMsg, RemoveAlertMsg } from '../../../overlays/overlay-status/actions/overlay-status.actions';
import { selectFilteredOveralys, selectOverlaysMap } from '../../../overlays/reducers/overlays.reducer';
import { isFullOverlay } from '../../../core/utils/overlays';
import { IOverlay } from '../../../overlays/models/overlay.model';
import { CesiumMap } from '@ansyn/imagery-cesium';

@ImageryPlugin({
	supported: [OpenLayersMap, OpenLayersDisabledMap, CesiumMap],
	deps: [Store]
})
export class AlertsPlugin extends BaseImageryPlugin {
	overlay: IOverlay;
	@AutoSubscription
	setOverlaysNotInCase$: Observable<any> = combineLatest(this.store$.select(selectOverlaysMap), this.store$.select(selectFilteredOveralys)).pipe(
		map(this.setOverlaysNotInCase.bind(this)),
		tap((action: RemoveAlertMsg | AddAlertMsg) => this.store$.dispatch(action))
	);

	constructor(protected store$: Store<any>) {
		super();
	}

	@AutoSubscription
	positionChange$ = () => combineLatest(this.store$.select(selectMapPositionByMapId(this.mapId)), this.store$.select(selectOverlayByMapId(this.mapId)))
		.pipe(
			filter(([position, overlay]) => Boolean(position) && Boolean(overlay)),
			tap(([position, overlay]) => this.overlay = overlay),
			switchMap(([position, overlay]) => {
				const actions = [this.positionChanged(position, overlay)];
				return actions.map(action => this.store$.dispatch(action))
			}),
		);

	setOverlaysNotInCase([overlays, filteredOverlays]: [Map<string, IOverlay>, string[]]): RemoveAlertMsg | AddAlertMsg {
		const shouldRemoved = !this.overlay || filteredOverlays.some((id: string) => id === this.overlay.id);
		const payload = { key: AlertMsgTypesEnum.overlayIsNotPartOfQuery, value: this.mapId };
		return shouldRemoved ? new RemoveAlertMsg(payload) : new AddAlertMsg(payload);
	}

	positionChanged(position: ImageryMapPosition, overlay: IOverlay): RemoveAlertMsg | AddAlertMsg {
		const isWorldView = !isFullOverlay(overlay);
		let isInBound;
		if (!isWorldView) {
			const viewExtent = position.extentPolygon;
			const intersection = getPolygonIntersectionRatioWithMultiPolygon(viewExtent, overlay.footprint);<commit_msg>set overlay before filter (#2623)<commit_after>import {
	BaseImageryPlugin,
	getPolygonIntersectionRatioWithMultiPolygon,
	ImageryMapPosition,
	ImageryPlugin
} from '@ansyn/imagery';
import { OpenLayersDisabledMap, OpenLayersMap } from '@ansyn/ol';
import { select, Store } from '@ngrx/store';
import { combineLatest, Observable } from 'rxjs';
import { selectMapPositionByMapId, selectOverlayByMapId } from '@ansyn/map-facade';
import { filter, map, switchMap, tap } from 'rxjs/operators';
import { AutoSubscription } from 'auto-subscriptions';
import { AlertMsgTypesEnum } from '../../../alerts/model';
import { AddAlertMsg, RemoveAlertMsg } from '../../../overlays/overlay-status/actions/overlay-status.actions';
import { selectFilteredOveralys, selectOverlaysMap } from '../../../overlays/reducers/overlays.reducer';
import { isFullOverlay } from '../../../core/utils/overlays';
import { IOverlay } from '../../../overlays/models/overlay.model';
import { CesiumMap } from '@ansyn/imagery-cesium';

@ImageryPlugin({
	supported: [OpenLayersMap, OpenLayersDisabledMap, CesiumMap],
	deps: [Store]
})
export class AlertsPlugin extends BaseImageryPlugin {
	overlay: IOverlay;
	@AutoSubscription
	setOverlaysNotInCase$: Observable<any> = combineLatest(this.store$.select(selectOverlaysMap), this.store$.select(selectFilteredOveralys)).pipe(
		map(this.setOverlaysNotInCase.bind(this)),
		tap((action: RemoveAlertMsg | AddAlertMsg) => this.store$.dispatch(action))
	);

	constructor(protected store$: Store<any>) {
		super();
	}

	@AutoSubscription
	positionChange$ = () => combineLatest(this.store$.select(selectMapPositionByMapId(this.mapId)), this.store$.select(selectOverlayByMapId(this.mapId)))
		.pipe(
			tap(([position, overlay]) => this.overlay = overlay),
			filter(([position, overlay]) => Boolean(position) && Boolean(overlay)),
			switchMap(([position, overlay]) => {
				const actions = [this.positionChanged(position, overlay)];
				return actions.map(action => this.store$.dispatch(action))
			}),
		);

	setOverlaysNotInCase([overlays, filteredOverlays]: [Map<string, IOverlay>, string[]]): RemoveAlertMsg | AddAlertMsg {
		const shouldRemoved = !this.overlay || filteredOverlays.some((id: string) => id === this.overlay.id);
		const payload = { key: AlertMsgTypesEnum.overlayIsNotPartOfQuery, value: this.mapId };
		return shouldRemoved ? new RemoveAlertMsg(payload) : new AddAlertMsg(payload);
	}

	positionChanged(position: ImageryMapPosition, overlay: IOverlay): RemoveAlertMsg | AddAlertMsg {
		const isWorldView = !isFullOverlay(overlay);
		let isInBound;
		if (!isWorldView) {
			const viewExtent = position.extentPolygon;
			const intersection = getPolygonIntersectionRatioWithMultiPolygon(viewExtent, overlay.footprint);
{'fraction_non_alphanumeric': 0.14445258147198828, 'fraction_numerical': 0.0007323324789454412, 'mean_word_length': 5.923954372623574, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2891924', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1696, 'n_words': 323}