Skip to content

Commit 64d21f7

Browse files
committed
fix ICL935 && leaflet新增自定义比例尺范例
1 parent 7705acb commit 64d21f7

File tree

8 files changed

+180
-64
lines changed

8 files changed

+180
-64
lines changed

dist/iclient9-leaflet.js

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8249,10 +8249,6 @@ var TiledMapLayer = exports.TiledMapLayer = _leaflet2.default.TileLayer.extend({
82498249
return tileUrl;
82508250
},
82518251

8252-
setScales: function setScales(scales) {
8253-
this.scales = scales || this.scales;
8254-
},
8255-
82568252
getScale: function getScale(zoom) {
82578253
var me = this;
82588254
//返回当前比例尺
@@ -17970,10 +17966,6 @@ var TileVectorLayer = exports.TileVectorLayer = _VectorGrid.VectorGrid.extend({
1797017966
return style;
1797117967
},
1797217968

17973-
setScales: function setScales(scales) {
17974-
this.scales = scales || this.scales;
17975-
},
17976-
1797717969
getScale: function getScale(zoom) {
1797817970
var me = this;
1797917971
//返回当前比例尺
@@ -24056,48 +24048,6 @@ var JSONFormat = function (_Format) {
2405624048
} catch (e) {
2405724049
// Fall through if the regexp test fails.
2405824050
}
24059-
} else try {
24060-
/**
24061-
* Parsing happens in three stages. In the first stage, we run the
24062-
* text against a regular expression which looks for non-JSON
24063-
* characters. We are especially concerned with '()' and 'new'
24064-
* because they can cause invocation, and '=' because it can
24065-
* cause mutation. But just to be safe, we will reject all
24066-
* unexpected characters.
24067-
*/
24068-
if (/^[\],:{}\s]*$/.test(json.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
24069-
24070-
/**
24071-
* In the second stage we use the eval function to compile the
24072-
* text into a JavaScript structure. The '{' operator is
24073-
* subject to a syntactic ambiguity in JavaScript - it can
24074-
* begin a block or an object literal. We wrap the text in
24075-
* parens to eliminate the ambiguity.
24076-
*/
24077-
object = eval('(' + json + ')');
24078-
24079-
/**
24080-
* In the optional third stage, we recursively walk the new
24081-
* structure, passing each name/value pair to a filter
24082-
* function for possible transformation.
24083-
*/
24084-
if (typeof filter === 'function') {
24085-
var _walk = function _walk(k, v) {
24086-
if (v && (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object') {
24087-
for (var i in v) {
24088-
if (v.hasOwnProperty(i)) {
24089-
v[i] = _walk(i, v[i]);
24090-
}
24091-
}
24092-
}
24093-
return filter(k, v);
24094-
};
24095-
24096-
object = _walk('', object);
24097-
}
24098-
}
24099-
} catch (e) {
24100-
// Fall through if the regexp test fails.
2410124051
}
2410224052

2410324053
if (this.keepData) {
@@ -56526,7 +56476,11 @@ _leaflet2.default.Proj.Projection = _leaflet2.default.Class.extend({
5652656476
initialize: function initialize(code, def, bounds) {
5652756477
var isP4 = _leaflet2.default.Proj._isProj4Obj(code);
5652856478
this._proj = isP4 ? code : this._projFromCodeDef(code, def);
56529-
this.bounds = isP4 ? def : bounds;
56479+
var boundsOption = bounds;
56480+
if (_leaflet2.default.Util.isArray(bounds)) {
56481+
boundsOption = _leaflet2.default.bounds(bounds);
56482+
}
56483+
this.bounds = isP4 ? def : boundsOption;
5653056484
},
5653156485

5653256486
project: function project(latlng) {
@@ -56555,6 +56509,21 @@ _leaflet2.default.Proj.Projection = _leaflet2.default.Class.extend({
5655556509
return (0, _proj2.default)(code);
5655656510
}
5655756511
});
56512+
/**
56513+
* @class L.Proj.CRS
56514+
* @description leaflet Proj投影定义类
56515+
* @extends L.CRS
56516+
* @example
56517+
* 用法:
56518+
* var crs =new L.Proj.CRS("EPSG:4326", '', {
56519+
* origin: [-180,90],
56520+
* scaleDenominators: [2000,1000,500,200,100,50,20,10],
56521+
* });
56522+
* var map=L.map('map', {
56523+
* crs: crs
56524+
* ...
56525+
* })
56526+
*/
5655856527

5655956528
_leaflet2.default.Proj.CRS = _leaflet2.default.Class.extend({
5656056529
includes: _leaflet2.default.CRS,
@@ -56563,6 +56532,18 @@ _leaflet2.default.Proj.CRS = _leaflet2.default.Class.extend({
5656356532
transformation: new _leaflet2.default.Transformation(1, 0, -1, 0)
5656456533
},
5656556534

56535+
/**
56536+
* @function L.Proj.CRS.prototype.initialize
56537+
* @description L.Proj.CRS 投影类构造函数
56538+
* @param a -{String} proj srsCode。
56539+
* @param b -{String} proj def。
56540+
* @param c -{Object} options。可选参数:<br>
56541+
* origin -{Array|L.Point} 原点。必填<br>
56542+
* scales -{Array} 比例尺数组 <br>
56543+
* scaleDenominators -{Array} 比例尺分母数组 <br>
56544+
* resolutions -{Array} 分辨率数组 <br>
56545+
* bounds -{Array|L.Bounds} 范围 <br>
56546+
*/
5656656547
initialize: function initialize(a, b, c) {
5656756548
var code, proj, def, options;
5656856549

@@ -56584,18 +56565,29 @@ _leaflet2.default.Proj.CRS = _leaflet2.default.Class.extend({
5658456565
this.transformation = this.options.transformation;
5658556566

5658656567
if (this.options.origin) {
56568+
if (this.options.origin instanceof _leaflet2.default.Point) {
56569+
this.options.origin = [this.options.origin.x, this.options.origin.y];
56570+
}
5658756571
this.transformation = new _leaflet2.default.Transformation(1, -this.options.origin[0], -1, this.options.origin[1]);
5658856572
}
5658956573

5659056574
if (this.options.scales) {
56591-
this._scales = this.options.scales;
56575+
this._scales = this._toProj4Scales(this.options.scales);
56576+
} else if (this.options.scaleDenominators) {
56577+
var scales = [];
56578+
for (var i = 0; i < this.options.scaleDenominators.length; i++) {
56579+
scales[i] = 1 / this.options.scaleDenominators[i];
56580+
}
56581+
this._scales = this._toProj4Scales(scales);
5659256582
} else if (this.options.resolutions) {
5659356583
this._scales = [];
5659456584
for (var i = this.options.resolutions.length - 1; i >= 0; i--) {
5659556585
if (this.options.resolutions[i]) {
5659656586
this._scales[i] = 1 / this.options.resolutions[i];
5659756587
}
5659856588
}
56589+
} else if (this.options.bounds) {
56590+
this._scales = this._getDefaultProj4ScalesByBounds(this.options.bounds);
5659956591
}
5660056592

5660156593
this.infinite = !this.options.bounds;
@@ -56653,6 +56645,32 @@ _leaflet2.default.Proj.CRS = _leaflet2.default.Class.extend({
5665356645
}
5665456646
}
5665556647
return low;
56648+
},
56649+
56650+
_toProj4Scales: function _toProj4Scales(scales) {
56651+
var proj4Scales = [];
56652+
if (!scales) {
56653+
return proj4Scales;
56654+
}
56655+
for (var i = 0; i < scales.length; i++) {
56656+
proj4Scales[i] = 96 * scales[i] / 0.0254;
56657+
}
56658+
return proj4Scales;
56659+
},
56660+
56661+
_getDefaultProj4ScalesByBounds: function _getDefaultProj4ScalesByBounds(bounds) {
56662+
if (!bounds) {
56663+
return [];
56664+
}
56665+
var boundsSize = _leaflet2.default.bounds(bounds).getSize();
56666+
var extendsSize = Math.max(boundsSize.x, boundsSize.y);
56667+
var resolution = extendsSize / 256;
56668+
var scales = [];
56669+
var maxZoom = 23;
56670+
for (var i = 0; i < maxZoom; i++) {
56671+
scales[i] = Math.pow(2, i) / resolution;
56672+
}
56673+
return scales;
5665656674
}
5665756675
});
5665856676

@@ -63507,7 +63525,7 @@ var names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
6350763525
/* 396 */
6350863526
/***/ (function(module, exports) {
6350963527

63510-
module.exports = {"_args":[["proj4@2.4.3","E:\\0730\\iClient9"]],"_from":"proj4@2.4.3","_id":"proj4@2.4.3","_inCache":true,"_installable":true,"_location":"/proj4","_nodeVersion":"6.9.2","_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/proj4-2.4.3.tgz_1488570790416_0.3068596587982029"},"_npmUser":{"email":"calvin.metcalf@gmail.com","name":"cwmma"},"_npmVersion":"4.0.5","_phantomChildren":{},"_requested":{"name":"proj4","raw":"proj4@2.4.3","rawSpec":"2.4.3","scope":null,"spec":"2.4.3","type":"version"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/proj4/-/proj4-2.4.3.tgz","_shasum":"f3bb7e631bffc047c36a1a3cc14533a03bbe9969","_shrinkwrap":null,"_spec":"proj4@2.4.3","_where":"E:\\0730\\iClient9","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"contributors":[{"email":"madair@dmsolutions.ca","name":"Mike Adair"},{"email":"rich@greenwoodmap.com","name":"Richard Greenwood"},{"email":"calvin.metcalf@gmail.com","name":"Calvin Metcalf"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"1.0.0","wkt-parser":"^1.1.3"},"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~1.1.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","grunt-rollup":"^1.0.1","istanbul":"~0.2.4","mocha":"~1.17.1","rollup":"^0.41.4","rollup-plugin-json":"^2.0.1","rollup-plugin-node-resolve":"^2.0.0","tin":"~0.4.0"},"directories":{"doc":"docs","test":"test"},"dist":{"shasum":"f3bb7e631bffc047c36a1a3cc14533a03bbe9969","tarball":"https://registry.npmjs.org/proj4/-/proj4-2.4.3.tgz"},"gitHead":"e975a5462ad7abb23e33ea75281eb749e77e1510","homepage":"https://github.com/proj4js/proj4js#readme","license":"MIT","main":"dist/proj4-src.js","maintainers":[{"email":"calvin.metcalf@gmail.com","name":"cwmma"},{"email":"andreas.hocevar@gmail.com","name":"ahocevar"}],"module":"lib/index.js","name":"proj4","optionalDependencies":{},"readme":"ERROR: No README data found!","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"build":"grunt","build:tmerc":"grunt build:tmerc","test":"npm run build && istanbul test _mocha test/test.js"},"version":"2.4.3"}
63528+
module.exports = {"_args":[[{"raw":"proj4@2.4.3","scope":null,"escapedName":"proj4","name":"proj4","rawSpec":"2.4.3","spec":"2.4.3","type":"version"},"E:\\work\\iClient9"]],"_cnpm_publish_time":1488570791097,"_from":"proj4@2.4.3","_hasShrinkwrap":false,"_id":"proj4@2.4.3","_inCache":true,"_location":"/proj4","_nodeVersion":"6.9.2","_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/proj4-2.4.3.tgz_1488570790416_0.3068596587982029"},"_npmUser":{"name":"cwmma","email":"calvin.metcalf@gmail.com"},"_npmVersion":"4.0.5","_phantomChildren":{},"_requested":{"raw":"proj4@2.4.3","scope":null,"escapedName":"proj4","name":"proj4","rawSpec":"2.4.3","spec":"2.4.3","type":"version"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/proj4/-/proj4-2.4.3.tgz","_shasum":"f3bb7e631bffc047c36a1a3cc14533a03bbe9969","_shrinkwrap":null,"_spec":"proj4@2.4.3","_where":"E:\\work\\iClient9","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"contributors":[{"name":"Mike Adair","email":"madair@dmsolutions.ca"},{"name":"Richard Greenwood","email":"rich@greenwoodmap.com"},{"name":"Calvin Metcalf","email":"calvin.metcalf@gmail.com"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"1.0.0","wkt-parser":"^1.1.3"},"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~1.1.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","grunt-rollup":"^1.0.1","istanbul":"~0.2.4","mocha":"~1.17.1","rollup":"^0.41.4","rollup-plugin-json":"^2.0.1","rollup-plugin-node-resolve":"^2.0.0","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"dist":{"shasum":"f3bb7e631bffc047c36a1a3cc14533a03bbe9969","size":116887,"noattachment":false,"tarball":"http://registry.npm.taobao.org/proj4/download/proj4-2.4.3.tgz"},"gitHead":"e975a5462ad7abb23e33ea75281eb749e77e1510","homepage":"https://github.com/proj4js/proj4js#readme","license":"MIT","main":"dist/proj4-src.js","maintainers":[{"name":"ahocevar","email":"andreas.hocevar@gmail.com"},{"name":"cwmma","email":"calvin.metcalf@gmail.com"}],"module":"lib/index.js","name":"proj4","optionalDependencies":{},"publish_time":1488570791097,"readme":"ERROR: No README data found!","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"build":"grunt","build:tmerc":"grunt build:tmerc","test":"npm run build && istanbul test _mocha test/test.js"},"version":"2.4.3"}
6351163529

6351263530
/***/ }),
6351363531
/* 397 */

dist/iclient9-leaflet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>自定义比例尺地图</title>
6+
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
8+
</head>
9+
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
10+
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
11+
12+
<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
13+
<script type="text/javascript" src="../../dist/iclient9-leaflet.min.js"></script>
14+
<script type="text/javascript">
15+
var map, url = "http://117.122.248.69:8090/iserver/services/map-jingjin/rest/maps/京津地区地图";
16+
//自定义比例尺
17+
var scaleDenominators = [100000, 50000, 25000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 1];
18+
var origin = [114.59, 42.31];
19+
//leaflet CRS投影设置
20+
var crs = new L.Proj.CRS("EPSG:4326", '', {
21+
origin: origin,
22+
scaleDenominators: scaleDenominators,
23+
});
24+
25+
map = L.map('map', {
26+
crs: crs,
27+
center: [39.79, 116.85],
28+
maxZoom: 14,
29+
zoom: 10,
30+
});
31+
L.supermap.tiledMapLayer(url).addTo(map);
32+
</script>
33+
</body>
34+
</html>

examples/leaflet/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var exampleConfig = {
2828
name: "平面坐标系底图",
2929
thumbnail: "l_tiledMapLayerNonEarth.png",
3030
fileName: "01_tiledMapLayerNonEarth"
31+
}, {
32+
name: "自定义比例尺",
33+
thumbnail: "l_tiledMapLayerProj4.png",
34+
fileName: "01_tiledMapLayerProj4"
3135
}, {
3236
name: "地图信息",
3337
thumbnail: "l_mapService.png",
5.31 KB
Loading

src/leaflet/core/Proj4Leaflet.js

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ L.Proj.Projection = L.Class.extend({
1111
initialize: function (code, def, bounds) {
1212
var isP4 = L.Proj._isProj4Obj(code);
1313
this._proj = isP4 ? code : this._projFromCodeDef(code, def);
14-
this.bounds = isP4 ? def : bounds;
14+
var boundsOption = bounds;
15+
if (L.Util.isArray(bounds)) {
16+
boundsOption = L.bounds(bounds);
17+
}
18+
this.bounds = isP4 ? def : boundsOption;
1519
},
1620

1721
project: function (latlng) {
@@ -40,6 +44,21 @@ L.Proj.Projection = L.Class.extend({
4044
return proj4(code);
4145
}
4246
});
47+
/**
48+
* @class L.Proj.CRS
49+
* @description leaflet Proj投影定义类
50+
* @extends L.CRS
51+
* @example
52+
* 用法:
53+
* var crs =new L.Proj.CRS("EPSG:4326", '', {
54+
* origin: [-180,90],
55+
* scaleDenominators: [2000,1000,500,200,100,50,20,10],
56+
* });
57+
* var map=L.map('map', {
58+
* crs: crs
59+
* ...
60+
* })
61+
*/
4362

4463
L.Proj.CRS = L.Class.extend({
4564
includes: L.CRS,
@@ -48,6 +67,18 @@ L.Proj.CRS = L.Class.extend({
4867
transformation: new L.Transformation(1, 0, -1, 0)
4968
},
5069

70+
/**
71+
* @function L.Proj.CRS.prototype.initialize
72+
* @description L.Proj.CRS 投影类构造函数
73+
* @param a -{String} proj srsCode。
74+
* @param b -{String} proj def。
75+
* @param c -{Object} options。可选参数:<br>
76+
* origin -{Array|L.Point} 原点。必填<br>
77+
* scales -{Array} 比例尺数组 <br>
78+
* scaleDenominators -{Array} 比例尺分母数组 <br>
79+
* resolutions -{Array} 分辨率数组 <br>
80+
* bounds -{Array|L.Bounds} 范围 <br>
81+
*/
5182
initialize: function (a, b, c) {
5283
var code,
5384
proj,
@@ -72,20 +103,31 @@ L.Proj.CRS = L.Class.extend({
72103
this.transformation = this.options.transformation;
73104

74105
if (this.options.origin) {
106+
if (this.options.origin instanceof L.Point) {
107+
this.options.origin = [this.options.origin.x, this.options.origin.y];
108+
}
75109
this.transformation =
76110
new L.Transformation(1, -this.options.origin[0],
77111
-1, this.options.origin[1]);
78112
}
79113

80114
if (this.options.scales) {
81-
this._scales = this.options.scales;
115+
this._scales = this._toProj4Scales(this.options.scales);
116+
} else if (this.options.scaleDenominators) {
117+
var scales = [];
118+
for (var i = 0; i < this.options.scaleDenominators.length; i++) {
119+
scales[i] = 1 / this.options.scaleDenominators[i];
120+
}
121+
this._scales = this._toProj4Scales(scales);
82122
} else if (this.options.resolutions) {
83123
this._scales = [];
84124
for (var i = this.options.resolutions.length - 1; i >= 0; i--) {
85125
if (this.options.resolutions[i]) {
86126
this._scales[i] = 1 / this.options.resolutions[i];
87127
}
88128
}
129+
} else if (this.options.bounds) {
130+
this._scales = this._getDefaultProj4ScalesByBounds(this.options.bounds);
89131
}
90132

91133
this.infinite = !this.options.bounds;
@@ -144,5 +186,31 @@ L.Proj.CRS = L.Class.extend({
144186
}
145187
}
146188
return low;
189+
},
190+
191+
_toProj4Scales: function (scales) {
192+
var proj4Scales = [];
193+
if (!scales) {
194+
return proj4Scales;
195+
}
196+
for (var i = 0; i < scales.length; i++) {
197+
proj4Scales[i] = (96 * scales[i]) / 0.0254;
198+
}
199+
return proj4Scales;
200+
},
201+
202+
_getDefaultProj4ScalesByBounds: function (bounds) {
203+
if (!bounds) {
204+
return [];
205+
}
206+
var boundsSize = L.bounds(bounds).getSize();
207+
var extendsSize = Math.max(boundsSize.x, boundsSize.y);
208+
var resolution = extendsSize / 256;
209+
var scales = [];
210+
var maxZoom = 23;
211+
for (var i = 0; i < maxZoom; i++) {
212+
scales[i] = Math.pow(2, i) / resolution;
213+
}
214+
return scales;
147215
}
148216
});

src/leaflet/mapping/TiledMapLayer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ export var TiledMapLayer = L.TileLayer.extend({
5959
return tileUrl;
6060
},
6161

62-
setScales: function (scales) {
63-
this.scales = scales || this.scales;
64-
},
65-
6662
getScale: function (zoom) {
6763
var me = this;
6864
//返回当前比例尺

src/leaflet/overlay/TileVectorLayer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ export var TileVectorLayer = VectorGrid.extend({
224224
return style;
225225
},
226226

227-
setScales: function (scales) {
228-
this.scales = scales || this.scales;
229-
},
230-
231227
getScale: function (zoom) {
232228
var me = this;
233229
//返回当前比例尺

0 commit comments

Comments
 (0)