Skip to content

Commit 5146788

Browse files
committed
leaflet 端新增 L.Util.transform 工具,用于要素的投影转换。view by songyumeng.
1 parent 71678cf commit 5146788

File tree

14 files changed

+1097
-360
lines changed

14 files changed

+1097
-360
lines changed

dist/leaflet/iclient9-leaflet-es6.js

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63113,7 +63113,7 @@ external_L_default.a.Proj.Projection = external_L_default.a.Class.extend({
6311363113
* @extends {L.Class}
6311463114
* @param {string} srsCode - proj srsCode。
6311563115
* @param {Object} options - 参数。
63116-
* @param {string} options.def - 投影的proj4定义。[详细]{@link http://iclient.supermap.io/web/introduction/leafletDevelop.html#projection}
63116+
* @param {string} options.def - 投影的proj4定义。[详细]{@link http://iclient.supermap.io/web/introduction/leafletDevelop.html#multiProjection}
6311763117
* @param {(Array.<number>|L.Point)} options.origin - 原点。
6311863118
* @param {Array.<number>} options.scales - 比例尺数组。
6311963119
* @param {Array.<number>} options.scaleDenominators - 比例尺分母数组。
@@ -64061,6 +64061,9 @@ class CommontypesConversion_CommontypesConversion {
6406164061
* @return {SuperMap.Bounds} SuperMap的bounds对象
6406264062
*/
6406364063
static toSuperMapBounds(bounds) {
64064+
if (["FeatureCollection", "Feature", "Geometry"].indexOf(bounds.type) !== -1) {
64065+
bounds = external_L_default.a.geoJSON(bounds).getBounds();
64066+
}
6406464067
if (bounds instanceof external_L_default.a.LatLngBounds) {
6406564068
return new Bounds_Bounds(
6406664069
bounds.getSouthWest().lng,
@@ -64085,6 +64088,7 @@ class CommontypesConversion_CommontypesConversion {
6408564088
bounds[3]
6408664089
);
6408764090
}
64091+
6408864092
return new Bounds_Bounds();
6408964093
}
6409064094

@@ -64231,6 +64235,147 @@ external_L_default.a.Util.scaleToResolution = scaleToResolution;
6423164235
external_L_default.a.Util.getMeterPerMapUnit = getMeterPerMapUnit;
6423264236
external_L_default.a.Util.GetResolutionFromScaleDpi = GetResolutionFromScaleDpi;
6423364237
external_L_default.a.Util.NormalizeScale = NormalizeScale;
64238+
// CONCATENATED MODULE: ./src/leaflet/core/Transform.js
64239+
64240+
64241+
64242+
/**
64243+
* @function L.Util.transform
64244+
* @description 将要素转换为指定坐标
64245+
* @param {(L.marker|L.circleMarker|L.polyline|L.polygon|L.rectangle|L.latLngBounds|L.bounds|Object)} feature - 待转要素包括 Leaflet Vector Layers
64246+
* 的 L.marker|L.circleMarker|L.polyline|L.polygon|L.rectangle|L.latLngBounds|L.bounds 类型和 GeoJOSN 规范数据类型
64247+
* @param {L.Proj.CRS} [sourceCRS=L.CRS.EPSG4326] - 要素转换目标坐标系,默认为 L.CRS.EPSG4326
64248+
* @param {L.Proj.CRS} targetCRS - 要素转换目标坐标系
64249+
* @return {Object} 返回GeoJOSN 规范数据类型
64250+
*/
64251+
var transform = function (feature, sourceCRS = external_L_default.a.CRS.EPSG4326, targetCRS) {
64252+
let selfFeatures = null;
64253+
let selfCallback = null;
64254+
//将数据统一为 geojson 格式处理:
64255+
if (["FeatureCollection", "Feature", "Geometry"].indexOf(feature.type) === -1) {
64256+
if (feature.toGeoJSON) {
64257+
feature = feature.toGeoJSON();
64258+
} else if (feature instanceof external_L_default.a.LatLngBounds) {
64259+
feature = external_L_default.a.rectangle(feature).toGeoJSON();
64260+
} else if (feature instanceof external_L_default.a.Bounds) {
64261+
feature = external_L_default.a.rectangle([[feature.getTopLeft().x, feature.getTopLeft().y],
64262+
[feature.getBottomRight().x, feature.getBottomRight().y]]).toGeoJSON();
64263+
} else {
64264+
throw new Error("This tool only supports data conversion in geojson format or Vector Layers of Leaflet.")
64265+
}
64266+
}
64267+
64268+
//geojson 几种数据类型及处理形式
64269+
const parseCoords = {
64270+
"point": function (array) {
64271+
return selfCallback(array);
64272+
},
64273+
64274+
"multipoint": function (array) {
64275+
return parseCoords["linestring"].apply(this, [array])
64276+
},
64277+
64278+
"linestring": function (array) {
64279+
let points = [];
64280+
let p = null;
64281+
for (let i = 0, len = array.length; i < len; ++i) {
64282+
try {
64283+
p = parseCoords["point"].apply(this, [array[i]]);
64284+
} catch (err) {
64285+
throw err;
64286+
}
64287+
points.push(p);
64288+
}
64289+
return points;
64290+
},
64291+
64292+
"multilinestring": function (array) {
64293+
return parseCoords["polygon"].apply(this, [array]);
64294+
},
64295+
64296+
"polygon": function (array) {
64297+
let rings = [];
64298+
let l;
64299+
for (let i = 0, len = array.length; i < len; ++i) {
64300+
try {
64301+
l = parseCoords["linestring"].apply(this, [array[i]]);
64302+
} catch (err) {
64303+
throw err;
64304+
}
64305+
rings.push(l);
64306+
}
64307+
return rings;
64308+
},
64309+
"multipolygon": function (array) {
64310+
let polys = [];
64311+
let p = null;
64312+
for (let i = 0, len = array.length; i < len; ++i) {
64313+
try {
64314+
p = parseCoords["polygon"].apply(this, [array[i]]);
64315+
} catch (err) {
64316+
throw err;
64317+
}
64318+
polys.push(p);
64319+
}
64320+
return polys;
64321+
}
64322+
64323+
};
64324+
64325+
//返回结果:
64326+
return featureTransform(feature, _transformCoordinates);
64327+
64328+
function featureTransform(feature, callback) {
64329+
selfFeatures = feature;
64330+
selfCallback = callback;
64331+
//分离处理:
64332+
if (feature.type === "Feature") {
64333+
selfFeatures = _prepareFeatuers(feature);
64334+
} else if (feature.type === "FeatureCollection") {
64335+
let featureResults = [];
64336+
for (let i = 0; i < feature.features.length; ++i) {
64337+
try {
64338+
featureResults.push(_prepareFeatuers(feature.features[i]));
64339+
} catch (err) {
64340+
featureResults = null;
64341+
}
64342+
}
64343+
selfFeatures.features = featureResults;
64344+
}
64345+
64346+
return selfFeatures;
64347+
}
64348+
64349+
function _prepareFeatuers(feature) {
64350+
const geometry = feature.geometry;
64351+
if (!(Util.isArray(geometry.coordinates))) {
64352+
throw "Geometry must have coordinates array: " + geometry;
64353+
}
64354+
if (!parseCoords[geometry.type.toLowerCase()]) {
64355+
throw "Unsupported geometry type: " + geometry.type;
64356+
}
64357+
try {
64358+
geometry.coordinates = parseCoords[geometry.type.toLowerCase()].apply(
64359+
this, [geometry.coordinates]
64360+
);
64361+
} catch (err) {
64362+
// deal with bad coordinates
64363+
throw err;
64364+
}
64365+
feature.geometry = geometry;
64366+
return feature;
64367+
}
64368+
64369+
function _transformCoordinates(coordinates) {
64370+
//判断code 是投影坐标还是地理坐标
64371+
var point = sourceCRS.unproject({x: coordinates[0], y: coordinates[1]});
64372+
const transform = targetCRS.project(point);
64373+
return [transform.x, transform.y];
64374+
}
64375+
64376+
};
64377+
64378+
external_L_default.a.Util.transform = transform;
6423464379
// CONCATENATED MODULE: ./src/leaflet/core/index.js
6423564380

6423664381

@@ -64248,6 +64393,8 @@ external_L_default.a.Util.NormalizeScale = NormalizeScale;
6424864393

6424964394

6425064395

64396+
64397+
6425164398
// CONCATENATED MODULE: ./src/leaflet/mapping/BaiduTileLayer.js
6425264399

6425364400

@@ -71548,13 +71695,6 @@ var GraphicCanvasRenderer = external_L_default.a.Class.extend({
7154871695
_clearBuffer: emptyFunc
7154971696
});
7155071697

71551-
71552-
/* function calculateOffset(point, anchor) {
71553-
let pt = L.point(point),
71554-
ac = L.point(anchor);
71555-
return [pt.x - ac.x, pt.y - ac.y];
71556-
} */
71557-
7155871698
external_L_default.a.Canvas.include({
7155971699

7156071700
drawGraphics: function (graphics, defaultStyle) {
@@ -82259,7 +82399,7 @@ module.exports = function(proj4){
8225982399
/* 73 */
8226082400
/***/ (function(module) {
8226182401

82262-
module.exports = {"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"http://localhost:4873/proj4/-/proj4-2.3.15.tgz","_shasum":"5ad06e8bca30be0ffa389a49e4565f51f06d089e","_spec":"proj4@2.3.15","_where":"E:\\2018\\git\\iClient-JavaScript","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"bundleDependencies":false,"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":"~0.0.2"},"deprecated":false,"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"};
82402+
module.exports = {"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"http://registry.npm.taobao.org/proj4/download/proj4-2.3.15.tgz","_shasum":"5ad06e8bca30be0ffa389a49e4565f51f06d089e","_spec":"proj4@2.3.15","_where":"G:\\iClient\\iClient-JavaScript","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"bundleDependencies":false,"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":"~0.0.2"},"deprecated":false,"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"};
8226382403

8226482404
/***/ }),
8226582405
/* 74 */

dist/leaflet/iclient9-leaflet-es6.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.

0 commit comments

Comments
 (0)