Skip to content

Commit bd7b9d2

Browse files
webmapv2 添加栅格图层时增加bounds配置 review by luox
1 parent 4c73149 commit bd7b9d2

File tree

3 files changed

+136
-17
lines changed

3 files changed

+136
-17
lines changed

src/common/mapping/WebMapService.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ export class WebMapService {
183183
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' });
184184
const capabilities = parser.parse(capabilitiesText);
185185
const wmsCapabilities = capabilities.WMT_MS_Capabilities || capabilities.WMS_Capabilities;
186-
resolve({ version: wmsCapabilities['@_version'] });
186+
const latlonBounds = wmsCapabilities['Capability']['Layer']['LatLonBoundingBox'];
187+
let bounds = null;
188+
if (latlonBounds) {
189+
bounds = [+latlonBounds['@_minx'], +latlonBounds['@_miny'], +latlonBounds['@_maxx'], +latlonBounds['@_maxy']];
190+
}
191+
const EX_GeographicBoundingBox = wmsCapabilities['Capability']['Layer']['EX_GeographicBoundingBox'];
192+
if (EX_GeographicBoundingBox) {
193+
bounds = [+EX_GeographicBoundingBox['westBoundLongitude'], +EX_GeographicBoundingBox['southBoundLatitude'], +EX_GeographicBoundingBox['eastBoundLongitude'], +EX_GeographicBoundingBox['northBoundLatitude']];
194+
}
195+
resolve({ version: wmsCapabilities['@_version'], bounds });
187196
});
188197
});
189198
}

src/common/mapping/WebMapV2.js

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { FetchRequest } from '../util/FetchRequest';
1010
import { SourceListModelV2 } from './utils/SourceListModelV2';
1111
import { isSameRasterLayer, mergeFeatures } from './utils/util';
1212

13+
const INTERNET_MAP_BOUNDS = {
14+
TIANDITU: [-180, -90, 180, 90],
15+
OSM: [-180, -90, 180, 90],
16+
GOOGLE_CN: [-180, -90, 180, 90],
17+
BING: [-180, -90, 180, 90]
18+
}
19+
1320
export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
1421
return class WebMapV2 extends SuperClass {
1522
constructor(
@@ -592,13 +599,15 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
592599
const isLabel = Boolean(labelLayerVisible);
593600
const labelUrl = tiandituUrls.labelUrl;
594601
const tiandituUrl = tiandituUrls.tiandituUrl;
595-
this._addBaselayer({ url: tiandituUrl, layerID: name, visibility: visible });
602+
const bounds = INTERNET_MAP_BOUNDS['TIANDITU'];
603+
this._addBaselayer({ url: tiandituUrl, layerID: name, visibility: visible, bounds });
596604
isLabel &&
597605
this._addBaselayer({
598606
url: labelUrl,
599607
layerID: this._getTdtLabelLayerName(name),
600608
parentLayerId: name,
601-
visibility: visible
609+
visibility: visible,
610+
bounds
602611
});
603612
addedCallback && addedCallback();
604613
}
@@ -651,7 +660,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
651660
return imageUrl;
652661
});
653662

654-
this._addBaselayer({ url: urls, layerID: layerName, visibility: layerInfo.visible });
663+
this._addBaselayer({ url: urls, layerID: layerName, visibility: layerInfo.visible, bounds: INTERNET_MAP_BOUNDS['BING'] });
655664
addedCallback && addedCallback();
656665
}
657666

@@ -690,23 +699,53 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
690699
urlArr = [url];
691700
}
692701
const layerId = layerInfo.layerID || layerInfo.name;
693-
this._addBaselayer({ url: urlArr, layerID: layerId, visibility: layerInfo.visible });
702+
this._addBaselayer({ url: urlArr, layerID: layerId, visibility: layerInfo.visible, bounds: INTERNET_MAP_BOUNDS[layerInfo.layerType] || [-180, -90, 180, 90] });
694703
addedCallback && addedCallback();
695704
}
696705

697706
_createDynamicTiledLayer(layerInfo, addedCallback) {
698707
const url = layerInfo.url;
699708
const layerId = layerInfo.layerID || layerInfo.name;
700709
const { minzoom, maxzoom } = layerInfo;
701-
this._addBaselayer({
702-
url: [url],
703-
layerID: layerId,
704-
visibility: layerInfo.visible,
705-
minzoom,
706-
maxzoom,
707-
isIserver: true
710+
this.getBounds(`${url}.json`, {
711+
withoutFormatSuffix: true,
712+
withCredentials: this.webMapService.handleWithCredentials('', url, false)
713+
}).then((res) => {
714+
let bounds = null;
715+
if (res && res.bounds) {
716+
bounds = [
717+
res.bounds.left,
718+
res.bounds.bottom,
719+
res.bounds.right,
720+
res.bounds.top
721+
];
722+
const epsgCode = res.prjCoordSys.epsgCode;
723+
if (epsgCode !== 4326) {
724+
const [left, bottom] = this._unproject(
725+
[res.bounds.left, res.bounds.bottom]
726+
);
727+
const [right, top] = this._unproject(
728+
[res.bounds.right, res.bounds.top]
729+
);
730+
bounds = [
731+
left,
732+
bottom,
733+
right,
734+
top
735+
];
736+
}
737+
}
738+
this._addBaselayer({
739+
url: [url],
740+
layerID: layerId,
741+
visibility: layerInfo.visible,
742+
minzoom,
743+
maxzoom,
744+
isIserver: true,
745+
bounds
746+
});
747+
addedCallback && addedCallback();
708748
});
709-
addedCallback && addedCallback();
710749
}
711750

712751
_createWMSLayer(layerInfo, addedCallback) {
@@ -717,7 +756,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
717756
const layerId = layerInfo.layerID || layerInfo.name;
718757
if (result) {
719758
const wmsUrl = this._getWMSUrl(layerInfo, result.version);
720-
this._addBaselayer({ url: [wmsUrl], layerID: layerId, visibility: layerInfo.visible });
759+
this._addBaselayer({ url: [wmsUrl], layerID: layerId, visibility: layerInfo.visible, bounds: result.bounds });
721760
addedCallback && addedCallback();
722761
}
723762
},
@@ -1244,9 +1283,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
12441283
this.map.getSource(layerInfo.layerID) && !addSource
12451284
? layerInfo.layerID
12461285
: {
1247-
type: 'geojson',
1248-
data: { type: 'FeatureCollection', features: features }
1249-
},
1286+
type: 'geojson',
1287+
data: { type: 'FeatureCollection', features: features }
1288+
},
12501289
paint: {
12511290
'text-color': labelStyle.fill,
12521291
'text-halo-color': textHaloColor,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy