-
Notifications
You must be signed in to change notification settings - Fork 4
draft swipe position #32
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
Open
Nour-Cheour10
wants to merge
10
commits into
QuantStack:main
Choose a base branch
from
Nour-Cheour10:SwipeLayer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+470
−65
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
831b904
draft swipe position
Nour-Cheour10 0c21a18
Release 0.1.0
martinRenou 55ad7b9
add as a control
Nour-Cheour10 218cb68
draft swipe position
Nour-Cheour10 ef1ee79
add as a control
Nour-Cheour10 4628e50
linting
Nour-Cheour10 3396c15
Merge branch 'SwipeLayer' of https://github.com/Nour-Cheour10/Ipy-ope…
Nour-Cheour10 bb8679e
added split map
Nour-Cheour10 9c643ca
added remove funtion
Nour-Cheour10 753d79e
model problem
Nour-Cheour10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Control from 'ol/control/Control'; | ||
import { getRenderPixel } from 'ol/render'; | ||
import 'ol/ol.css'; | ||
import '../css/widget.css'; | ||
import { MapView } from './widget'; | ||
|
||
// Interface for SplitMapControl options | ||
interface SplitMapControlOptions { | ||
target?: string; | ||
map_view?: MapView; | ||
swipe_position?: number; | ||
} | ||
|
||
export default class SplitMapControl extends Control { | ||
swipe: HTMLInputElement; | ||
leftLayer: any; | ||
map_view: MapView; | ||
private _swipe_position: number; | ||
|
||
constructor(leftLayer: any, options: SplitMapControlOptions = {}) { | ||
const element = document.createElement('div'); | ||
element.className = 'ol-unselectable ol-control split-map-control'; | ||
|
||
super({ | ||
element: element, | ||
target: options.target, | ||
}); | ||
|
||
this.leftLayer = leftLayer; | ||
|
||
if (options.map_view) { | ||
this.map_view = options.map_view; | ||
} else { | ||
throw new Error('MapView is required for SplitMapControl.'); | ||
} | ||
|
||
this._swipe_position = options.swipe_position ?? 0; | ||
|
||
const swiperContainer = document.createElement('div'); | ||
swiperContainer.className = 'swiper-container'; | ||
swiperContainer.style.width = '100%'; | ||
|
||
this.swipe = document.createElement('input'); | ||
this.swipe.type = 'range'; | ||
this.swipe.className = 'swipe'; | ||
this.swipe.style.width = '100%'; | ||
this.updateSwipeValue(); | ||
swiperContainer.appendChild(this.swipe); | ||
|
||
this.map_view.map_container.style.position = 'relative'; | ||
this.map_view.map_container.appendChild(swiperContainer); | ||
|
||
const map_view = this.map_view; | ||
|
||
this.leftLayer.on('prerender', (event: any) => { | ||
const gl = event.context; | ||
gl.enable(gl.SCISSOR_TEST); | ||
|
||
const mapSize = map_view.getSize(); | ||
|
||
if (mapSize) { | ||
const bottomLeft = getRenderPixel(event, [0, mapSize[1]]); | ||
const topRight = getRenderPixel(event, [mapSize[0], 0]); | ||
|
||
const width = Math.round( | ||
(topRight[0] - bottomLeft[0]) * (this._swipe_position / 100), | ||
); | ||
const height = topRight[1] - bottomLeft[1]; | ||
|
||
gl.scissor(bottomLeft[0], bottomLeft[1], width, height); | ||
} | ||
}); | ||
|
||
this.leftLayer.on('postrender', (event: any) => { | ||
const gl = event.context; | ||
gl.disable(gl.SCISSOR_TEST); | ||
}); | ||
|
||
this.swipe.addEventListener('input', () => { | ||
this._swipe_position = parseInt(this.swipe.value, 10); | ||
this.updateSwipeValue(); | ||
map_view.map.render(); | ||
}); | ||
} | ||
|
||
private updateSwipeValue() { | ||
if (this.swipe) { | ||
this.swipe.value = this._swipe_position.toString(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) QuantStack | ||
// Distributed under the terms of the Modified BSD License. | ||
import { unpack_models, ISerializers } from '@jupyter-widgets/base'; | ||
import { BaseControlModel, BaseControlView } from './basecontrol'; | ||
import 'ol/ol.css'; | ||
import '../css/widget.css'; | ||
import SplitMapControl from './splitcontrol'; | ||
import { MODULE_NAME, MODULE_VERSION } from './version'; | ||
|
||
export class SplitMapControlModel extends BaseControlModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
_model_name: SplitMapControlModel.model_name, | ||
_model_module: SplitMapControlModel.model_module, | ||
_model_module_version: SplitMapControlModel.model_module_version, | ||
_view_name: SplitMapControlModel.view_name, | ||
_view_module: SplitMapControlModel.view_module, | ||
_view_module_version: SplitMapControlModel.view_module_version, | ||
left_layer: undefined, | ||
right_layer: undefined, | ||
swipe_position: 50, | ||
}; | ||
} | ||
|
||
static serializers: ISerializers = { | ||
...BaseControlModel.serializers, | ||
left_layer: { deserialize: unpack_models }, | ||
right_layer: { deserialize: unpack_models }, | ||
}; | ||
|
||
static model_name = 'SplitMapControlModel'; | ||
static model_module = MODULE_NAME; | ||
static model_module_version = MODULE_VERSION; | ||
static view_name = 'SplitMapControlView'; | ||
static view_module = MODULE_NAME; | ||
static view_module_version = MODULE_VERSION; | ||
} | ||
|
||
function asArray(arg: any) { | ||
return Array.isArray(arg) ? arg : [arg]; | ||
} | ||
|
||
export class SplitMapControlView extends BaseControlView { | ||
swipe_position: number; | ||
|
||
initialize(parameters: any) { | ||
super.initialize(parameters); | ||
this.map_view = this.options.map_view; | ||
this.map_view.layer_views = this.options.map_view.layerViews; | ||
if (this.map_view && !this.map_view.layerViews) { | ||
console.warn( | ||
'Layer views is not initialized. Ensure it is properly set.', | ||
); | ||
} | ||
} | ||
|
||
createObj() { | ||
const left_models = asArray(this.model.get('left_layer')); | ||
let layersModel = this.map_view.model.get('layers'); | ||
layersModel = layersModel.concat(left_models); | ||
|
||
return this.map_view.layer_views.update(layersModel).then((views: any) => { | ||
const left_views: any[] = []; | ||
views.forEach((view: any) => { | ||
if (left_models.indexOf(view.model) !== -1) { | ||
left_views.push(view.obj); | ||
} | ||
}); | ||
|
||
this.swipe_position = this.model.get('swipe_position'); | ||
|
||
this.obj = new SplitMapControl(left_views[0], { | ||
map_view: this.map_view, | ||
swipe_position: this.swipe_position, | ||
}); | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,7 +11,8 @@ import { LayerModel, LayerView } from './layer'; | |||
import { BaseOverlayModel, BaseOverlayView } from './baseoverlay'; | ||||
import { BaseControlModel, BaseControlView } from './basecontrol'; | ||||
import { ViewObjectEventTypes } from 'ol/View'; | ||||
|
||||
import { SplitMapControlModel, SplitMapControlView } from './splitmapcontrol'; | ||||
export { SplitMapControlModel, SplitMapControlView }; | ||||
import { Map } from 'ol'; | ||||
import View from 'ol/View'; | ||||
import 'ol/ol.css'; | ||||
|
@@ -31,6 +32,8 @@ export * from './heatmap'; | |||
export * from './rastertilelayer'; | ||||
export * from './geotifflayer'; | ||||
export * from './vectortilelayer'; | ||||
export * from './splitmapcontrol'; | ||||
export * from './splitcontrol'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also you probably don't need this
Suggested change
|
||||
|
||||
const DEFAULT_LOCATION = [0.0, 0.0]; | ||||
|
||||
|
@@ -49,6 +52,7 @@ export class MapModel extends DOMWidgetModel { | |||
overlays: [], | ||||
zoom: 2, | ||||
center: DEFAULT_LOCATION, | ||||
swipe_position: 0, | ||||
}; | ||||
} | ||||
|
||||
|
@@ -96,7 +100,6 @@ export class MapView extends DOMWidgetView { | |||
this.removeLayerView, | ||||
this, | ||||
); | ||||
|
||||
this.overlayViews = new ViewList<BaseOverlayView>( | ||||
this.addOverlayModel, | ||||
this.removeOverlayView, | ||||
|
@@ -128,21 +131,22 @@ export class MapView extends DOMWidgetView { | |||
this.model.set('zoom', this.map.getView().getZoom()); | ||||
this.model.save_changes(); | ||||
}); | ||||
|
||||
this.layersChanged(); | ||||
this.overlayChanged(); | ||||
this.controlChanged(); | ||||
this.overlayChanged(); | ||||
this.zoomChanged(); | ||||
this.centerChanged(); | ||||
this.model.on('change:layers', this.layersChanged, this); | ||||
this.model.on('change:overlays', this.overlayChanged, this); | ||||
this.model.on('change:controls', this.controlChanged, this); | ||||
this.model.on('change:zoom', this.zoomChanged, this); | ||||
this.model.on('change:center', this.centerChanged, this); | ||||
} | ||||
|
||||
layersChanged() { | ||||
const layers = this.model.get('layers') as LayerModel[]; | ||||
this.layerViews.update(layers); | ||||
} | ||||
|
||||
overlayChanged() { | ||||
const overlay = this.model.get('overlays') as BaseOverlayModel[]; | ||||
this.overlayViews.update(overlay); | ||||
|
@@ -159,6 +163,10 @@ export class MapView extends DOMWidgetView { | |||
this.map.getView().setZoom(newZoom); | ||||
} | ||||
} | ||||
getSize() { | ||||
const size = this.map.getSize(); | ||||
return size; | ||||
} | ||||
|
||||
centerChanged() { | ||||
const newCenter = this.model.get('center'); | ||||
|
@@ -192,9 +200,9 @@ export class MapView extends DOMWidgetView { | |||
this.displayed.then(() => { | ||||
view.trigger('displayed', this); | ||||
}); | ||||
|
||||
return view; | ||||
} | ||||
|
||||
async addOverlayModel(child_model: BaseOverlayModel) { | ||||
const view = await this.create_child_view<BaseOverlayView>(child_model, { | ||||
map_view: this, | ||||
|
@@ -224,6 +232,7 @@ export class MapView extends DOMWidgetView { | |||
imageElement: HTMLImageElement; | ||||
map_container: HTMLDivElement; | ||||
map: Map; | ||||
map_view: MapView; | ||||
layerViews: ViewList<LayerView>; | ||||
overlayViews: ViewList<BaseOverlayView>; | ||||
controlViews: ViewList<BaseControlView>; | ||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you don't need this