Skip to content

Commit ab878ac

Browse files
[fix]intmap leaflet review by qiw
1 parent 57307af commit ab878ac

File tree

4 files changed

+5
-178
lines changed

4 files changed

+5
-178
lines changed

examples/leaflet/01_tiledMapLayer3857.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
1616
var map,
1717
url = host + '/iserver/services/map-china400/rest/maps/China';
18-
url = 'http://172.16.14.44:8090/iserver/services/map-china400/rest/maps/China';
1918

2019
// 方式一:1.调用 L.supermap.initMap,根据 SuperMap iServer 地图服务的地图信息,创建地图和底图
21-
L.supermap.initMap(url, { mapOptions: { zoom: 0 } });
20+
L.supermap.initMap(url);
2221
/*
2322
// 方式二:1.调用 L.supermap.MapService,获取 SuperMap iServer 地图服务的地图信息
2423
// 2.调用 L.supermap.crsFromMapJSON 创建 CRS

examples/leaflet/01_tiledMapLayer4326.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// 3.调用 L.map 创建地图
2525
// 4.调用 L.supermap.TiledMapLayer 创建底图
2626
new L.supermap.MapService(url).getMapInfo((res) => {
27-
var def = `GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]]`;
28-
Proj4js.defs('EPSG:4490', def);
2927
var crs = L.supermap.crsFromMapJSON(res.result);
3028
map = L.map('map', {
3129
crs: crs,

src/leaflet/mapping/initMap.js

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -264,172 +264,3 @@ function getCRS(epsgCodeStr, { bounds, dpi, resolutions }) {
264264
}
265265
return new CRS(epsgCodeStr, options);
266266
}
267-
268-
// async function getOtherEpsgCRS(url, epsgCodeStr, { bounds, dpi, visibleScales }) {
269-
// const projDef = await FetchRequest.get(`${url}/prjCoordSys.wkt`, null, {
270-
// withoutFormatSuffix: true
271-
// }).then(function (response) {
272-
// return response.text();
273-
// });
274-
// console.log(proj4def);
275-
// proj4.defs(epsgCodeStr, projDef);
276-
// return getCRS(epsgCodeStr, { bounds, dpi, visibleScales, def: projDef });
277-
// }
278-
// /**
279-
// * @private
280-
// * @function getMapOptions
281-
// * @description 获取extent。
282-
// * @param {Object} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
283-
// * @returns {Promise} Promise 对象。
284-
// */
285-
// async function getProjectionExtent(url) {
286-
// const extentInfo = await FetchRequest.get(url + '/prjCoordSys/projection/extent.json').then(function (response) {
287-
// if (response && response.status === 204) {
288-
// return null;
289-
// }
290-
// return response.json();
291-
// });
292-
// return extentInfo || null;
293-
// }
294-
295-
// /**
296-
// * @private
297-
// * @function getEnvelop
298-
// * @description 获取地图参数。
299-
// * @param {Object} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
300-
// * @param {Object} bounds - bounds。
301-
// * @returns {Promise} Promise 对象。
302-
// */
303-
// async function getEnvelop(url, bounds) {
304-
// const envelope = await getProjectionExtent(url);
305-
// if (!envelope) {
306-
// return bounds;
307-
// }
308-
// return envelope;
309-
// }
310-
311-
// /**
312-
// * @private
313-
// * @function setBaseMapCRS
314-
// * @description 作为底图后,设置底图为自定义比例尺。
315-
// * @param {L.Map} map - Leaflet Map 对象。
316-
// * @param {CRS} originCrs - 图层或地图配置的CRS。
317-
// * @param {Object} mapJSONObj - 地图 JSON 对象。
318-
// */
319-
// function getBaseMapCRS(mapJSONObj, originCrs) {
320-
// let code = typeof originCrs === 'string' ? originCrs : originCrs.code;
321-
// let { bounds, visibleScales, visibleScalesEnabled, dpi } = mapJSONObj;
322-
// if (visibleScalesEnabled) {
323-
// let crs = new CRS(code, {
324-
// dpi,
325-
// origin: [bounds.left, bounds.top],
326-
// scales: visibleScales
327-
// });
328-
// return crs;
329-
// }
330-
331-
// let crs = new CRS(code, {
332-
// dpi,
333-
// origin: [bounds.left, bounds.top],
334-
// bounds: getCRSBounds(bounds)
335-
// });
336-
// return crs;
337-
// // return originCrs;
338-
// }
339-
340-
// function getCRSBounds(bounds) {
341-
// const { left, top, bottom, right } = bounds;
342-
// return [
343-
// [left, top],
344-
// [right, bottom]
345-
// ];
346-
// }
347-
348-
// /**
349-
// * @private
350-
// * @function getLayerParams
351-
// * @description 获取图层参数。
352-
// * @param {Object} mapJSONObj - 地图 JSON 对象。
353-
// * @returns {Object} 图层参数。
354-
// */
355-
// function getLayerParams(mapJSONObj) {
356-
// const { clipRegionEnabled, clipRegion, cacheEnabled, overlapDisplayed, overlapDisplayedOptions } = mapJSONObj;
357-
// return {
358-
// clipRegionEnabled,
359-
// clipRegion,
360-
// cacheEnabled,
361-
// // prjCoordSys,
362-
// overlapDisplayed,
363-
// overlapDisplayedOptions: JSON.stringify(overlapDisplayedOptions)
364-
// };
365-
// }
366-
// /**
367-
// * @private
368-
// * @function _getMapCRS
369-
// * @description 获取mapCrs。
370-
// * @param {Object} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
371-
// * @param {Object} mapJSONObj - 地图 JSON 对象。
372-
// * @param {Object} mapJSONObj.visibleScales - visibleScales
373-
// * @param {Object} mapJSONObj.prjCoordSys - prjCoordSys
374-
// * @param {number} mapJSONObj.dpi - dpi
375-
// * @param {Object} mapJSONObj.bounds - bounds。
376-
// * @returns {Promise} Promise 对象, crs
377-
// */
378-
// function _getMapCRS({ prjCoordSys, bounds, dpi, visibleScales }, def) {
379-
// let mapcrs = L.CRS.EPSG3857;
380-
// const { type, epsgCode } = prjCoordSys;
381-
// if (epsgCode == '4326' || epsgCode == '3857') {
382-
// mapcrs = getCRS('EPSG:' + epsgCode, { bounds, dpi, visibleScales });
383-
// } else if (type == 'PCS_NON_EARTH') {
384-
// mapcrs = getNonEarthCRS(bounds);
385-
// } else {
386-
// mapcrs = getCRS(url, 'EPSG:' + epsgCode, { bounds, dpi, visibleScales });
387-
// }
388-
// return mapcrs;
389-
// }
390-
// /**
391-
// * @private
392-
// * @function getVisibleScales
393-
// * @description 获取VisibleScales。
394-
// * @param {Object} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
395-
// * @param {Object} mapJSONObj - 地图 JSON 对象。
396-
// * @param {Object} mapJSONObj.visibleScales - visibleScales
397-
// * @param {Object} mapJSONObj.prjCoordSys - prjCoordSys
398-
// * @param {number} mapJSONObj.dpi - dpi
399-
// * @param {Object} mapJSONObj.bounds - bounds。
400-
// * @param {Object} [mapOptions] - 地图参数。
401-
// * @param {Object} [mapOptions.maxZoom=22] - 地图最大缩放级别。
402-
// * @returns {Promise} Promise 对象, visibleScales。
403-
// */
404-
// function getVisibleScales({ visibleScales, prjCoordSys, dpi, bounds }, { maxZoom }) {
405-
// if (prjCoordSys && visibleScales.length == 0) {
406-
// return getScales(bounds, prjCoordSys.coordUnit, dpi, { maxZoom });
407-
// }
408-
// return visibleScales;
409-
// }
410-
// /**
411-
// * @private
412-
// * @function getMapOptions
413-
// * @description 获取地图参数。
414-
// * @param {Object} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
415-
// * @param {Object} bounds - bounds.
416-
// * @param {string} coordUnit - coordUnit
417-
// * @param {number} dpi - dpi
418-
// * @param {Object} [mapOptions] - 地图参数。
419-
// * @param {Object} [mapOptions.maxZoom=22] - 地图最大缩放级别。
420-
// * @returns {Promise} Promise 对象。
421-
// */
422-
// function getScales(bounds, coordUnit, dpi, { maxZoom }) {
423-
// const resolution = Math.abs(bounds.left - bounds.right) / 256;
424-
// let temp = resolutionToScale(resolution, dpi, coordUnit);
425-
// let scales = [];
426-
// for (let i = 0; i < maxZoom; i++) {
427-
// if (i == 0) {
428-
// scales[i] = temp;
429-
// continue;
430-
// }
431-
// temp = temp * 2;
432-
// scales[i] = temp;
433-
// }
434-
// return scales;
435-
// }

