Skip to content

Commit

Permalink
【feature】leaflet initmap 对接tileset
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng authored and xilanhuaweidapao committed Jan 4, 2024
1 parent 460bd4b commit 468dc2f
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 224 deletions.
18 changes: 13 additions & 5 deletions src/common/iServer/InitMapServiceBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ export class InitMapServiceBase {
* @returns {Promise}
*/
getMapInfo(callback) {
return new Promise((resolve, reject) => {
const mapService = this.createMapService();
mapService.getMapInfo((res) => {
callback(res, resolve, reject);
const mapService = this.createMapService();
if(callback){
return new Promise((resolve, reject) => {
mapService.getMapInfo((res) => {
callback(res, resolve, reject);
});
});
});
}
return mapService.getMapInfo();

}

getTilesets() {
return this.createMapService().getTilesets();
}

/**
Expand Down
23 changes: 22 additions & 1 deletion src/common/util/MapCalculateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,26 @@ export function conversionDegree(degrees) {
* const result = scalesToResolutions(scales, bounds, dpi, mapUnit);
* ```
*/
export function scalesToResolutions(scales, bounds, dpi, mapUnit, level = 22) {
export function scalesToResolutions(scales, bounds, dpi, mapUnit, level = 22, baseScale) {
var resolutions = [];
if (scales && scales.length > 0) {
for (let i = 0; i < scales.length; i++) {
resolutions.push(scaleToResolution(scales[i], dpi, mapUnit));
}
} else if (baseScale){
const maxReolution = Math.abs(bounds.left - bounds.right) / 256;
const baseRes = scaleToResolution(baseScale, dpi, mapUnit);
let topRes = baseRes;
for (let i = 0; i < level; i++) {
const temp = baseRes * Math.pow(2, i);
if(Math.abs(temp,maxReolution)<= 1E-6 || temp>maxReolution){
topRes = temp;
break;
}
}
for (let i = 0; i < level; i++) {
resolutions.push(topRes / Math.pow(2, i));
}
} else {
const maxReolution = Math.abs(bounds.left - bounds.right) / 256;
for (let i = 0; i < level; i++) {
Expand Down Expand Up @@ -220,6 +234,13 @@ export function scaleToResolution(scale, dpi, mapUnit) {
return resolution;
}

export function getDpi(scale, resolution, mapUnit) {
const inchPerMeter = 1 / 0.0254;
const meterPerMapUnitValue = getMeterPerMapUnit(mapUnit);
const dpi = 1.0/resolution/(scale * inchPerMeter * meterPerMapUnitValue);
return dpi;
}

/**
* 范围是否相交。
* @param {Array} extent1 范围 1。
Expand Down
6 changes: 4 additions & 2 deletions src/leaflet/core/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import {
getMeterPerMapUnit as MeterPerMapUnit,
getZoomByResolution,
scalesToResolutions
scalesToResolutions,
getDpi
} from '@supermap/iclient-common/util/MapCalculateUtil';

/**
Expand Down Expand Up @@ -230,5 +231,6 @@ export var getResolutionFromScaleDpi = function(scale, dpi, coordUnit, datumAxis
};
export {
getZoomByResolution,
scalesToResolutions
scalesToResolutions,
getDpi
}
Loading

0 comments on commit 468dc2f

Please sign in to comment.