Merge branch 'iipbs/sn/dev'
This commit is contained in:
@@ -84,6 +84,8 @@ function Gis({
|
||||
defaultLonLat = [127.4875, 37.4916],
|
||||
viewExtent,
|
||||
viewMinZoom,
|
||||
// 지정 범위 전체까지 축소를 허용한다. 기본값은 기존 타 앱의 범위 제한을 유지한다.
|
||||
viewShowFullExtent = false,
|
||||
showZoomLevel = false,
|
||||
toolBarIconSize,
|
||||
zoomGuide,
|
||||
@@ -176,6 +178,7 @@ function Gis({
|
||||
minZoom: viewMinZoom ?? gisCore.defaults.minZoom,
|
||||
maxZoom: gisCore.defaults.maxZoom,
|
||||
extent: viewExtent,
|
||||
showFullExtent: viewShowFullExtent,
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -21,11 +21,6 @@ import Tile from 'ol/layer/Tile.js';
|
||||
import TileWMS from 'ol/source/TileWMS.js';
|
||||
import gisCore from './gis.core.js';
|
||||
import { showBusinessUserMessage } from '../../../lib/user-message';
|
||||
import {
|
||||
buildFloodDngrSldBody,
|
||||
FLOOD_DNGR_MAP_LAYER_TYPE,
|
||||
getFloodDngrSldSettings,
|
||||
} from './gis.wms-sld.js';
|
||||
|
||||
/**
|
||||
* GisApp.layer
|
||||
@@ -195,19 +190,12 @@ GisOlLayer.prototype = {
|
||||
params['FORMAT'] = 'image/png';
|
||||
params['TRANSPARENT'] = true;
|
||||
params['TILED'] = true;
|
||||
// 빈 값이면 GeoServer 레이어의 기본 스타일(Default Style)로 그린다.
|
||||
// 도시침수지도(tb_ms_flood_dngr_map)의 침수심도 색상도 GeoServer에 등록한 기본 스타일을 사용하며,
|
||||
// 긴 SLD_BODY를 URL에 싣지 않아 운영 프록시의 헤더 크기 초과(502)를 피한다.
|
||||
params['STYLES'] = '';
|
||||
if (filter) params['CQL_FILTER'] = filter;
|
||||
|
||||
if (lyrTyNm === FLOOD_DNGR_MAP_LAYER_TYPE) {
|
||||
const sldSettings = getFloodDngrSldSettings(GisApp.layerCode, options?.id);
|
||||
const sldBody = buildFloodDngrSldBody(lyrTyNm, sldSettings);
|
||||
if (!sldBody) {
|
||||
console.warn('[GisApp] 도시침수지도 WMS SLD 생성에 필요한 침수심도 설정 5건이 유효하지 않습니다.', options);
|
||||
return null;
|
||||
}
|
||||
params['SLD_BODY'] = sldBody;
|
||||
}
|
||||
|
||||
const wmsLayer = new Tile({
|
||||
...layerOptions,
|
||||
id: layerOptions?.id,
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
const FLOOD_DNGR_MAP_LAYER_TYPE = 'tb_ms_flood_dngr_map';
|
||||
const FLOOD_DEPTH_ATTRIBUTE = 'sbmrg_dpthl_cd';
|
||||
const FLOOD_DEPTH_CODES = ['N330', 'N331', 'N332', 'N333', 'N334'];
|
||||
|
||||
const escapeXml = (value) => String(value ?? '')
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''');
|
||||
|
||||
const toHex = (value) => Math.round(value).toString(16).padStart(2, '0');
|
||||
|
||||
const parseCssColor = (value) => {
|
||||
const normalized = String(value ?? '').trim();
|
||||
const rgbaMatch = normalized.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(0(?:\.\d+)?|1(?:\.0+)?))?\s*\)$/i);
|
||||
if (rgbaMatch) {
|
||||
const red = Number(rgbaMatch[1]);
|
||||
const green = Number(rgbaMatch[2]);
|
||||
const blue = Number(rgbaMatch[3]);
|
||||
const opacity = rgbaMatch[4] == null ? 1 : Number(rgbaMatch[4]);
|
||||
if ([red, green, blue].some((channel) => channel < 0 || channel > 255) || opacity < 0 || opacity > 1) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
hex: `#${toHex(red)}${toHex(green)}${toHex(blue)}`,
|
||||
opacity,
|
||||
};
|
||||
}
|
||||
|
||||
const hexMatch = normalized.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
||||
if (!hexMatch) return null;
|
||||
const rawHex = hexMatch[1].length === 3
|
||||
? hexMatch[1].split('').map((character) => character + character).join('')
|
||||
: hexMatch[1];
|
||||
return {
|
||||
hex: `#${rawHex.toLowerCase()}`,
|
||||
opacity: 1,
|
||||
};
|
||||
};
|
||||
|
||||
const getFloodDepthCode = (filterSql) => {
|
||||
const match = String(filterSql ?? '').match(/\bsbmrg_dpthl_cd\s*=\s*'([^']+)'/i);
|
||||
const depthCode = match?.[1]?.trim();
|
||||
return FLOOD_DEPTH_CODES.includes(depthCode) ? depthCode : null;
|
||||
};
|
||||
|
||||
const getLineWidth = (value) => {
|
||||
const lineWidth = Number(value);
|
||||
return Number.isFinite(lineWidth) && lineWidth >= 0 && lineWidth <= 20 ? lineWidth : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 빈도 부모 레이어 바로 아래에 있는 침수심도 설정만 선별한다.
|
||||
* 부모는 WMS 요청을 담당하고, 반환된 자식 5건은 SLD 규칙의 필터와 색상 원본으로 사용한다.
|
||||
*/
|
||||
export const getFloodDngrSldSettings = (layerCode, parentLayerId) => Object.values(layerCode ?? {})
|
||||
.filter((layerSetting) => (
|
||||
String(layerSetting?.upperLyrSn ?? '') === String(parentLayerId ?? '')
|
||||
&& layerSetting?.lyrTyNm === FLOOD_DNGR_MAP_LAYER_TYPE
|
||||
))
|
||||
.sort((left, right) => Number(left?.sortOrdr ?? 0) - Number(right?.sortOrdr ?? 0));
|
||||
|
||||
/**
|
||||
* DB의 침수심도 필터와 RGBA 스타일을 GeoServer가 해석할 수 있는 SLD 1.0 XML로 변환한다.
|
||||
* 다섯 침수심도 코드나 색상값 중 하나라도 유효하지 않으면 잘못된 기본 스타일 표출을 막기 위해 null을 반환한다.
|
||||
*/
|
||||
export const buildFloodDngrSldBody = (layerName, layerSettings) => {
|
||||
if (!Array.isArray(layerSettings) || layerSettings.length !== FLOOD_DEPTH_CODES.length) return null;
|
||||
|
||||
const settingsByDepthCode = new Map();
|
||||
for (const layerSetting of layerSettings) {
|
||||
const depthCode = getFloodDepthCode(layerSetting?.flterSql);
|
||||
if (depthCode && !settingsByDepthCode.has(depthCode)) {
|
||||
settingsByDepthCode.set(depthCode, layerSetting);
|
||||
}
|
||||
}
|
||||
|
||||
if (settingsByDepthCode.size !== FLOOD_DEPTH_CODES.length) return null;
|
||||
|
||||
const rules = [];
|
||||
for (const depthCode of FLOOD_DEPTH_CODES) {
|
||||
const layerSetting = settingsByDepthCode.get(depthCode);
|
||||
const fillColor = parseCssColor(layerSetting?.polgnColor);
|
||||
const strokeColor = parseCssColor(layerSetting?.lnColor);
|
||||
const lineWidth = getLineWidth(layerSetting?.lnWdth);
|
||||
if (!fillColor || !strokeColor || lineWidth == null) return null;
|
||||
|
||||
rules.push(
|
||||
`<sld:Rule><sld:Name>${escapeXml(depthCode)}</sld:Name><sld:Title>${escapeXml(layerSetting?.lyrNm || depthCode)}</sld:Title>`
|
||||
+ `<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>${FLOOD_DEPTH_ATTRIBUTE}</ogc:PropertyName><ogc:Literal>${escapeXml(depthCode)}</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>`
|
||||
+ `<sld:PolygonSymbolizer><sld:Fill><sld:CssParameter name="fill">${fillColor.hex}</sld:CssParameter><sld:CssParameter name="fill-opacity">${fillColor.opacity}</sld:CssParameter></sld:Fill>`
|
||||
+ `<sld:Stroke><sld:CssParameter name="stroke">${strokeColor.hex}</sld:CssParameter><sld:CssParameter name="stroke-opacity">${strokeColor.opacity}</sld:CssParameter><sld:CssParameter name="stroke-width">${lineWidth}</sld:CssParameter></sld:Stroke></sld:PolygonSymbolizer></sld:Rule>`
|
||||
);
|
||||
}
|
||||
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>`
|
||||
+ `<sld:StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc">`
|
||||
+ `<sld:NamedLayer><sld:Name>${escapeXml(layerName)}</sld:Name><sld:UserStyle><sld:FeatureTypeStyle>${rules.join('')}</sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer>`
|
||||
+ `</sld:StyledLayerDescriptor>`;
|
||||
};
|
||||
|
||||
export { FLOOD_DNGR_MAP_LAYER_TYPE };
|
||||
Reference in New Issue
Block a user