MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / addGeojsonFromUrl

Method addGeojsonFromUrl

src/openlayers/mapping/WebMap.js:2279–2338  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.addGeojsonFromUrl * @description 从web服务输入geojson地址的图层 * @param {Object} layerInfo - 图层信息 * @param {number} len - 总的图层数量 * @param {number} layerIndex - 当前图层index

(layerInfo, len, layerIndex)

Source from the content-addressed store, hash-verified

2277 * @param {number} layerIndex - 当前图层index
2278 */
2279 addGeojsonFromUrl(layerInfo, len, layerIndex) {
2280 // 通过web添加geojson不需要携带cookie
2281 let { dataSource } = layerInfo,
2282 { url } = dataSource,
2283 that = this;
2284 FetchRequest.get(url, null, {
2285 withCredentials: that.isCredentail(url),
2286 withoutFormatSuffix: true
2287 })
2288 .then(function (response) {
2289 return response.json();
2290 })
2291 .then(async function (data) {
2292 if (!data || data.succeed === false) {
2293 //请求失败
2294 if (len) {
2295 that.errorCallback && that.errorCallback(data.error, 'autoUpdateFaild', that.map);
2296 } else {
2297 that.layerAdded++;
2298 that.sendMapToUser(len);
2299 that.errorCallback && that.errorCallback(data.error, 'getLayerFaild', that.map);
2300 }
2301 return;
2302 }
2303 var features;
2304 if (data.type === 'CSV' || data.type === 'EXCEL') {
2305 if (layerInfo.dataSource && layerInfo.dataSource.administrativeInfo) {
2306 //行政规划信息
2307 data.content.rows.unshift(data.content.colTitles);
2308 let { divisionType, divisionField } = layerInfo.dataSource.administrativeInfo;
2309 let geojson = that.excelData2FeatureByDivision(data.content, divisionType, divisionField);
2310 features = that._parseGeoJsonData2Feature({
2311 allDatas: { features: geojson.features },
2312 fileCode: layerInfo.projection
2313 });
2314 } else {
2315 features = await that.excelData2Feature(data.content, layerInfo);
2316 }
2317 } else {
2318 var geoJson = data.content ? JSON.parse(data.content) : data;
2319 features = that.geojsonToFeature(geoJson, layerInfo);
2320 }
2321 if (len) {
2322 //上图
2323 await that.addLayer(layerInfo, features, layerIndex);
2324 that.layerAdded++;
2325 that.sendMapToUser(len);
2326 } else {
2327 //自动更新
2328 that.map.removeLayer(layerInfo.layer);
2329 layerInfo.labelLayer && that.map.removeLayer(layerInfo.labelLayer);
2330 await that.addLayer(layerInfo, features, layerIndex);
2331 }
2332 })
2333 .catch(function (error) {
2334 that.layerAdded++;
2335 that.sendMapToUser(len);
2336 that.errorCallback && that.errorCallback(error, 'getLayerFaild', that.map);

Callers 2

addLayersMethod · 0.80
updateFeaturesToMapMethod · 0.80

Calls 10

isCredentailMethod · 0.80
sendMapToUserMethod · 0.80
excelData2FeatureMethod · 0.80
geojsonToFeatureMethod · 0.80
getMethod · 0.45
parseMethod · 0.45
addLayerMethod · 0.45
removeLayerMethod · 0.45

Tested by

no test coverage detected