| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- define(['html!templates/menu/baseCalc/coorTransform',
- 'css!styles/tools/toolPublicPopup',
- 'css!styles/menu/baseCalc/coorTransform',
- ],
- function (tplLayout) {
- /**
- * 模块状态,用于存储模块的状态 例如:收起,关闭
- * @type {Object}
- */
- var status = {
- initialized: false//是否初始化
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- data: {},
- beforeId: "",
- afterId: "",
- beforeStyle: {
- color: "#2ecc71",
- fontFillColor: "#fff000",
- labelOffset: -15,
- },
- afterStyle: {
- color: "#3498db",
- fontFillColor: "#fff000",
- labelOffset: 15,
- }
- };
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function open(data) {
- modValue.data = data;
- if (!status.initialized) {
- setLayout();
- bindEvent();
- subscribe();
- status.initialized = true;
- } else {
- // 重置
- reset();
- }
- resetLayout();
- $("#coorTransformModal .title").text(data.label);
- ONEMAP.C.publisher.publish({
- modName: 'coorTransform'
- }, 'baseCalc:active');
- };
- function setLayout() {
- $('body').append(tplLayout);
- //拖拽
- $("#coorTransformModal .popup-ct").dragmove($('#coorTransformModal'));
- };
- function resetLayout() {
- if (modValue.data.coorKey == "sh2000xyToWgs84") {
- $("#coorTransformModal .beforeLon").text("X:")
- $("#coorTransformModal .beforeLat").text("Y:")
- $("#coorTransformModal .afterLonLat").text("经度:")
- }
- else if (modValue.data.coorKey == "wgs84ToSh2000xy") {
- $("#coorTransformModal .beforeLon").text("经度:")
- $("#coorTransformModal .beforeLat").text("纬度:")
- $("#coorTransformModal .afterLonLat").text("XY:")
- } else {
- $("#coorTransformModal .beforeLon").text("经度:")
- $("#coorTransformModal .beforeLat").text("纬度:")
- $("#coorTransformModal .afterLonLat").text("经纬度:")
- }
- }
- /**
- * 事件绑定
- */
- function bindEvent() {
- $("#coorTransformModal .close").bind('click', function () {
- close();
- });
- $("#coorTransformModal .btn-default.sure").bind('click', function () {
- execute()
- });
- //回车执行
- $('#coorTransformInput, #jumpToLatInput').bind('keydown', function (e) {
- if (e.keyCode === 13) {
- execute();
- }
- });
- };
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'baseCalc:active');
- };
- /**
- * 关闭模块
- * @return {[type]} [description]
- */
- function remove(options) {
- if (options.modName != 'coorTransform') {
- close();
- } else {
- $("#coorTransformModal").show();
- }
- }
- function reset() {
- $("#coorTransformForm .lonCoor").val("");
- $("#coorTransformForm .latCoor").val("");
- // clearMarker();
- $("#coorTransformForm .outputCoor").text("")
- }
- function close() {
- $("#coorTransformModal").hide();
- reset();
- }
- // 执行
- function execute() {
- // 检测坐标
- let lon = $("#coorTransformForm .lonCoor").val()
- let lat = $("#coorTransformForm .latCoor").val()
- if (lon == "" || lat == "") {
- alert("请完善转换参数")
- throw "请完善转换参数 "
- }
- lon = Number(lon)
- lat = Number(lat)
- if (isNaN(lon) || isNaN(lat)) {
- alert("请输入正确的数字格式的坐标")
- throw "请输入正确的数字格式的坐标"
- }
- if (modValue.data.coorKey == "sh2000xyToWgs84") {
- getLatLng(lon, lat);
- } else {
- // 检测坐标范围
- if (judge(lon, lat)) {
- getLatLng(lon, lat);
- }
- }
- }
- /**
- * 获取输入信息并跳转到指定的坐标
- * @type {Function}
- * @private
- */
- function judge(lng, lat) {
- if (!L.Util.verifyLatLng(lat, lng)) {
- alert('请正确输入经纬范围(经度0-180、纬度0-90)');
- return false;
- }
- return true;
- }
- /**
- * 获取并计算经纬度
- * @private
- */
- function getLatLng(beforeLon, beforeLat) {
- // clearMarker();
- let url = ""
- // if (modValue.data.coorKey == "wgsThx") url = '/wgs84ToGcj02';
- // if (modValue.data.coorKey == "hxTwgs") url = '/gcj02ToWgs84';
- // if (modValue.data.coorKey == "wgsTbd") url = '/wgs84ToBD09';
- // if (modValue.data.coorKey == "bdTwgs") url = '/bd09ToWgs84';
- // if (modValue.data.coorKey == "wgsTsh2000") url = '/wgs84ToSh2000';
- // if (modValue.data.coorKey == "sh2000Twgs") url = '/sh2000ToWgs84';
- let paramData = {}
- if (modValue.data.coorKey == "sh2000xyToWgs84") {
- paramData = {
- x: beforeLon,
- y: beforeLat,
- }
- } else {
- paramData = {
- lon: beforeLon,
- lat: beforeLat,
- }
- }
- $.ajax({
- type: "get",
- dataType: 'json',
- url: onemapUrlConfig.PROXY_URL + "/" + modValue.data.coorKey, // + '?lon=' + beforeLon + '&lat=' + beforeLat,
- data: paramData,
- success: function (data) {
- let lon, lat;
- if (data.x) {
- lon = data.x
- lat = data.y
- } else {
- lon = data.lon
- lat = data.lat
- }
- // modValue.beforeId = addMarker(beforeLon, beforeLat, modValue.beforeStyle, modValue.data.beforeLabel)
- // modValue.afterId = addMarker(lon, lat, modValue.afterStyle, modValue.data.afterLabel)
- $("#coorTransformForm .outputCoor").text(lon + ', ' + lat)
- // map3DViewer.setView({
- // center: {
- // lng: lon,
- // lat: lat
- // },
- // distance: 40,
- // heading: 0,//摄像机平面角度 正北为0
- // tilt: 0//摄像机倾斜角
- // });
- },
- error: function (error) {
- console.log(error)
- }
- });
- return;
- };
- function addMarker(lon, lat, style, text) {
- let entity = map3DViewer.map.entities.add({
- name: '添加点',
- position: Cesium.Cartesian3.fromDegrees(lon, lat, 0),
- point: {
- color: Cesium.Color.fromCssColorString(style.color), //颜色
- pixelSize: 10, //大小
- outlineColor: Cesium.Color.YELLOW, //轮廓颜色
- outlineWidth: 1
- },
- label: {
- pixelOffset: new Cesium.Cartesian2(0, style.labelOffset),
- text: text,
- font: '24px',
- fillColor: Cesium.Color.fromCssColorString(style.color)//Cesium.Color.fromCssColorString(style.fontFillColor)
- }
- })
- return entity._id;
- }
- /**
- * 清除marker
- * @return {[type]} [description]
- */
- function clearMarker() {
- if (modValue.beforeId) {
- map3DViewer.map.entities.removeById(modValue.beforeId)
- modValue.beforeId = ""
- }
- if (modValue.afterId) {
- map3DViewer.map.entities.removeById(modValue.afterId)
- modValue.afterId = ""
- }
- }
- return ONEMAP.M.coorTransformForm = {
- open: open,
- clearMarker: clearMarker
- };
- })
|