|
@@ -270,9 +270,7 @@ export class olMap {
|
|
|
const xmlDoc = parser.parseFromString(res.data, 'text/xml');
|
|
|
const featureType = xmlDoc.getElementsByTagName('FeatureType')[0];
|
|
|
const layerParam = {
|
|
|
- layerName: featureType.getElementsByTagName('Title')[0].textContent,
|
|
|
- typeName: featureType.getElementsByTagName('Name')[0].textContent,
|
|
|
- srsName: featureType.getElementsByTagName('SRS')[0].textContent
|
|
|
+ typeName: featureType.getElementsByTagName('Name')[0].textContent
|
|
|
};
|
|
|
this.createWfsLayer(options, layerParam);
|
|
|
}
|
|
@@ -308,7 +306,6 @@ export class olMap {
|
|
|
// 添加自定义 Headers
|
|
|
const headers = globalHeaders();
|
|
|
xhr.setRequestHeader('Authorization', headers.Authorization);
|
|
|
- xhr.setRequestHeader('clientid', headers.clientid);
|
|
|
|
|
|
xhr.responseType = 'arraybuffer'; // 确保支持图片二进制数据
|
|
|
xhr.onload = function () {
|
|
@@ -340,20 +337,42 @@ export class olMap {
|
|
|
createWfsLayer(options, layerParam) {
|
|
|
const source = new VectorSource({
|
|
|
format: new GeoJSON(),
|
|
|
- url: `${commonUrl}${options.code}?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&typeName=流域:GEO_BAS_POLYGON&outputFormat=application/json& srsName=EPSG:4490`
|
|
|
+ loader: function (extent, resolution, projection) {
|
|
|
+ // 构建带认证头的请求参数
|
|
|
+ const url =
|
|
|
+ `${commonUrl}${options.code}?` +
|
|
|
+ `REQUEST=GetFeature` +
|
|
|
+ `&typeName=${encodeURIComponent(layerParam.typeName)}` +
|
|
|
+ `&outputFormat=application/json`;
|
|
|
+ const headers = globalHeaders();
|
|
|
+ fetch(url, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': headers.Authorization
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then((response) => {
|
|
|
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
+ return response.json();
|
|
|
+ })
|
|
|
+ .then((json) => {
|
|
|
+ const features = new GeoJSON().readFeatures(json, {
|
|
|
+ dataProjection: layerParam.srsName,
|
|
|
+ featureProjection: projection
|
|
|
+ });
|
|
|
+ this.addFeatures(features);
|
|
|
+ })
|
|
|
+ .catch(error => console.error('WFS加载失败:', error));
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
const vectorLayer = new VectorLayer({
|
|
|
source: source,
|
|
|
style: new Style({
|
|
|
- fill: new Fill({
|
|
|
- color: 'rgba(255, 255, 255, 0.6)'
|
|
|
- }),
|
|
|
- stroke: new Stroke({
|
|
|
- color: '#319FD3',
|
|
|
- width: 1
|
|
|
- })
|
|
|
- })
|
|
|
+ // 必须设置样式才能显示
|
|
|
+ fill: new Fill({ color: 'rgba(0,0,0, 0)' }),
|
|
|
+ stroke: new Stroke({ color: 'rgba(0,0,0, 1)', width: 1 })
|
|
|
+ }),
|
|
|
+ zIndex: options.zIndex ? options.zIndex : -99
|
|
|
});
|
|
|
|
|
|
this.map.addLayer(vectorLayer);
|