-
Notifications
You must be signed in to change notification settings - Fork 0
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
GSLUX-623 intégration 3D #69
Changes from 15 commits
9766834
2adae93
ce1a1a6
89455cc
2eadc41
bad24f0
d7e0304
18dce30
6e056f1
312d33f
be32c6c
098f69b
2effb94
7aaf9bd
35597cb
8c4f64f
1f80144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import MapLibreLayer from '@geoblocks/ol-maplibre-layer' | ||
import MapLibreLayer from '@/lib/ol-maplibre-layer' | ||
|
||
export declare type MapLibreLayerType = typeof MapLibreLayer |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { ImageWMS, WMTS } from 'ol/source' | |
import WmtsTileGrid from 'ol/tilegrid/WMTS' | ||
import { getTopLeft } from 'ol/extent.js' | ||
import { get as getProjection, transformExtent } from 'ol/proj' | ||
import MapLibreLayer from '@geoblocks/ol-maplibre-layer' | ||
import MapLibreLayer from '@/lib/ol-maplibre-layer' | ||
|
||
import { layersCache } from '@/stores/layers.cache' | ||
import type { Layer, LayerId } from '@/stores/map.store.model' | ||
|
@@ -67,6 +67,9 @@ function createWmsLayer(layer: Layer): ImageLayer<ImageWMS> { | |
}, | ||
source: olSource, | ||
}) | ||
olLayer.set('olcs.extent', getOlcsExtent()) | ||
olLayer.set('label', name) | ||
olLayer.set('id', id) | ||
|
||
return olLayer | ||
} | ||
|
@@ -102,6 +105,9 @@ function createWmtsLayer(layer: Layer): TileLayer<WMTS> { | |
id, | ||
}, | ||
}) | ||
olLayer.set('olcs.extent', getOlcsExtent()) | ||
olLayer.set('label', name) | ||
olLayer.set('id', id) | ||
|
||
if (layer.currentTimeMinValue) { | ||
const newLayer = | ||
|
@@ -148,15 +154,18 @@ function createVectorLayer( | |
metadata: bgLayer.metadata, | ||
}) | ||
const styleStore = useStyleStore() | ||
if (newBgBaseLayer?.maplibreMap.loaded()) { | ||
styleStore.setBaseStyle(bgLayer.id, newBgBaseLayer.getStyle()) | ||
if (newBgBaseLayer?.getMapLibreMap().loaded()) { | ||
styleStore.setBaseStyle( | ||
bgLayer.id, | ||
newBgBaseLayer?.getMapLibreMap().getStyle() | ||
) | ||
} else { | ||
new Promise(resolve => | ||
newBgBaseLayer?.maplibreMap.once('data', resolve) | ||
newBgBaseLayer?.getMapLibreMap().once('data', resolve) | ||
).then(() => | ||
styleStore.setBaseStyle( | ||
bgLayer.id, | ||
newBgBaseLayer?.maplibreMap.getStyle() | ||
newBgBaseLayer?.getMapLibreMap().getStyle() | ||
) | ||
) | ||
} | ||
|
@@ -213,7 +222,8 @@ export default function useOpenLayers() { | |
} | ||
|
||
function addLayer(olMap: OlMap, layer: Layer) { | ||
const baseLayer = getLayerFromCache(layer) | ||
if (!layer) return | ||
const baseLayer = getOrCreateLayer(layer) | ||
olMap.addLayer(baseLayer) | ||
} | ||
|
||
|
@@ -261,7 +271,7 @@ export default function useOpenLayers() { | |
layersCache.set(id, layer) | ||
} | ||
|
||
function getLayerFromCache(layer: Layer): BaseLayer { | ||
function getOrCreateLayer(layer: Layer): BaseLayer { | ||
const id = layer.id | ||
|
||
const cachedLayer = layersCache.get(id) | ||
|
@@ -274,6 +284,12 @@ export default function useOpenLayers() { | |
} | ||
} | ||
|
||
function getLayerFromCache( | ||
layer: Layer | undefined | null | ||
): BaseLayer | null { | ||
return layer ? layersCache.get(layer.id) || null : null | ||
} | ||
|
||
function applyOnBgLayer( | ||
olMap: OlMap, | ||
callbackFunction: (bgLayer: BaseLayer) => void | ||
|
@@ -295,10 +311,11 @@ export default function useOpenLayers() { | |
.getArray() | ||
.findIndex(layer => layer.getZIndex() === DEFAULT_BGZINDEX) | ||
|
||
const oldBgLayerId = mapLayers.getArray()[currentBgLayerPos]?.get('id') | ||
let bgBaseLayer: BaseLayer | undefined = undefined | ||
if (bgLayer) { | ||
if (isLayerCached(bgLayer)) { | ||
bgBaseLayer = getLayerFromCache(bgLayer) | ||
bgBaseLayer = getLayerFromCache(bgLayer)! | ||
} else { | ||
// try to create vector layer from vector sources | ||
if (vectorSources) { | ||
|
@@ -326,7 +343,9 @@ export default function useOpenLayers() { | |
olMap.addLayer(bgBaseLayer) | ||
} | ||
} | ||
statePersistorStyleService.restoreStyle(true) | ||
if (oldBgLayerId !== bgLayer?.id) { | ||
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. I don't understand how, at this point, bg layer's id cannot be different? 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. the style shall be restored from local storage when changing bg Layers. When only the style is changed, restoreStyle shall not be calles. |
||
statePersistorStyleService.restoreStyle(true) | ||
} | ||
} | ||
|
||
return { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
stylePropertyTypeList, | ||
StyleCapabilities, | ||
BgLayerDef, | ||
VectorSourceDict, | ||
VectorStyleDict, | ||
StyleSpecification, | ||
} from '@/composables/mvt-styles/mvt-styles.model' | ||
import { useStyleStore } from '@/stores/style.store' | ||
import type { Layer } from '@/stores/map.store.model' | ||
import { bgConfigFixture } from '@/__fixtures__/background.config.fixture' | ||
import BaseLayer from 'ol/layer/Base' | ||
|
@@ -32,6 +34,24 @@ | |
return isValidUUIDv4Regex.test(serial) | ||
} | ||
|
||
const styleStore = useStyleStore() | ||
function setCustomStyleSerial( | ||
bgLayer: Layer | undefined | null, | ||
serial: string | ||
) { | ||
if (bgLayer === null || bgLayer === undefined) return | ||
const newVectorSources: VectorSourceDict = new Map() | ||
styleStore.bgVectorSources.forEach((vectorSource, key) => { | ||
if (key === bgLayer.id) { | ||
const newVectorSource = { ...vectorSource, xyz_custom: serial } | ||
newVectorSources.set(key, newVectorSource) | ||
} else { | ||
newVectorSources.set(key, vectorSource) | ||
} | ||
}) | ||
styleStore.setBgVectorSources(newVectorSources) | ||
} | ||
|
||
function setConfigForLayer( | ||
label: string, | ||
keyword: string, | ||
|
@@ -168,7 +188,7 @@ | |
if (!baseStyles.get(bgLayer.id)) return | ||
const baseStyle: StyleSpecification = JSON.parse( | ||
JSON.stringify(baseStyles.get(bgLayer.id)) | ||
) as any | ||
if (!baseStyle) return | ||
if (!baseStyle || !baseStyle.layers) return | ||
if (activeStyle) { | ||
|
@@ -177,7 +197,7 @@ | |
for (const styleProperty of stylePropertyTypeList) { | ||
const props = styleItem[`${styleProperty}s`] || [] | ||
if (props.includes(layer.id)) { | ||
const basePaint: any = Object.assign( | ||
{}, | ||
baseStyle.layers[i].paint | ||
) | ||
|
@@ -199,21 +219,24 @@ | |
return baseStyle | ||
} | ||
|
||
const getvtstyleUrl_ = '/getvtstyle' | ||
const uploadvtstyleUrl_ = '/uploadvtstyle' | ||
const deletevtstyleUrl_ = '/deletevtstyle' | ||
|
||
function unregisterStyle(styleId: String | null) { | ||
function unregisterStyle( | ||
styleId: String | null, | ||
registerUrls: Map<string, string> | ||
) { | ||
if (styleId === null) { | ||
return Promise.resolve() | ||
} else { | ||
const url = `${deletevtstyleUrl_}?id=${styleId}` | ||
const url = `${registerUrls.get('delete')}?id=${styleId}` | ||
return fetch(url).catch(() => '') | ||
} | ||
} | ||
|
||
function registerStyle(style: StyleSpecification, oldStyleId: String | null) { | ||
return unregisterStyle(oldStyleId).then(() => { | ||
function registerStyle( | ||
style: StyleSpecification, | ||
oldStyleId: String | null, | ||
registerUrls: Map<string, string> | ||
) { | ||
return unregisterStyle(oldStyleId, registerUrls).then(() => { | ||
const formData = new FormData() | ||
const data = JSON.stringify(style) | ||
const blob = new Blob([data], { type: 'application/json' }) | ||
|
@@ -222,7 +245,7 @@ | |
method: 'POST', | ||
body: formData, | ||
} | ||
return fetch(uploadvtstyleUrl_, options) | ||
return fetch(registerUrls.get('upload') || '', options) | ||
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. what's the point in fetching an empty url? 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. I will never be empty, but TypeScript requests a backup value |
||
.then(response => response.json()) | ||
.then(result => { | ||
return result.id | ||
|
@@ -289,16 +312,17 @@ | |
|
||
return { | ||
getDefaultMapBoxStyleUrl, | ||
getDefaultMapBoxStyleXYZ, | ||
setConfigForLayer, | ||
getRoadStyleFromSimpleStyle, | ||
applyDefaultStyle, | ||
applyConsolidatedStyle, | ||
getVectorId, | ||
setCustomStyleSerial, | ||
unregisterStyle, | ||
registerStyle, | ||
checkSelection, | ||
isLayerStyleEditable, | ||
getStyleCapabilitiesFromLayer, | ||
getvtstyleUrl_, | ||
} | ||
} |
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.
Clean code comment.
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 will add a comment to restore the newer version when OL is updated.