test/leaflet/mapping/initMapSpec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { initMap, crsFromMapJSON } from '../../../src/leaflet/mapping/initMap';
22
import { FetchRequest } from '../../../src/common/util/FetchRequest';
33
import { mockCreateTile } from '../../tool/mock_leaflet';
4+
import proj4 from 'proj4';
45

56
var map;
67
var def4490 = `GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]]`;
@@ -78,7 +79,7 @@ describe('initMap', () => {
7879
});
7980

8081
it('initMap 4326', async () => {
81-
var url = 'http://172.16.14.44:8090/iserver/services/map-jinjing/rest/maps/jinjing';
82+
var url = 'http://fake:8090/iserver/services/map-jinjing/rest/maps/jinjing';
8283
var mapInfo = {
8384
prjCoordSys: {
8485
distanceUnit: 'METER',
@@ -268,7 +269,7 @@ describe('initMap', () => {
268269
});
269270

270271
it('initMap 4490', async () => {
271-
var url = 'http://172.16.14.44:8090/iserver/services/map-china/rest/maps/chian4490';
272+
var url = 'http://fake:8090/iserver/services/map-china/rest/maps/chian4490';
272273
var mapInfo = {
273274
prjCoordSys: {
274275
distanceUnit: 'METER',
@@ -498,10 +499,8 @@ describe('initMap', () => {
498499
},
499500
coordUnit: 'DEGREE'
500501
};
502+
proj4.defs('EPSG:4490', def4490);
501503
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
502-
if (testUrl.includes('prjCoordSys.wkt')) {
503-
return Promise.resolve(new Response(def4490));
504-
}
505504
return Promise.resolve(new Response(JSON.stringify(mapInfo)));
506505
});
507506
var crs = await crsFromMapJSON(mapInfo);

0 commit comments

Comments
 (0)