Skip to content

Commit 53f8a43

Browse files
author
ParnDeedlit&潘卓然
committed
【SDK】【修复】【修复MapboxGL客户端专题图的坐标动态投影变换】
1 parent cd63bba commit 53f8a43

File tree

7 files changed

+220
-28
lines changed

7 files changed

+220
-28
lines changed

src/mapboxgl/MapExtend.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import mapboxgl from '@mapgis/mapbox-gl';
2+
13
/**
24
* @function mapboxgl.Zondy.MapExtend
35
* @description 扩展了 mapboxgl.Map 对图层相关的操作。
46
* @private
57
*/
68
export var MapExtend = function () {
79

8-
window.mapboxgl.Map.prototype.overlayLayersManager = {};
9-
// window.mapboxgl.Map.prototype.addLayerBak = window.mapboxgl.Map.prototype.addLayerBak;
10-
window.mapboxgl.Map.prototype.addLayer = function (layer, before) {
10+
mapboxgl.Map.prototype.overlayLayersManager = {};
11+
// mapboxgl.Map.prototype.addLayerBak = mapboxgl.Map.prototype.addLayerBak;
12+
mapboxgl.Map.prototype.addLayer = function (layer, before) {
1113
if (layer.source || layer.type === 'custom' || layer.type === "background") {
1214
this.addLayerBak(layer, before);
1315
return this;
@@ -18,18 +20,19 @@ export var MapExtend = function () {
1820
});
1921
return;
2022
}
21-
addLayer(layer, this);
23+
// addLayer(layer, this);
24+
this._addLayer(layer, this);
2225
this.overlayLayersManager[layer.id] = layer;
2326
return this;
2427
};
25-
window.mapboxgl.Map.prototype.getLayer = function (id) {
28+
mapboxgl.Map.prototype.getLayer = function (id) {
2629
if (this.overlayLayersManager[id]) {
2730
return this.overlayLayersManager[id];
2831
}
2932
return this.style.getLayer(id);
3033
};
3134

32-
window.mapboxgl.Map.prototype.moveLayer = function (id, beforeId) {
35+
mapboxgl.Map.prototype.moveLayer = function (id, beforeId) {
3336
if (this.overlayLayersManager[id]) {
3437
moveLayer(id, beforeId);
3538
return this;
@@ -41,7 +44,7 @@ export var MapExtend = function () {
4144
}
4245
};
4346

44-
window.mapboxgl.Map.prototype.removeLayer = function (id) {
47+
mapboxgl.Map.prototype.removeLayer = function (id) {
4548
if (this.overlayLayersManager[id]) {
4649
removeLayer(this.overlayLayersManager[id]);
4750
delete this.overlayLayersManager[id];
@@ -53,7 +56,7 @@ export var MapExtend = function () {
5356
};
5457

5558
//目前扩展的overlayer,只支持显示或隐藏图层操作
56-
window.mapboxgl.Map.prototype.setLayoutProperty = function (layerID, name, value) {
59+
mapboxgl.Map.prototype.setLayoutProperty = function (layerID, name, value) {
5760
if (this.overlayLayersManager[layerID]) {
5861
if (name === "visibility") {
5962
if (value === "visible") {
@@ -70,21 +73,21 @@ export var MapExtend = function () {
7073
this._update(true);
7174
return this;
7275
};
73-
window.mapboxgl.Map.prototype.updateTransform = function (units, originX, originY, centerX, centerY, width, height) {
76+
mapboxgl.Map.prototype.updateTransform = function (units, originX, originY, centerX, centerY, width, height) {
7477
this.transform.units = units;
7578
this.transform.latRange = [this._tileExtent[1], this._tileExtent[3]];
7679
this.transform.lngRange = [this._tileExtent[0], this._tileExtent[2]];
7780
var mercatorZfromAltitude = this.mercatorZfromAltitude;
78-
window.mapboxgl.MercatorCoordinate.fromLngLat = function (lngLatLike, altitude) {
81+
mapboxgl.MercatorCoordinate.fromLngLat = function (lngLatLike, altitude) {
7982
altitude = altitude || 0;
80-
const lngLat = window.mapboxgl.LngLat.convert(lngLatLike);
81-
return new window.mapboxgl.MercatorCoordinate(
83+
const lngLat = mapboxgl.LngLat.convert(lngLatLike);
84+
return new mapboxgl.MercatorCoordinate(
8285
(lngLat.lng - originX) / width,
8386
(originY - lngLat.lat) / height,
8487
mercatorZfromAltitude(altitude, lngLat.lat));
8588
};
86-
window.mapboxgl.MercatorCoordinate.prototype.toLngLat = function () {
87-
return new window.mapboxgl.LngLat(
89+
mapboxgl.MercatorCoordinate.prototype.toLngLat = function () {
90+
return new mapboxgl.LngLat(
8891
this.x * width + originX,
8992
originY - this.y * height);
9093
};
@@ -125,7 +128,7 @@ export var MapExtend = function () {
125128
if (beforeLayerID) {
126129
var beforeLayer = document.getElementById(beforeLayerID);
127130
if (!beforeLayer) {
128-
window.mapboxgl.Evented.prototype.fire("error", {
131+
mapboxgl.Evented.prototype.fire("error", {
129132
error: new Error(`Layer with id "${beforeLayerID}" does not exist on this document.`)
130133
});
131134
}

src/mapboxgl/index.js

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { MapExtend } from './MapExtend';
2+
3+
export { MapExtend };
4+
15
import { mapboxgl, MapDocLayer, MapTileLayer, MapWmsLayer, MapWMTSLayer, MapVectorLayer, ArcGISLayer, TDTLayer } from './layer';
26

37
export { mapboxgl, MapDocLayer, MapTileLayer, MapWmsLayer, MapWMTSLayer, MapVectorLayer, ArcGISLayer, TDTLayer };
@@ -105,11 +109,11 @@ import {
105109
NetAnalyse,
106110
NetAnalysisExtent,
107111
SlopLineParam
108-
} from '../service/extend';
112+
} from '../service/Igserver/extend';
109113

110114
import { CommonServiceBase, Events, CORS, RequestTimeout, FetchRequest, IgsServiceBase, JSONFormat } from '../service/baseserver';
111115

112-
import { ColorInfo, GDBInfo, MapDoc, CatalogService, TileLayer, VectorLayer } from '../service/MRCS';
116+
import { ColorInfo, GDBInfo, MapDoc, CatalogService, TileLayer, VectorLayer } from '../service/Igserver/MRCS';
113117

114118
import {
115119
EditDocFeature,
@@ -127,7 +131,7 @@ import {
127131
QueryParameter,
128132
QueryParameterBase,
129133
QueryServiceBase
130-
} from '../service/MRFS';
134+
} from '../service/Igserver/MRFS';
131135

132136
import {
133137
AnalysisBase,
@@ -149,7 +153,7 @@ import {
149153
ProjectBase,
150154
ProjectByLayer,
151155
ProjectBySRID
152-
} from '../service/MRFWS';
156+
} from '../service/Igserver/MRFWS';
153157

154158
import {
155159
CalArea,
@@ -162,7 +166,7 @@ import {
162166
ProjectRang,
163167
Smooth,
164168
TopAnalysis
165-
} from '../service/MRGS';
169+
} from '../service/Igserver/MRGS';
166170

167171
import {
168172
GetDocImageService,
@@ -171,7 +175,7 @@ import {
171175
GetMapInfoService,
172176
GetTileImageService,
173177
MapServiceBase
174-
} from '../service/MRMS';
178+
} from '../service/Igserver/MRMS';
175179

176180
import {
177181
CAllOtherDataItemInfoSource,
@@ -202,7 +206,10 @@ import {
202206
ItemValue,
203207
ThemeOper,
204208
ThemesInfo
205-
} from '../service/theme';
209+
} from '../service/Igserver/theme';
210+
211+
import { UserService, GeoDatasetService, CalculateModelService } from '../service/clouddisk';
212+
export { UserService, GeoDatasetService, CalculateModelService };
206213

207214
export { ServiceBase };
208215

@@ -382,15 +389,52 @@ export {
382389
ThemesInfo
383390
};
384391

392+
import {
393+
GeoFeatureThemeLayer,
394+
ThemeLayer,
395+
RangeThemeLayer,
396+
UniqueThemeLayer,
397+
GraphThemeLayer,
398+
graphThemeLayer,
399+
RandomThemeLayer,
400+
SimpleThemeLayer,
401+
RankSymbolThemeLayer,
402+
ThemeStyle
403+
} from './theme';
404+
export {
405+
GeoFeatureThemeLayer,
406+
ThemeLayer,
407+
RangeThemeLayer,
408+
UniqueThemeLayer,
409+
GraphThemeLayer,
410+
graphThemeLayer,
411+
RandomThemeLayer,
412+
SimpleThemeLayer,
413+
RankSymbolThemeLayer,
414+
ThemeStyle
415+
};
416+
385417
// 大数据相关
418+
import {
419+
PostgisCatlogService,
420+
PostgisCustomQueryService,
421+
PostgisQueryService,
422+
PostgisTableService,
423+
PostgisVectorTileService
424+
} from '../service/datastore/postgis';
425+
426+
export { PostgisCatlogService, PostgisCustomQueryService, PostgisQueryService, PostgisTableService, PostgisVectorTileService };
427+
386428
import {
387429
EchartsLayer,
388430
MapvLayer,
389431
DeckglLayer
432+
/* StreamLayer */
390433
} from './overlay/index.js';
391434

392-
export let Overlay = {
435+
export {
393436
EchartsLayer,
394437
MapvLayer,
395438
DeckglLayer
439+
/* StreamLayer */
396440
};

src/mapboxgl/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "@mapgis/webclient-es6-mapboxgl",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "dist/webclient-mapboxgl-plugin.min.js",
65
"module": "index.js",
76
"scripts": {
87
"test": "echo \"Error: no test specified\" && exit 1"

src/mapboxgl/theme/GeoFeatureThemeLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class GeoFeatureThemeLayer extends ThemeLayer {
8989
*/
9090
addFeatures(features) {
9191
var me = this;
92-
window.mapboxgl.Evented.prototype.fire("beforefeaturesadded", {
92+
mapboxgl.Evented.prototype.fire("beforefeaturesadded", {
9393
features: features
9494
});
9595

src/mapboxgl/theme/ThemeLayer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ class ThemeLayer {
421421
map = this.map;
422422
var tempPoint = null;
423423
if (isArray(coordinate)) {
424-
coordinate = this.WebMercator2lonLat(coordinate[0], coordinate[1]);
424+
425+
// coordinate = this.WebMercator2lonLat(coordinate[0], coordinate[1]);
426+
coordinate = new mapboxgl.LngLat(coordinate[0], coordinate[1]);
425427
tempPoint = map.project(coordinate);
426428
pixelP = [tempPoint.x, tempPoint.y];
427429
}
@@ -443,7 +445,7 @@ class ThemeLayer {
443445
}
444446
this.startPitch = this.map.getPitch();
445447
this.startBearing = this.map.getBearing();
446-
var startMovePoint = this.map.project(this.WebMercator2lonLat(0, 0));
448+
var startMovePoint = this.map.project(new mapboxgl.LngLat(0, 0));
447449
this.startMoveX = startMovePoint.x;
448450
this.startMoveY = startMovePoint.y;
449451
}
@@ -462,7 +464,8 @@ class ThemeLayer {
462464
this.mapContainer.style.perspective = this.map.transform.cameraToCenterDistance + 'px';
463465
var tPitch = this.map.getPitch() - this.startPitch;
464466
var tBearing = -this.map.getBearing() + this.startBearing;
465-
var endMovePoint = this.map.project(this.WebMercator2lonLat(0, 0));
467+
// var endMovePoint = this.map.project(this.WebMercator2lonLat(0, 0));
468+
var endMovePoint = this.map.project(new mapboxgl.LngLat(0, 0));
466469
var tMoveX = endMovePoint.x - this.startMoveX;
467470
var tMoveY = endMovePoint.y - this.startMoveY;
468471
this.div.style.transform = 'rotateX(' + tPitch + 'deg)' + ' rotateZ(' + tBearing + 'deg)' + ' translate3d(' + tMoveX + 'px, ' + tMoveY + 'px, 0px)';
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var webpack = require('webpack');
2+
var path = require('path');
3+
var HappyPack = require('happypack');//多线程loader 加快编译速度
4+
var os = require('os');
5+
var happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
6+
var HtmlWebpackPlugin = require('html-webpack-plugin');
7+
const BuildInfo = require('./version/version.js')
8+
9+
module.exports = {
10+
mode:'development',
11+
devtool: 'eval-source-map',
12+
entry: path.join(__dirname, '.', 'index.js'),
13+
output: {
14+
path: path.join(__dirname, '.', 'output'),//打包后的文件存放的地方
15+
filename: "webclient-mapboxgl-plugin.js"//打包后输出文件的文件名
16+
},
17+
externals: {
18+
'@mapgis/mapbox-gl': 'mapboxgl',
19+
'mapv': "function(){try{return mapv}catch(e){return {}}}()",
20+
'echarts': 'function(){try{return echarts}catch(e){return {}}}()'
21+
},
22+
module: {
23+
// noParse: /[\/\\]mapbox-gl\.js$/,
24+
// noParse: /3rdLib[^.*mapbox]\.js$/,
25+
26+
//script-loader
27+
rules: [
28+
{
29+
test: /(\.js)$/,
30+
use: 'happypack/loader?id=js',
31+
exclude: [/node_modules/,/leaflet/,/openlayers/]
32+
}
33+
]
34+
},
35+
plugins: [
36+
new HappyPack({
37+
id: 'js',
38+
// threads: 4,
39+
threadPool: happyThreadPool,
40+
loaders: [{
41+
loader: 'babel-loader',
42+
options: {
43+
presets: ['es2015'],
44+
cacheDirectory: true,
45+
plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties']
46+
}
47+
}]
48+
}),
49+
new HtmlWebpackPlugin({
50+
filename: 'webclient-mapboxgl-plugin.html',
51+
template: 'src/config/opensource/version/version.html',
52+
inject: false,//不插入生成的js 仅用于版本声明
53+
minify: {
54+
removeComments: false,
55+
collapseWhitespace: true,
56+
removeAttributeQuotes: true
57+
},
58+
buildInfo: BuildInfo
59+
})
60+
]
61+
}

0 commit comments

Comments
 (0)