123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- /**
- * [ONEMAP.M.mapHolder]
- * @return {[object]}
- * 地图框架引入
- * 地图操作
- */
- define([
- 'modDir/service/addressSearch',
- 'modDir/service/poiSearch',
- 'modDir/service/regionSearch',
- 'modDir/service/routeSearch',
- 'css!scripts/vendor/map23dlib/map23DView',
- 'css!styles/mapHolder'
- ], function (addressSearchF, poiSearchF, regionSearchF, routeSearchF) {
- /**
- * 地图初始化 根据客户端的类型 初始pc端和移动端
- * @exports ONEMAP.M.mapHolder
- * @type {Object}
- */
- var modValue = {
- mainLayers: null,
- leadorStreetViewControl: null,
- vact: 'add',
- beifen: {}
- }
- /**
- * 地图初始化参数
- */
- var options = {
- center: [39.90743, 116.39134],
- zoom: 6
- };
- //模块状态
- var status = {}
- /**
- * 初始化
- * @type {Function}
- * @returns {*}
- */
- function init() {
- if (ONEMAP.D.globalSettingData) {
- options.center = [
- ONEMAP.D.globalSettingData.baseMap2D.center.lat,
- ONEMAP.D.globalSettingData.baseMap2D.center.lng
- ];
- options.zoom = ONEMAP.D.globalSettingData.baseMap2D.zoom;
- }
- if (Detector.webgl) {
- modValue.webgl = true;
- } else {
- modValue.webgl = false;
- }
- mapInit();
- subscribe();
- ONEMAP.C.publisher.publish('mapDragend', 'mapChange');
- //移除加载动画
- if (navigator.appName == "Microsoft Internet Explorer") {
- $('#loadingGif').fadeOut(200, function () {
- $('#loadingTop').animate({
- top: '0px'
- }, 600);
- $('#loadingBottom').animate({
- top: '100%'
- }, 600);
- $('#loadingPanel').hide(400);
- setTimeout(function () {
- }, 600)
- });
- } else {
- setTimeout(function () {
- $('#loadingPanel').addClass('open');
- setTimeout(function () {
- $('#loadingPanel').fadeOut(400);
- }, 1000)
- }, 200)
- }
- };
- function mapInit() {
- if (modValue.webgl) {
- //地图加载
- map23DControl.init({
- mapWrapId: 'mapHolder',
- view: {
- center: {
- lat: options.center[0],
- lng: options.center[1]
- },
- zoom: options.zoom
- },
- synch: true,
- display: {
- map2D: false,
- map3D: true
- }
- });
- require(['modDir/3dEarth'], function (tdEarth) {
- tdEarth.init();
- });
- } else {
- //地图加载
- map23DControl.init({
- mapWrapId: 'mapHolder',
- view: {
- center: {
- lat: options.center[0],
- lng: options.center[1]
- },
- zoom: options.zoom
- },
- synch: false,
- display: {
- map2D: false,
- map3D: true
- }
- });
- }
- map23DControl.show3D();
- $('#map3DWrap').css({
- height: $(window).height()
- });
- //设置地图边界
- map2DViewer.map.setMaxBounds([
- [84, 360],
- [-84, -360]
- ]);
- if (ONEMAP.D.globalSettingData) {
- switch (ONEMAP.D.globalSettingData.baseMap2D.type) {
- case 1:
- if (Detector.webgl) {
- map23DControl.setDefaultTileLayer("gm");
- } else {
- map2DViewer.setDefaultTileLayer("gm");
- }
- modValue.mainLayers = "gm";
- $("#mapBaseLayerControl .choosemap .name-dem-control .name-control").hide();
- $("#mapBaseLayerControl .choosemap .name-dem-control .dem-control").hide();
- break;
- case 2:
- if (Detector.webgl) {
- map23DControl.setDefaultTileLayer("gr");
- } else {
- map2DViewer.setDefaultTileLayer("gr");
- }
- modValue.mainLayers = "gr";
- setTimeout(function () {
- $("#mapBaseLayerControl .choosemap .name-dem-control .name-control").show();
- $("#mapBaseLayerControl .choosemap .name-dem-control .dem-control").show();
- }, 500)
- break;
- case 3:
- if (Detector.webgl) {
- map23DControl.setDefaultTileLayer("gt");
- } else {
- map2DViewer.setDefaultTileLayer("gt");
- }
- modValue.mainLayers = "gt";
- $("#mapBaseLayerControl .choosemap .name-dem-control .name-control").hide();
- $("#mapBaseLayerControl .choosemap .name-dem-control .dem-control").hide();
- break;
- }
- }
- map2DViewer.map.on('dragend', function () {
- var zoom = map2DViewer.map.getZoom();
- ONEMAP.C.publisher.publish('mapDragend', 'mapChange');
- ONEMAP.C.publisher.publish(map2DViewer.map.getZoom(), 'mapChange23D');
- })
- map2DViewer.map.on('moveend', function (e) {
- ONEMAP.C.publisher.publish('mapMove', 'map2DMoveEnd');
- })
- map2DViewer.map.on('move', function (e) {
- ONEMAP.C.publisher.publish('mapMoveIng', 'map2DMoveIng');
- })
- //操作地图关闭侧栏
- map2DViewer.map.on('click dragend', function () {
- ONEMAP.C.publisher.publish('mapDragend', 'layout::sideBar');
- $("#openTdSideContent").show();
- $("#mapHolder").unbind('mouseover');
- })
- map2DViewer.map.on('mousemove', function (e) {
- var lat = e.latlng.lat;
- var lng = e.latlng.lng;
- ONEMAP.C.publisher.publish({
- lat: lat,
- lng: lng,
- e: e
- }, 'mousemove23D');
- })
- map2DViewer.map.on('zoomend', function () {
- if (map2DViewer.map.getZoom() == map2DViewer.map.options.maxZoom) {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: '已达地图最大显示级别'
- }, 'noteBar::add');
- }
- if (map2DViewer.map.getZoom() == map2DViewer.map.options.minZoom) {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: '已达地图最小显示级别'
- }, 'noteBar::add');
- }
- ONEMAP.C.publisher.publish(map2DViewer.map.getZoom(), 'userHeatlayerMarker');
- ONEMAP.C.publisher.publish(map2DViewer.map.getZoom(), 'mapChange23D');
- ONEMAP.C.publisher.publish('zoomend', 'mapChange');
- })
- //地图点击事件
- map2DViewer.map.on('click', function (e) {
- var lat = e.latlng.lat,
- lng = e.latlng.lng;
- var options = {
- lng: lng,
- lat: lat
- }
- ONEMAP.C.publisher.publish(options, 'mapClick2D');
- });
- };
- function delMarker(ajaxData) {
- $.ajax({
- type: "get",
- dataType: 'json',
- url: onemapUrlConfig.userCenterUrl + '/bookmarker/del',
- data: ajaxData,
- success: function (data) {
- //console.log(data)
- }
- })
- }
- /**
- * 设置经纬网
- */
- function setSTLatLngLayer(options) {
- var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
- if (options == 'show') {
- STLatLngLayerControl.changStatus(true);
- if (!chrome) {
- // locaSpace.SetLatLonGridVisible(true);
- // locaSpaceMap.Refresh()
- }
- } else {
- STLatLngLayerControl.changStatus(false);
- if (!chrome) {
- //locaSpace.SetLatLonGridVisible(false);
- //locaSpaceMap.Refresh()
- }
- }
- };
- /**
- * 右键菜单函数
- */
- //
- function disable() {
- return false
- };
- //从这里出发
- function pointStartli(e) {
- require(['modDir/tools/toolRouteSearch'], function (toolRouteSearch) {
- toolRouteSearch.setStartPoint(e.latlng);
- });
- };
- //添加途经点
- function pointAcrossli(e) {
- require(['modDir/tools/toolRouteSearch'], function (toolRouteSearch) {
- toolRouteSearch.setAcrossPoint(e.latlng);
- });
- };
- //添加规避点
- function pointAvoidli(e) {
- require(['modDir/tools/toolRouteSearch'], function (toolRouteSearch) {
- toolRouteSearch.setAvoidPoint(e.latlng);
- });
- };
- //到这里去
- function pointStopli(e) {
- require(['modDir/tools/toolRouteSearch'], function (toolRouteSearch) {
- toolRouteSearch.setStopPoint(e.latlng);
- });
- };
- //周边搜索
- function aroundFindli(e) {
- require(['modDir/tools/toolPlaceSearch'], function (toolPlaceSearch) {
- toolPlaceSearch.rightClickPopup(e.latlng);
- });
- };
- //加入地图书签
- // function addBookMarker() {
- //判断是否登录,没有登录进行提示
- // if (!ONEMAP.D.isLoad) {
- // ONEMAP.C.publisher.publish({
- // type: 'warning',
- // message: '请登录后使用!'
- // }, 'noteBar::add');
- // return false;
- // }
- // require(['modDir/user/userFav'], function (userFav) {
- // userFav.addFav();
- // });
- // };
- //鼠标抓手样式
- function removeMouseHand() {
- map2DViewer.map.off("mousedown", mouseDownStatus);
- map2DViewer.map.off("mouseup", mouseUpStatus);
- };
- function mouseDownStatus() {
- if (L.Browser.ie || L.Browser.firefox) {
- map2DViewer.map.getContainer().style.cursor = 'url(/images/layout/mouseDown.cur),auto';
- } else {
- map2DViewer.map.getContainer().style.cursor = 'url(/images/layout/mouseDown.cur) 5 5,auto';
- }
- }
- function mouseUpStatus() {
- if (L.Browser.ie || L.Browser.firefox) {
- map2DViewer.map.getContainer().style.cursor = 'url(/images/layout/mouseMove.cur),auto';
- } else {
- map2DViewer.map.getContainer().style.cursor = 'url(/images/layout/mouseMove.cur) 5 5,auto';
- }
- }
- function mouseHand() {
- mouseUpStatus();
- map2DViewer.map.on("mousedown", mouseDownStatus);
- map2DViewer.map.on("mouseup", mouseUpStatus);
- };
- //清空地图
- function cleanMapli() {
- ONEMAP.M.myLayerActions.clearLayer();
- ONEMAP.C.publisher.publish('', 'cleanMap');
- ONEMAP.C.publisher.publish({
- modName: 'cleanMap',
- }, 'tools:active');
- $("#cleanMap").click();
- };
- /**
- * 判断是否是正确的latlng
- * @param lat
- * @param lng
- * @returns {boolean}
- */
- function isNatureLatLng(lat, lng) {
- if (lat > -90 && lat < 90 && lng > -180 && lng < 180) {
- return true;
- } else {
- return false;
- }
- };
- function getContextmenuPlaceName(e) {
- contextmenuPlaceName.innerHTML = '正在搜索中...';
- var earthLatlng = L.Util.formatEarthLatLng(e.latlng);
- if (isNatureLatLng(earthLatlng.lat, earthLatlng.lng)) {
- var addressSearch = new addressSearchF();
- addressSearch.getAddressInfo({
- zoom: map2DViewer.map.getZoom(),
- latLng: [earthLatlng.lat, earthLatlng.lng]
- }, function (data) {
- data = data.data;
- contextmenuPlaceName.innerHTML = data.region ? data.region : '未知地点';
- });
- }
- };
- function getContextmenuLatlng(e) {
- modValue.latlng = e.latlng;
- var nLatlng = L.Util.formatHMS(e.latlng);
- contextmenuLatlng.innerHTML = nLatlng.lng + ' , ' + nLatlng.lat;
- };
- function getContextmenuCPJ(e) {
- // contextmenuCPJ.innerHTML = "当前磁偏角:正在查询中...";
- }
- function getCP(altData) {
- contextmenuCPJ.innerHTML = '正在查询中...';
- var ajaxUrl = onemapUrlConfig.declination;
- var newdata = new Date();
- var year = newdata.getFullYear();
- var month = (newdata.getMonth() + 1) < 10 ? '0' + (newdata.getMonth() + 1) : (newdata.getMonth() + 1);
- var day = newdata.getDate() < 10 ? '0' + newdata.getDate() : newdata.getDate();
- var ajaxData = {
- alt: altData,
- lat: modValue.latlng.lat,
- lon: modValue.latlng.lng,
- startYear: year,
- startMonth: month,
- startDay: day
- };
- //console.log(ajaxData);
- $.ajax({
- url: ajaxUrl + '?alt=' + altData + '&lat=' + ajaxData.lat + '&lon=' + ajaxData.lon + '&startYear=' + year + '&startMonth=' + month + '&startDay=' + day,
- type: 'GET',
- dataType: 'json',
- // data: ajaxData,
- })
- .done(function (data) {
- // //console.log(data);
- // //console.log(data.declination);
- contextmenuCPJ.innerHTML = "当前磁偏角:" + data.declination;
- //console.log("success");
- })
- .fail(function (data) {
- // //console.log(data);
- // //console.log("error");
- contextmenuCPJ.innerHTML = "当前磁偏角:暂无数据";
- })
- .always(function () {
- //console.log("complete");
- });
- }
- function getContextmenuDEMHeight(e) {
- contextmenuDEMHeight.innerHTML = '正在查询中...';
- var ajaxUrl = onemapUrlConfig.elevationDataUrl + '/v1.0/geoprocessing/single_elevation';
- var ajaxData = {
- lat: e.latlng.lat,
- lon: e.latlng.lng,
- zoom: map23DData.view.zoom,
- delta_zoom: 0
- };
- $.ajax({
- type: "get",
- dataType: 'json',
- data: ajaxData,
- url: ajaxUrl,
- beforeSend: ONEMAP.V.loading.load(),
- success: function (data) {
- if (data.code == 0) {
- contextmenuDEMHeight.innerHTML = "当前高程: " + data.data + "米";
- // getCP(data.data);
- } else {
- contextmenuDEMHeight.innerHTML = "当前高程: " + data.message;
- }
- },
- completer: ONEMAP.V.loading.loaded()
- });
- }
- /**
- * 获取当前点地形数据
- * [getTerrainanalysis description]
- * @return {[type]} [description]
- */
- function getTerrainanalysis(e) {
- contextmenuTerrainanalysis.innerHTML = '地形查询中...';
- var curlatlng = e.latlng.lat + "," + e.latlng.lng
- //获取该点坡向
- $.ajax({
- type: "get",
- dataType: 'json',
- data: {
- locations: curlatlng
- },
- url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/aspect',
- beforeSend: ONEMAP.V.loading.load(),
- success: function (data) {
- if (data.status == 'ok') {
- modValue.curPX = data.results[0].aspect.toFixed(3);
- contextmenuTerrainanalysis.innerHTML = "坡向: " + modValue.curPX;
- $.ajax({
- type: "get",
- dataType: 'json',
- data: {
- locations: curlatlng
- },
- url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/slope',
- beforeSend: ONEMAP.V.loading.load(),
- success: function (data) {
- if (data.status == 'ok') {
- modValue.PD = data.results[0].slope.toFixed(3);
- contextmenuTerrainanalysis.innerHTML = "坡向:" + modValue.curPX + ";坡度:" + modValue.PD;
- // getCP(data.data);
- } else {
- contextmenuTerrainanalysis.innerHTML = "坡向:无数据;坡度:无数据";
- }
- },
- completer: ONEMAP.V.loading.loaded()
- });
- // getCP(data.data);
- } else {
- contextmenuTerrainanalysis.innerHTML = "坡向: 无数据";
- }
- },
- completer: ONEMAP.V.loading.loaded()
- });
- }
- /**
- * 地图容器重置
- * @return {[type]} [description]
- */
- function mapResize() {
- if (ONEMAP.M.pcLayout.status.showFullMap) {
- $('#map3DWrap').css({
- height: $(window).height(),
- top: '0px'
- });
- } else {
- $('#map3DWrap').css({
- height: $(window).height(),
- top: '0px'
- });
- }
- setTimeout(function () {
- map2DViewer.map.invalidateSize();
- }, 100);
- }
- function resetMapCenterZoomLayer(center, zoom) {
- map2DViewer.setView({
- center: {
- lat: center.lat,
- lng: center.lon
- },
- zoom: zoom
- })
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(setSTLatLngLayer, 'mapHolder::STLatLngLayer');
- ONEMAP.C.publisher.subscribe(mapResize, 'layout::resize');
- };
- return ONEMAP.M.mapHolder = {
- init: init,
- modValue: modValue,
- mouseHand: mouseHand,
- removeMouseHand: removeMouseHand,
- getContextmenuPlaceName: getContextmenuPlaceName,
- resetMapCenterZoomLayer: resetMapCenterZoomLayer
- };
- })
|