define(function() { /** * 状态值 * @type {Boolean} * @default false * @private */ var status = { initialized: false, //是否初始化 veiwHeightType: null }; /** * 模块数据 用于数据存储和外部调用 * @type {Object} * 数据存放 */ var modValue = { drawId: [] }; /** * 可是分析初始化 */ function init() { if (!status.initialized) { subscribe(); status.initialized = true; } ONEMAP.C.publisher.publish({ modName: 'toolKSFX' }, 'tools:active'); }; /** * 注册监听事件 */ function subscribe() { ONEMAP.C.publisher.subscribe(remove, 'tools:active'); ONEMAP.C.publisher.subscribe(removetoolKSFX, 'cleanMap'); ONEMAP.C.publisher.subscribe(removeEvent, 'change23D'); }; function removeEvent() { if (map23DData.show3DAlert) { locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态 locaSpaceMap.Refresh(); } $('#coverHeightKSFX').hide(); closeCircleControl(); } /** * 通视分析加载或移除 */ function remove(options) { if (options.modName != 'toolKSFX') { if (options.modName == 'cleanMap') { removetoolKSFX(); } $(".tools-KSFX").removeClass('cur'); } else { if ($(".tools-KSFX").hasClass('cur')) { $(".tools-KSFX").removeClass('cur'); removetoolKSFX(); } else { $(".tools-KSFX").addClass('cur'); addtoolKSFX(); } } } /** *移除通视分析 */ function removetoolKSFX() { if (map23DData.show3DAlert) { locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态 locaSpaceMap.Refresh(); } if (modValue.group) { map23DControl.group({ action: 'remove', guid: modValue.group, }) modValue.group = false; } $('#coverHeightKSFX').hide(); closeCircleControl(); }; /** * 加载通视分析 */ function addtoolKSFX() { $('#coverHeightKSFX').show(); $('#coverHeightKSFX .cancel').unbind('click').bind('click', function() { $('#coverHeightKSFX').hide(); $(".tools-KSFX").removeClass('cur'); removetoolKSFX(); }); $('#coverHeightKSFX .sure').unbind('click').bind('click', function() { if (!modValue.group) { modValue.group = map23DControl.group({ action: 'add' }) } var height = parseInt($('#coverHeightKSFX .input').val()); modValue.viewHeight = height; if (height > 0 && height < 1000) { $('#coverHeightKSFX').hide(); if (map23DData.show3DAlert) { locaSpaceMap.Globe.CenterHeightOfViewshedAnalysis = height; locaSpaceMap.Globe.Action = 13; locaSpaceMap.Refresh(); } openCircleControl(); $(".tools-KSFX").removeClass('cur'); } else { alert('请输入大于0小于1000的高度值'); } }); }; function closeCircleControl() { //map2DViewer.drawCircleResult = function(){} map2DViewer.removeCircle(); } function openCircleControl() { map2DViewer.drawCircleResult = function(data) { if (data.radius > 10000) { alert('半径过大,建议小于10000米') } else { modValue.radius = data.radius; modValue.coordinates = data.startpoint; var guid = map2DViewer.marker({ action: 'add', groupId: modValue.group, geojson: { "properties": { title: '', iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker/b3.png', iconSize: [10, 24], iconAnchor: [5, 24], }, "geometry": { "coordinates": [modValue.coordinates[1], modValue.coordinates[0]] } } }) showKSY(); } } map2DViewer.drawCircle(); } function showKSY() { var coods = [modValue.coordinates[1].toFixed(5),modValue.coordinates[0].toFixed(5)] $.ajax({ type: 'get', dataType: 'json', url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/viewshed', data: { lng: coods[0], lat: coods[1], radius: modValue.radius, height: modValue.viewHeight }, success: function(data) { $.each(data.features, function(i, t) { var guid = map2DViewer.polygon({ action: 'add', groupId: modValue.group, geojson: { "properties": { title: '测试polygon', color: '#00ffcc', weight: 1, fillColor: '#00ffcc', opacity: 0.7, fillOpacity: 0.7, popupContent: '' }, "geometry": { "type": "Polygon", "coordinates": t.geometry.coordinates } } }) }) closeCircleControl(); }, error: function(errorData) { ONEMAP.V.loading.loaded(); } }) } return ONEMAP.M.toolKSFX = { init: init } })