123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- define(['html!templates/tools/toolJumpToLatlng',
- 'modDir/service/poiSearch',
- 'css!styles/tools/toolPublicPopup'],
- function (tplLayout, poiSearchF) {
- /**
- * 模块状态,用于存储模块的状态 例如:收起,关闭
- * @type {Object}
- */
- var status = {
- initialized: false//是否初始化
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- InputType: 1,//查询方式
- jumpLatLng: {//查询默认参数
- lat: 0,
- lng: 0,
- zoom: 1
- },
- marker: null,//图标
- jumpObj: {}//收藏数据
- };
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function init() {
- if (!status.initialized) {
- setLayout();
- bindEvent();
- subscribe();
- status.initialized = true;
- $("#jumpToLatlngForm .input").val('0');
- $("#jumpToLatlngModal #lngD").val("");
- }
- if ($(".tools-painting").hasClass('cur')) {
- // var r = confirm("是否离开标注并保存当前标注?");
- // if(r){
- // $(".tsAct li.save").click();
- // $(".modal .modal-header .close,#userDrawAddModal .form .sure").bind("click",function(){
- afac()
- // })
- // }
- } else {
- afac()
- }
- };
- function afac() {
- $('#jumpToZoom').val(map23DData.view.zoom);
- if (map23DData.display.map2D) {
- $('#jumpToLatlngModal').removeClass('class3d');
- } else if (map23DData.display.map3D) {
- $('#jumpToLatlngModal').addClass('class3d');
- }
- $("#jumpToLatlngModal").show();
- $("#jumpToLatlngModal #lngD").focus();
- ONEMAP.C.publisher.publish({
- modName: 'toolJumpToLatlng'
- }, 'tools:active');
- }
- function setLayout() {
- $('body').append(tplLayout);
- //拖拽
- $("#jumpToLatlngModal .popup-ct").dragmove($('#jumpToLatlngModal'));
- };
- function change23D(options) {
- if (options == '2d') {
- $('#jumpToLatlngModal').removeClass('class3d');
- } else {
- $('#jumpToLatlngModal').addClass('class3d');
- }
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(change23D, 'change23D');
- ONEMAP.C.publisher.subscribe(clearMarker, 'cleanMap');
- ONEMAP.C.publisher.subscribe(remove, 'tools:active');
- };
- /**
- * 关闭模块
- * @return {[type]} [description]
- */
- function remove(options) {
- if (options.modName != 'toolJumpToLatlng') {
- removeCurClass();
- } else {
- if ($('.tools-toolJumpToLatlng').hasClass('cur')) {
- removeCurClass();
- } else {
- $('.tools-toolJumpToLatlng').addClass('cur');
- }
- }
- }
- /**
- * 工具栏状态控制
- */
- function removeCurClass(options) {
- $('#toolsBar .tools-toolJumpToLatlng').removeClass('cur');
- $('#topBar .tools-toolJumpToLatlng').removeClass('cur');
- $("#jumpToLatlngModal").hide();
- };
- /**
- * 获取并计算经纬度
- * @private
- */
- function getLatLng() {
- if (modValue.InputType === 1) {
- modValue.jumpLatLng.lng = L.Util.HMStoLatLng(
- $('#jumpToLatlngForm dt .lng').attr('v'),
- ($('#lngD').val() ? $('#lngD').val() : 0),
- ($('#lngF').val() ? $('#lngF').val() : 0),
- ($('#lngM').val() ? $('#lngM').val() : 0)
- );
- modValue.jumpLatLng.lat = L.Util.HMStoLatLng(
- $('#jumpToLatlngForm dt .lat').attr('v'),
- ($('#latD').val() ? $('#latD').val() : 0),
- ($('#latF').val() ? $('#latF').val() : 0),
- ($('#latM').val() ? $('#latM').val() : 0)
- );
- } else if (modValue.InputType === 2) {
- var lng = parseFloat($('#jumpToLngInput').val() ? $('#jumpToLngInput').val() : 0);
- var lat = parseFloat($('#jumpToLatInput').val() ? $('#jumpToLatInput').val() : 0);
- if ($('#jumpToLatlngForm dt .lat').attr('v') === 's') {
- lat = -1 * lat;
- }
- if ($('#jumpToLatlngForm dt .lng').attr('v') === 'w') {
- lng = -1 * lng;
- }
- modValue.jumpLatLng.lat = lat;
- modValue.jumpLatLng.lng = lng;
- }
- modValue.jumpLatLng.zoom = parseInt($('#jumpToZoom').val());
- jumpTo()
- };
- /**
- * 清除marker
- * @return {[type]} [description]
- */
- function clearMarker() {
- var key = modValue.marker;
- map23DControl.marker({
- action: 'remove',
- guid: key
- })
- }
- /**
- * 获取输入信息并跳转到指定的坐标
- * @type {Function}
- * @private
- */
- function jumpTo() {
- if (!L.Util.verifyLatLng(modValue.jumpLatLng.lat, modValue.jumpLatLng.lng)) {
- alert('请正确输入经纬范围(经度0-180、纬度0-90)');
- return false;
- }
- clearMarker();
- if (map23DData.display.map2D) {
- map2DViewer.setView({
- center: {
- lat: modValue.jumpLatLng.lat,
- lng: modValue.jumpLatLng.lng
- },
- zoom: modValue.jumpLatLng.zoom
- });
- } else if (map23DData.display.map3D) {
- map3DViewer.setView({
- center: {
- lat: modValue.jumpLatLng.lat,
- lng: modValue.jumpLatLng.lng
- },
- zoom: modValue.jumpLatLng.zoom,
- distance: map3DViewer.getZoomFrom2DZoom(modValue.jumpLatLng.zoom),
- heading: 0,//摄像机平面角度 正北为0
- tilt: 0//摄像机倾斜角
- });
- }
- $("#jumpToLatlngModal").hide();
- removeCurClass();
- ONEMAP.V.loading.load();
- ONEMAP.C.publisher.publish('jumpToLatLng', 'mapChange');
- };
- //设为目标
- function setPoint() {
- _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
- };
- //设为起点
- function setStart() {
- _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
- };
- //途经点
- function setAcross() {
- _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
- };
- //规避点
- function setAvoid() {
- _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
- };
- //终点
- function setStop() {
- _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
- };
- function _setDirectionsPoint(_lat, _lng, _type, _name) {
- switch (_type) {
- case "start":
- if (ONEMAP.M.directions) {
- ONEMAP.M.directions.setStartPoint(new L.LatLng(_lat, _lng), _name);
- } else {
- require(['mod/directions'], function (directions) {
- directions.init();
- directions.setStartPoint(new L.LatLng(_lat, _lng), _name);
- });
- }
- break;
- case "across":
- if (ONEMAP.M.directions) {
- ONEMAP.M.directions.setAcrossPoint(new L.LatLng(_lat, _lng), _name);
- } else {
- require(['mod/directions'], function (directions) {
- directions.init();
- directions.setAcrossPoint(new L.LatLng(_lat, _lng), _name);
- });
- }
- break;
- case "avoid":
- if (ONEMAP.M.directions) {
- ONEMAP.M.directions.setAvoidPoint(new L.LatLng(_lat, _lng), _name);
- } else {
- require(['mod/directions'], function (directions) {
- directions.init();
- directions.setAvoidPoint(new L.LatLng(_lat, _lng), _name);
- });
- }
- break;
- case "stop":
- if (ONEMAP.M.directions) {
- ONEMAP.M.directions.setStopPoint(new L.LatLng(_lat, _lng), _name);
- } else {
- require(['mod/directions'], function (directions) {
- directions.init();
- directions.setStopPoint(new L.LatLng(_lat, _lng), _name);
- });
- }
- break;
- }
- };
- //
- /**
- * 事件绑定
- */
- function bindEvent() {
- $("#jumpToLatlngForm .input").bind('click', function () {
- $(this).val('');
- });
- $("#jumpToLatlngModal .close").bind('click', function () {
- removeCurClass();
- });
- $("#jumpToLatlngModal .btn-default.sure").bind('click', function () {
- getLatLng();
- if (!$("#showShiZi").hasClass('cur')) {
- $("#showShiZi").click();
- }
- //removeCurClass();
- });
- //回车执行
- $('#jumpToLngInput, #jumpToLatInput').bind('keydown', function (e) {
- if (e.keyCode === 13) {
- getLatLng();
- //removeCurClass();
- }
- });
- $('#jumpToLatlngForm dt .lng').bind('click', function () {
- if ($(this).attr('v') === 'e') {
- $(this).attr('v', 'w');
- $(this).html('西经');
- } else {
- $(this).attr('v', 'e');
- $(this).html('东经');
- }
- });
- $('#jumpToLatlngForm dt .lat').bind('click', function () {
- if ($(this).attr('v') === 'n') {
- $(this).attr('v', 's');
- $(this).html('南纬');
- } else {
- $(this).attr('v', 'n');
- $(this).html('北纬');
- }
- });
- $("#shi").bind('click', function () {
- if (modValue.InputType === 1) {
- $('#jumpToLatlngForm').removeClass().addClass('type-2');
- // $(this).html('度分秒');
- modValue.InputType = 2;
- }
- })
- $("#du").bind('click', function () {
- if (modValue.InputType === 2) {
- $('#jumpToLatlngForm').removeClass().addClass('type-1');
- // $(this).html('十进制');
- modValue.InputType = 1;
- }
- })
- // $('#jumpToLatlngInputType').bind('click',function(){
- // if(modValue.InputType === 1){
- // $('#jumpToLatlngForm').removeClass().addClass('type-2');
- // $(this).html('度分秒');
- // modValue.InputType = 2;
- // }else if(modValue.InputType === 2){
- // $('#jumpToLatlngForm').removeClass().addClass('type-1');
- // $(this).html('十进制');
- // modValue.InputType = 1;
- // }
- // });
- };
- return ONEMAP.M.toolJumpToLatlng = {
- init: init,
- setStop: setStop,
- setAvoid: setAvoid,
- setAcross: setAcross,
- setStart: setStart,
- setStop: setStop,
- setPoint: setPoint,
- clearMarker: clearMarker
- };
- })
|