wmts 수정
This commit is contained in:
@@ -2,171 +2,46 @@ package com.kamco.cd.kamcoback.layer.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/** WMS 레이어 정보를 담는 DTO 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WmsLayerInfo {
|
||||
|
||||
private String name;
|
||||
private String title;
|
||||
private String abstractText;
|
||||
private List<String> keywords;
|
||||
|
||||
private List<String> keywords = new ArrayList<>();
|
||||
private BoundingBox boundingBox;
|
||||
private List<String> crs; // 지원하는 좌표계 목록
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WmsLayerInfo{"
|
||||
+ "name='"
|
||||
+ name
|
||||
+ '\''
|
||||
+ ", title='"
|
||||
+ title
|
||||
+ '\''
|
||||
+ ", abstractText='"
|
||||
+ abstractText
|
||||
+ '\''
|
||||
+ ", keywords="
|
||||
+ keywords
|
||||
+ ", boundingBox="
|
||||
+ boundingBox
|
||||
+ ", crs="
|
||||
+ crs
|
||||
+ '}';
|
||||
}
|
||||
/** 지원하는 좌표계 목록 */
|
||||
private List<String> crs = new ArrayList<>();
|
||||
|
||||
public WmsLayerInfo() {
|
||||
this.keywords = new ArrayList<>();
|
||||
this.crs = new ArrayList<>();
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAbstractText() {
|
||||
return abstractText;
|
||||
}
|
||||
|
||||
public void setAbstractText(String abstractText) {
|
||||
this.abstractText = abstractText;
|
||||
}
|
||||
|
||||
public List<String> getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public void setKeywords(List<String> keywords) {
|
||||
this.keywords = keywords;
|
||||
}
|
||||
/* ===== convenience methods ===== */
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
this.keywords.add(keyword);
|
||||
}
|
||||
|
||||
public BoundingBox getBoundingBox() {
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
public void setBoundingBox(BoundingBox boundingBox) {
|
||||
this.boundingBox = boundingBox;
|
||||
}
|
||||
|
||||
public List<String> getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
public void setCrs(List<String> crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
public void addCrs(String crsValue) {
|
||||
this.crs.add(crsValue);
|
||||
}
|
||||
|
||||
/** BoundingBox 정보를 담는 내부 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class BoundingBox {
|
||||
|
||||
private String crs;
|
||||
private double minX;
|
||||
private double minY;
|
||||
private double maxX;
|
||||
private double maxY;
|
||||
|
||||
public BoundingBox(String crs, double minX, double minY, double maxX, double maxY) {
|
||||
this.crs = crs;
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
public void setCrs(String crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
public double getMinX() {
|
||||
return minX;
|
||||
}
|
||||
|
||||
public void setMinX(double minX) {
|
||||
this.minX = minX;
|
||||
}
|
||||
|
||||
public double getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
public void setMinY(double minY) {
|
||||
this.minY = minY;
|
||||
}
|
||||
|
||||
public double getMaxX() {
|
||||
return maxX;
|
||||
}
|
||||
|
||||
public void setMaxX(double maxX) {
|
||||
this.maxX = maxX;
|
||||
}
|
||||
|
||||
public double getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
public void setMaxY(double maxY) {
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoundingBox{"
|
||||
+ "crs='"
|
||||
+ crs
|
||||
+ '\''
|
||||
+ ", minX="
|
||||
+ minX
|
||||
+ ", minY="
|
||||
+ minY
|
||||
+ ", maxX="
|
||||
+ maxX
|
||||
+ ", maxY="
|
||||
+ maxY
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,84 +2,40 @@ package com.kamco.cd.kamcoback.layer.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/** WMTS 레이어 정보를 담는 DTO 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WmtsLayerInfo {
|
||||
|
||||
public String identifier;
|
||||
public String title;
|
||||
public String abstractText;
|
||||
public List<String> keywords = new ArrayList<>();
|
||||
public BoundingBox boundingBox;
|
||||
public List<String> formats = new ArrayList<>();
|
||||
public List<TileMatrixSetLink> tileMatrixSetLinks = new ArrayList<>();
|
||||
public List<ResourceUrl> resourceUrls = new ArrayList<>();
|
||||
public List<Style> styles = new ArrayList<>();
|
||||
// add
|
||||
public List<String> matrixIds = new ArrayList<>(); // 20250130
|
||||
public String workspace; // 20250130
|
||||
private String identifier;
|
||||
private String title;
|
||||
private String abstractText;
|
||||
|
||||
private List<String> keywords = new ArrayList<>();
|
||||
private BoundingBox boundingBox;
|
||||
|
||||
private List<String> formats = new ArrayList<>();
|
||||
private List<TileMatrixSetLink> tileMatrixSetLinks = new ArrayList<>();
|
||||
private List<ResourceUrl> resourceUrls = new ArrayList<>();
|
||||
private List<Style> styles = new ArrayList<>();
|
||||
|
||||
// add (2025-01-30)
|
||||
private List<String> matrixIds = new ArrayList<>();
|
||||
private String workspace;
|
||||
|
||||
/* ===== convenience methods ===== */
|
||||
|
||||
public void addMatrixId(String matrixId) {
|
||||
this.matrixIds.add(matrixId);
|
||||
}
|
||||
|
||||
public List<String> getMatrixIds() {
|
||||
return matrixIds;
|
||||
}
|
||||
|
||||
public void setWorkspace(String workspace) {
|
||||
this.workspace = workspace;
|
||||
}
|
||||
|
||||
public String getWorkspace() {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setAbstractText(String abstractText) {
|
||||
this.abstractText = abstractText;
|
||||
}
|
||||
|
||||
public void setBoundingBox(BoundingBox boundingBox) {
|
||||
this.boundingBox = boundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WmtsLayerInfo{"
|
||||
+ "identifier='"
|
||||
+ identifier
|
||||
+ '\''
|
||||
+ ", title='"
|
||||
+ title
|
||||
+ '\''
|
||||
+ ", abstractText='"
|
||||
+ abstractText
|
||||
+ '\''
|
||||
+ ", keywords="
|
||||
+ keywords
|
||||
+ ", boundingBox="
|
||||
+ boundingBox
|
||||
+ ", formats="
|
||||
+ formats
|
||||
+ ", tileMatrixSetLinks="
|
||||
+ tileMatrixSetLinks
|
||||
+ ", resourceUrls="
|
||||
+ resourceUrls
|
||||
+ ", styles="
|
||||
+ styles
|
||||
+ '}';
|
||||
}
|
||||
|
||||
public void addKeyword(String keywowrd) {
|
||||
this.keywords.add(keywowrd);
|
||||
public void addKeyword(String keyword) {
|
||||
this.keywords.add(keyword);
|
||||
}
|
||||
|
||||
public void addFormat(String format) {
|
||||
@@ -99,246 +55,47 @@ public class WmtsLayerInfo {
|
||||
}
|
||||
|
||||
/** BoundingBox 정보를 담는 내부 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class BoundingBox {
|
||||
|
||||
public String crs;
|
||||
public double lowerCornerX;
|
||||
public double lowerCornerY;
|
||||
public double upperCornerX;
|
||||
public double upperCornerY;
|
||||
|
||||
public BoundingBox() {}
|
||||
|
||||
public BoundingBox(
|
||||
String crs,
|
||||
double lowerCornerX,
|
||||
double lowerCornerY,
|
||||
double upperCornerX,
|
||||
double upperCornerY) {
|
||||
this.crs = crs;
|
||||
this.lowerCornerX = lowerCornerX;
|
||||
this.lowerCornerY = lowerCornerY;
|
||||
this.upperCornerX = upperCornerX;
|
||||
this.upperCornerY = upperCornerY;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
public void setCrs(String crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
public double getLowerCornerX() {
|
||||
return lowerCornerX;
|
||||
}
|
||||
|
||||
public void setLowerCornerX(double lowerCornerX) {
|
||||
this.lowerCornerX = lowerCornerX;
|
||||
}
|
||||
|
||||
public double getLowerCornerY() {
|
||||
return lowerCornerY;
|
||||
}
|
||||
|
||||
public void setLowerCornerY(double lowerCornerY) {
|
||||
this.lowerCornerY = lowerCornerY;
|
||||
}
|
||||
|
||||
public double getUpperCornerX() {
|
||||
return upperCornerX;
|
||||
}
|
||||
|
||||
public void setUpperCornerX(double upperCornerX) {
|
||||
this.upperCornerX = upperCornerX;
|
||||
}
|
||||
|
||||
public double getUpperCornerY() {
|
||||
return upperCornerY;
|
||||
}
|
||||
|
||||
public void setUpperCornerY(double upperCornerY) {
|
||||
this.upperCornerY = upperCornerY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoundingBox{"
|
||||
+ "crs='"
|
||||
+ crs
|
||||
+ '\''
|
||||
+ ", lowerCorner=["
|
||||
+ lowerCornerX
|
||||
+ ", "
|
||||
+ lowerCornerY
|
||||
+ ']'
|
||||
+ ", upperCorner=["
|
||||
+ upperCornerX
|
||||
+ ", "
|
||||
+ upperCornerY
|
||||
+ ']'
|
||||
+ '}';
|
||||
}
|
||||
private String crs;
|
||||
private double lowerCornerX;
|
||||
private double lowerCornerY;
|
||||
private double upperCornerX;
|
||||
private double upperCornerY;
|
||||
}
|
||||
|
||||
/** ResourceURL 정보를 담는 내부 클래스 (타일 URL 템플릿) */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ResourceUrl {
|
||||
|
||||
private String format;
|
||||
private String resourceType;
|
||||
private String template;
|
||||
|
||||
public ResourceUrl() {}
|
||||
|
||||
public ResourceUrl(String format, String resourceType, String template) {
|
||||
this.format = format;
|
||||
this.resourceType = resourceType;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public void setResourceType(String resourceType) {
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public void setTemplate(String template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceUrl{"
|
||||
+ "format='"
|
||||
+ format
|
||||
+ '\''
|
||||
+ ", resourceType='"
|
||||
+ resourceType
|
||||
+ '\''
|
||||
+ ", template='"
|
||||
+ template
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
/** Style 정보를 담는 내부 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Style {
|
||||
|
||||
private String identifier;
|
||||
private String title;
|
||||
private boolean isDefault;
|
||||
|
||||
public Style() {}
|
||||
|
||||
public Style(String identifier, String title, boolean isDefault) {
|
||||
this.identifier = identifier;
|
||||
this.title = title;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void setDefault(boolean isDefault) {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Style{"
|
||||
+ "identifier='"
|
||||
+ identifier
|
||||
+ '\''
|
||||
+ ", title='"
|
||||
+ title
|
||||
+ '\''
|
||||
+ ", isDefault="
|
||||
+ isDefault
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
/** TileMatrixSetLink 정보를 담는 내부 클래스 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TileMatrixSetLink {
|
||||
|
||||
private String tileMatrixSet;
|
||||
private List<String> zoomLevels;
|
||||
|
||||
public TileMatrixSetLink() {
|
||||
this.zoomLevels = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TileMatrixSetLink(String tileMatrixSet, List<String> zoomLevels) {
|
||||
this.tileMatrixSet = tileMatrixSet;
|
||||
this.zoomLevels = zoomLevels != null ? zoomLevels : new ArrayList<>();
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getTileMatrixSet() {
|
||||
return tileMatrixSet;
|
||||
}
|
||||
|
||||
public void setTileMatrixSet(String tileMatrixSet) {
|
||||
this.tileMatrixSet = tileMatrixSet;
|
||||
}
|
||||
|
||||
public List<String> getZoomLevels() {
|
||||
return zoomLevels;
|
||||
}
|
||||
|
||||
public void setZoomLevels(List<String> zoomLevels) {
|
||||
this.zoomLevels = zoomLevels;
|
||||
}
|
||||
private List<String> zoomLevels = new ArrayList<>();
|
||||
|
||||
public void addZoomLevel(String zoomLevel) {
|
||||
this.zoomLevels.add(zoomLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TileMatrixSetLink{"
|
||||
+ "tileMatrixSet='"
|
||||
+ tileMatrixSet
|
||||
+ '\''
|
||||
+ ", zoomLevels="
|
||||
+ zoomLevels
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class WmtsService {
|
||||
List<String> titles = new ArrayList<>();
|
||||
|
||||
for (WmtsLayerInfo layer : layers) {
|
||||
titles.add(layer.title);
|
||||
titles.add(layer.getTitle()); // ✅ getter로 변경
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
@@ -60,9 +60,9 @@ public class WmtsService {
|
||||
public List<WmtsLayerInfo> getAllLayers(String geoserverUrl, String workspace) {
|
||||
List<WmtsLayerInfo> layers = new ArrayList<>();
|
||||
try {
|
||||
// 1. XML 문서 로드 및 파싱
|
||||
String capabilitiesUrl =
|
||||
geoserverUrl + WMTS_GEOSERVER_URL + workspace + WMTS_CAPABILITIES_URL;
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
@@ -71,12 +71,10 @@ public class WmtsService {
|
||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xPathFactory.newXPath();
|
||||
|
||||
// 2. 모든 Layer 노드 검색
|
||||
String expression = "//*[local-name()='Layer']";
|
||||
NodeList layerNodes =
|
||||
(NodeList) xpath.compile(expression).evaluate(doc, XPathConstants.NODESET);
|
||||
|
||||
// 3. 모든 레이어를 파싱하여 리스트에 추가
|
||||
for (int i = 0; i < layerNodes.getLength(); i++) {
|
||||
Node layerNode = layerNodes.item(i);
|
||||
String title = getChildValue(layerNode, "Title");
|
||||
@@ -96,28 +94,25 @@ public class WmtsService {
|
||||
}
|
||||
|
||||
/**
|
||||
* WMTS Capabilities URL에서 특정 타이틀의 레이어 정보를 가져옵니다. // * @param capabilitiesUrl 예:
|
||||
* http://localhost:8080/geoserver/gwc/service/wmts?REQUEST=GetCapabilities
|
||||
* WMTS Capabilities URL에서 특정 타이틀의 레이어 정보를 가져옵니다.
|
||||
*
|
||||
* @param geoserverUrl 예: http://localhost:8080
|
||||
* @param targetTitle 찾고자 하는 레이어의 Title (예: "My Maps")
|
||||
* @param targetTitle 찾고자 하는 레이어의 Title
|
||||
*/
|
||||
public WmtsLayerInfo getLayerInfoByTitle(
|
||||
String geoserverUrl, String workspace, String targetTitle) {
|
||||
try {
|
||||
// 1. XML 문서 로드 및 파싱
|
||||
String capabilitiesUrl =
|
||||
geoserverUrl + WMTS_GEOSERVER_URL + workspace + WMTS_CAPABILITIES_URL;
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true); // 네임스페이스 인식
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new URL(capabilitiesUrl).openStream());
|
||||
|
||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xPathFactory.newXPath();
|
||||
|
||||
// 2. 모든 Layer 노드 검색 (네임스페이스 무시하고 local-name으로 검색)
|
||||
// GeoServer WMTS에서 Layer는 <Contents> -> <Layer> 구조임
|
||||
String expression = "//*[local-name()='Layer']";
|
||||
NodeList layerNodes =
|
||||
(NodeList) xpath.compile(expression).evaluate(doc, XPathConstants.NODESET);
|
||||
@@ -125,10 +120,7 @@ public class WmtsService {
|
||||
for (int i = 0; i < layerNodes.getLength(); i++) {
|
||||
Node layerNode = layerNodes.item(i);
|
||||
|
||||
// 3. Title 확인
|
||||
String title = getChildValue(layerNode, "Title");
|
||||
|
||||
// 타이틀이 일치하면 객체 매핑 시작
|
||||
if (title != null && title.trim().equals(targetTitle)) {
|
||||
return parseLayerNode(workspace, layerNode, title);
|
||||
}
|
||||
@@ -139,38 +131,38 @@ public class WmtsService {
|
||||
throw new RuntimeException("WMTS 정보 조회 중 오류 발생: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null; // 찾지 못한 경우
|
||||
return null;
|
||||
}
|
||||
|
||||
// 레이어 노드를 Java 객체로 변환 20250130
|
||||
// 레이어 노드를 Java 객체로 변환 (2025-01-30)
|
||||
private WmtsLayerInfo parseLayerNode(String workspace, Node layerNode, String title) {
|
||||
WmtsLayerInfo info = new WmtsLayerInfo();
|
||||
info.workspace = workspace; // 20250130
|
||||
info.title = title;
|
||||
info.identifier = getChildValue(layerNode, "Identifier");
|
||||
info.abstractText = getChildValue(layerNode, "Abstract");
|
||||
|
||||
info.setWorkspace(workspace); // 20250130
|
||||
info.setTitle(title);
|
||||
info.setIdentifier(getChildValue(layerNode, "Identifier"));
|
||||
info.setAbstractText(getChildValue(layerNode, "Abstract"));
|
||||
|
||||
// Keywords 파싱
|
||||
// 구조: <ows:Keywords><ows:Keyword>...</ows:Keyword></ows:Keywords>
|
||||
info.keywords = getChildValues(layerNode, "Keywords", "Keyword");
|
||||
info.setKeywords(getChildValues(layerNode, "Keywords", "Keyword"));
|
||||
|
||||
// BoundingBox 파싱 (WGS84BoundingBox 기준)
|
||||
info.boundingBox = parseBoundingBox(layerNode);
|
||||
info.setBoundingBox(parseBoundingBox(layerNode));
|
||||
|
||||
// Formats 파싱
|
||||
info.formats = getChildValuesDirect(layerNode, "Format");
|
||||
info.setFormats(getChildValuesDirect(layerNode, "Format"));
|
||||
|
||||
// TileMatrixSetLink 파싱 (TileMatrixSet + Zoom Levels)
|
||||
info.tileMatrixSetLinks = parseTileMatrixSetLinks(layerNode);
|
||||
info.setTileMatrixSetLinks(parseTileMatrixSetLinks(layerNode));
|
||||
|
||||
// TileMatrixSetLimits에서 줌 레벨 추출 (개별 zoom 리스트)
|
||||
info.matrixIds = parseMatrixIds(layerNode); // 20260130
|
||||
// TileMatrixSetLimits에서 줌 레벨 추출
|
||||
info.setMatrixIds(parseMatrixIds(layerNode)); // 20260130
|
||||
|
||||
// ResourceURL 파싱
|
||||
info.resourceUrls = parseResourceUrls(layerNode);
|
||||
info.setResourceUrls(parseResourceUrls(layerNode));
|
||||
|
||||
// Styles 파싱
|
||||
info.styles = parseStyles(layerNode);
|
||||
info.setStyles(parseStyles(layerNode));
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -178,38 +170,40 @@ public class WmtsService {
|
||||
// --- Helper Methods ---
|
||||
|
||||
private WmtsLayerInfo.BoundingBox parseBoundingBox(Node layerNode) {
|
||||
// 보통 <ows:WGS84BoundingBox>를 찾음
|
||||
Node bboxNode = findChildNode(layerNode, "WGS84BoundingBox");
|
||||
if (bboxNode == null) bboxNode = findChildNode(layerNode, "BoundingBox");
|
||||
|
||||
if (bboxNode != null) {
|
||||
WmtsLayerInfo.BoundingBox bbox = new WmtsLayerInfo.BoundingBox();
|
||||
bbox.crs = getAttributeValue(bboxNode, "crs"); // WGS84는 보통 CRS 속성이 없을 수 있음(Default EPSG:4326)
|
||||
if (bboxNode == null) return null;
|
||||
|
||||
String lowerCorner = getChildValue(bboxNode, "LowerCorner");
|
||||
String upperCorner = getChildValue(bboxNode, "UpperCorner");
|
||||
WmtsLayerInfo.BoundingBox bbox = new WmtsLayerInfo.BoundingBox();
|
||||
|
||||
if (lowerCorner != null) {
|
||||
String[] coords = lowerCorner.split(" ");
|
||||
bbox.lowerCornerX = Double.parseDouble(coords[0]);
|
||||
bbox.lowerCornerY = Double.parseDouble(coords[1]);
|
||||
}
|
||||
if (upperCorner != null) {
|
||||
String[] coords = upperCorner.split(" ");
|
||||
bbox.upperCornerX = Double.parseDouble(coords[0]);
|
||||
bbox.upperCornerY = Double.parseDouble(coords[1]);
|
||||
}
|
||||
return bbox;
|
||||
bbox.setCrs(getAttributeValue(bboxNode, "crs"));
|
||||
|
||||
String lowerCorner = getChildValue(bboxNode, "LowerCorner");
|
||||
String upperCorner = getChildValue(bboxNode, "UpperCorner");
|
||||
|
||||
if (lowerCorner != null) {
|
||||
String[] coords = lowerCorner.trim().split("\\s+");
|
||||
bbox.setLowerCornerX(Double.parseDouble(coords[0]));
|
||||
bbox.setLowerCornerY(Double.parseDouble(coords[1]));
|
||||
}
|
||||
return null;
|
||||
|
||||
if (upperCorner != null) {
|
||||
String[] coords = upperCorner.trim().split("\\s+");
|
||||
bbox.setUpperCornerX(Double.parseDouble(coords[0]));
|
||||
bbox.setUpperCornerY(Double.parseDouble(coords[1]));
|
||||
}
|
||||
|
||||
return bbox;
|
||||
}
|
||||
|
||||
private List<WmtsLayerInfo.ResourceUrl> parseResourceUrls(Node layerNode) {
|
||||
List<WmtsLayerInfo.ResourceUrl> list = new ArrayList<>();
|
||||
NodeList children = layerNode.getChildNodes();
|
||||
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeName().contains("ResourceURL")) { // local-name check simplification
|
||||
if (node.getNodeName().contains("ResourceURL")) {
|
||||
WmtsLayerInfo.ResourceUrl url = new WmtsLayerInfo.ResourceUrl();
|
||||
url.setFormat(getAttributeValue(node, "format"));
|
||||
url.setResourceType(getAttributeValue(node, "resourceType"));
|
||||
@@ -223,6 +217,7 @@ public class WmtsService {
|
||||
private List<WmtsLayerInfo.Style> parseStyles(Node layerNode) {
|
||||
List<WmtsLayerInfo.Style> styles = new ArrayList<>();
|
||||
NodeList children = layerNode.getChildNodes();
|
||||
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeName().endsWith("Style")) {
|
||||
@@ -236,34 +231,23 @@ public class WmtsService {
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* TileMatrixSetLimits에서 줌 레벨을 추출합니다. 예: "EPSG:4326:0" → "0", "EPSG:4326:1" → "1"
|
||||
*
|
||||
* @param layerNode Layer 노드
|
||||
* @return 줌 레벨 문자열 리스트
|
||||
*/
|
||||
/** TileMatrixSetLimits에서 줌 레벨을 추출합니다. 예: "EPSG:4326:0" → "0" */
|
||||
private List<String> parseMatrixIds(Node layerNode) {
|
||||
List<String> matrixIds = new ArrayList<>();
|
||||
NodeList children = layerNode.getChildNodes();
|
||||
|
||||
// 모든 TileMatrixSetLink 찾기
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeName().contains("TileMatrixSetLink")) {
|
||||
// TileMatrixSetLimits 찾기
|
||||
Node limitsNode = findChildNode(node, "TileMatrixSetLimits");
|
||||
if (limitsNode != null) {
|
||||
NodeList limitsList = limitsNode.getChildNodes();
|
||||
// 각 TileMatrixLimits 처리
|
||||
for (int j = 0; j < limitsList.getLength(); j++) {
|
||||
Node limitNode = limitsList.item(j);
|
||||
if (limitNode.getNodeName().contains("TileMatrixLimits")) {
|
||||
// TileMatrix 또는 Identifier 값 추출
|
||||
String identifier = getChildValue(limitNode, "TileMatrix");
|
||||
if (identifier == null) {
|
||||
identifier = getChildValue(limitNode, "Identifier");
|
||||
}
|
||||
// 마지막 콜론 이후 값(줌 레벨) 추출
|
||||
if (identifier == null) identifier = getChildValue(limitNode, "Identifier");
|
||||
|
||||
if (identifier != null && identifier.contains(":")) {
|
||||
String[] parts = identifier.split(":");
|
||||
String zoomLevel = parts[parts.length - 1];
|
||||
@@ -278,25 +262,16 @@ public class WmtsService {
|
||||
return matrixIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* TileMatrixSetLink 정보를 파싱합니다. 각 TileMatrixSetLink에서 TileMatrixSet 이름과 줌 레벨들을 추출합니다.
|
||||
*
|
||||
* @param layerNode Layer 노드
|
||||
* @return TileMatrixSetLink 객체 리스트
|
||||
*/
|
||||
private List<WmtsLayerInfo.TileMatrixSetLink> parseTileMatrixSetLinks(Node layerNode) {
|
||||
List<WmtsLayerInfo.TileMatrixSetLink> links = new ArrayList<>();
|
||||
NodeList children = layerNode.getChildNodes();
|
||||
|
||||
// 모든 TileMatrixSetLink 찾기
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeName().contains("TileMatrixSetLink")) {
|
||||
|
||||
// TileMatrixSet 이름 추출
|
||||
String tileMatrixSet = getChildValue(node, "TileMatrixSet");
|
||||
|
||||
// 줌 레벨들 추출
|
||||
List<String> zoomLevels = new ArrayList<>();
|
||||
Node limitsNode = findChildNode(node, "TileMatrixSetLimits");
|
||||
if (limitsNode != null) {
|
||||
@@ -304,12 +279,9 @@ public class WmtsService {
|
||||
for (int j = 0; j < limitsList.getLength(); j++) {
|
||||
Node limitNode = limitsList.item(j);
|
||||
if (limitNode.getNodeName().contains("TileMatrixLimits")) {
|
||||
// TileMatrix 또는 Identifier 값 추출
|
||||
String identifier = getChildValue(limitNode, "TileMatrix");
|
||||
if (identifier == null) {
|
||||
identifier = getChildValue(limitNode, "Identifier");
|
||||
}
|
||||
// 마지막 콜론 이후 값(줌 레벨) 추출
|
||||
if (identifier == null) identifier = getChildValue(limitNode, "Identifier");
|
||||
|
||||
if (identifier != null && identifier.contains(":")) {
|
||||
String[] parts = identifier.split(":");
|
||||
String zoomLevel = parts[parts.length - 1];
|
||||
@@ -319,7 +291,6 @@ public class WmtsService {
|
||||
}
|
||||
}
|
||||
|
||||
// TileMatrixSetLink 객체 생성 및 추가
|
||||
if (tileMatrixSet != null) {
|
||||
WmtsLayerInfo.TileMatrixSetLink link =
|
||||
new WmtsLayerInfo.TileMatrixSetLink(tileMatrixSet, zoomLevels);
|
||||
@@ -331,16 +302,15 @@ public class WmtsService {
|
||||
return links;
|
||||
}
|
||||
|
||||
// 특정 노드 아래의 자식 태그 값 추출 (예: <Title>값)
|
||||
private String getChildValue(Node parent, String childName) {
|
||||
Node child = findChildNode(parent, childName);
|
||||
return (child != null) ? child.getTextContent() : null;
|
||||
}
|
||||
|
||||
// 특정 노드 아래의 반복되는 자식 구조 값 추출 (예: Keywords -> Keyword)
|
||||
private List<String> getChildValues(Node parent, String wrapperName, String childName) {
|
||||
List<String> results = new ArrayList<>();
|
||||
Node wrapper = findChildNode(parent, wrapperName);
|
||||
|
||||
if (wrapper != null) {
|
||||
NodeList children = wrapper.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
@@ -353,10 +323,10 @@ public class WmtsService {
|
||||
return results;
|
||||
}
|
||||
|
||||
// Wrapper 없이 바로 반복되는 값 추출 (예: Format)
|
||||
private List<String> getChildValuesDirect(Node parent, String childName) {
|
||||
List<String> results = new ArrayList<>();
|
||||
NodeList children = parent.getChildNodes();
|
||||
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeName().endsWith(childName)) {
|
||||
@@ -366,12 +336,10 @@ public class WmtsService {
|
||||
return results;
|
||||
}
|
||||
|
||||
// 이름으로 자식 노드 찾기 (Local Name 기준)
|
||||
private Node findChildNode(Node parent, String localName) {
|
||||
NodeList children = parent.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
// 네임스페이스 접두사(ows:, wmts:)를 무시하고 태그 이름 확인
|
||||
if (node.getNodeName().endsWith(":" + localName) || node.getNodeName().equals(localName)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user