/** * [ONEMAP.M.gcmsPolyline] * @return {[object]} */ define(function(){ //数据存放和外部调用 var modValue = { options:{}, mapDrawGroup:null, }; /** * 模块初始化 * @return {[type]} [description] */ function init(options){ if(options.type!="all"){ remove(); } modValue.mapDrawGroup = map23DControl.group({ action: 'add' }); modValue.options = {}; for(var op in options){ modValue.options[op] = options[op]; } //订阅推送 subscribe(); //modValue.mapDrawGroup.addTo(_map); //获取内容数据 getDetailData({callback:function(){ showDrawLayer(); }}); } /** * 坐标反转 * @param {[type]} latlngsAry [description] * @return {[type]} [description] */ function latLngsToReverse(latlngsAry){ var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry)); if(!$.isArray(tempLatlngsAry[0])){ return tempLatlngsAry.reverse(); }else { $(tempLatlngsAry).each(function(index, el) { tempLatlngsAry[index] = latLngsToReverse(el); }); } return tempLatlngsAry; }; function getDetailData(options){ ONEMAP.V.loading.load(); $.ajax({ url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'], type:"GET", dataType: 'json' }) .done(function(data) { ONEMAP.V.loading.loaded(); if(data.code == 4){ ONEMAP.T.noPermission('getDetailData'); } if(data.code == 3){ ONEMAP.T.logout('getDetailData'); } ONEMAP.D.gcmsCurArticleData = data['data']; options.callback(); }) .fail(function() { ONEMAP.V.loading.loaded(); }); } /** * 显示标注内容 * @return {[type]} [description] */ function showDrawLayer(){ var mapDrawData = JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']]); if(mapDrawData['features'].length>0){ $(mapDrawData['features']).each(function(index, el) { //switch(el['properties']['type']){ //case 'Polyline'://线 buildPolyline(el); // break; // } }); map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapDrawGroup].getBounds()); }else { ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add'); } } function buildPolyline(options){ if(!options['properties']['style']){ _.merge(options['properties'],{ style:{ color:'#0033ff', weight:5, opacity:0.5 } }) } map23DControl.polyline({ action: 'add', groupId: modValue.mapDrawGroup, geojson: { "properties": { altitudeMode:0, color: options['properties']['style'].color, weight: options['properties']['style'].weight, opacity: options['properties']['style'].opacity, }, "geometry": { "coordinates": options['geometry']['coordinates'] } } }) } /** * 注册监听 * @type {Function} */ function subscribe(){ ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove'); ONEMAP.C.publisher.subscribe(remove, 'cleanMap'); ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl'); } /** * 取消监听 * @type {Function} */ function unSubscribe() {} function GroupControl(type) { if (type == "show") { map23DControl.group({ action: 'show', guid: modValue.mapDrawGroup }) map23DControl.group({ action: 'show', guid: modValue.mapDrawGroup }) } else if (type == "hide") { map23DControl.group({ action: 'hide', guid: modValue.mapDrawGroup }) map23DControl.group({ action: 'hide', guid: modValue.mapDrawGroup }) } } /** * 模块移除 * @return {[type]} [description] */ function remove(){ map23DControl.group({ action: 'cleanAll', guid: modValue.mapDrawGroup }) map23DControl.group({ action: 'remove', guid: modValue.mapDrawGroup }) unSubscribe(); } return ONEMAP.M.gcmsPolyline = { init:init, remove:remove } });