| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- define(['html!templates/menu/baseCalc/gridInfoByLonlat',
- 'css!styles/tools/toolPublicPopup',
- 'css!styles/menu/baseCalc/gridInfoByLonlat',
- ],
- function (tplLayout) {
- /**
- * 模块状态,用于存储模块的状态 例如:收起,关闭
- * @type {Object}
- */
- var status = {
- initialized: false//是否初始化
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- data: {},
- handler: null
- };
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function open(data) {
- if (!status.initialized) {
- setLayout();
- bindEvent();
- subscribe();
- status.initialized = true;
- } else {
- // 重置
- reset();
- }
- modValue.data = data;
- $("#gridInfoByLonlatModal .title").text(data.label);
- ONEMAP.C.publisher.publish({
- modName: 'gridInfoByLonlat'
- }, 'baseCalc:active');
- };
- function setLayout() {
- $('body').append(tplLayout);
- //拖拽
- $("#gridInfoByLonlatModal .popup-ct").dragmove($('#gridInfoByLonlatModal'));
- };
- /**
- * 事件绑定
- */
- function bindEvent() {
- $("#gridInfoByLonlatModal .close").bind('click', function () {
- close();
- });
- $("#gridInfoByLonlatModal .openFunc").bind('click', function () {
- openFunc();
- });
- $("#gridInfoByLonlatModal .closeFunc").bind('click', function () {
- closeFunc();
- });
- };
- function openFunc() {
- addMapClickEvent();
- }
- function closeFunc() {
- removeMapClickEvent();
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'baseCalc:active');
- };
- /**
- * 关闭模块
- * @return {[type]} [description]
- */
- function remove(options) {
- if (options.modName != 'gridInfoByLonlat') {
- close();
- } else {
- $("#gridInfoByLonlatModal").show();
- }
- }
- function reset() {
- $("#gridInfoByLonlatForm .outputResult table tr").empty("")
- removeMapClickEvent();
- }
- function close() {
- $("#gridInfoByLonlatModal").hide();
- reset();
- }
- /**
- * 获取并计算经纬度
- * @private
- */
- function getInfo(lon, lat) {
- $.ajax({
- type: "get",
- dataType: 'json',
- url: onemapUrlConfig.PROXY_URL + "/getWGridCJByLonlat",
- data: {
- lon: lon,
- lat: lat,
- },
- success: function (data) {
- if (data.code == 200) {
- setOutputResult(data.content)
- }
- },
- error: function (error) {
- console.log(error)
- }
- });
- return;
- };
- function setOutputResult(data) {
- $("#gridInfoByLonlatForm .outputResult table tr").empty()
- let html = "";
- ttttt(data.位置信息).map(function (item) {
- html += item
- })
- if (typeof data.微网格信息 != "string" && Object.getOwnPropertyNames(data.微网格信息).length >= 3) {
- ttttt(data.微网格信息).map(function (item) {
- html += item
- })
- }
- if (typeof data.村居信息 != "string" && Object.getOwnPropertyNames(data.村居信息).length >= 3) {
- ttttt(data.村居信息).map(function (item) {
- html += item
- })
- }
- if (typeof data.网格信息 != "string" && Object.getOwnPropertyNames(data.网格信息).length >= 3) {
- ttttt(data.网格信息).map(function (item) {
- html += item
- })
- }
- function ttttt(obj) {
- let fieldArr = Object.getOwnPropertyNames(obj);
- let htmlArr = fieldArr.map(function (field) {
- return "<tr><td><span>" + field + ":</span></td><td><span>" + obj[field] + "</span></td></tr>"
- })
- return htmlArr;
- }
- $("#gridInfoByLonlatForm .outputResult table tr").append(html);
- }
- function addMapClickEvent() {
- if (modValue.handler != null) return;
- modValue.handler = new Cesium.ScreenSpaceEventHandler(map3DViewer.map.canvas);
- // 监听鼠标点击事件
- modValue.handler.setInputAction(function (click) {
- let cartesian = map3DViewer.map.scene.globe.pick(map3DViewer.map.camera.getPickRay(click.position), map3DViewer.map.scene);
- if (Cesium.defined(cartesian)) {
- // 将笛卡尔坐标转换为经纬度坐标
- var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
- var longitude = Cesium.Math.toDegrees(cartographic.longitude)
- var latitude = Cesium.Math.toDegrees(cartographic.latitude)
- getInfo(longitude, latitude)
- // var heightString = cartographic.height.toFixed(2);
- // console.log('经度:' + longitudeString + ',纬度:' + latitudeString + ',高度:' + heightString)
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- }
- function removeMapClickEvent() {
- if (modValue.handler) {
- modValue.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
- modValue.handler = null;
- }
- }
- return ONEMAP.M.gridInfoByLonlatForm = {
- open: open,
- };
- })
|