123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /**
- * [ONEMAP.M.gcmsPoint]
- * @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 'Point'://点
- buildMarker(el);
- //break;
- //}
- });
- map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapDrawGroup].getBounds());
-
- }else {
- ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
- }
- }
- function buildMarker(options){
- map23DControl.marker({
- action: 'add',
- groupId: modValue.mapDrawGroup,
- geojson: {
- "properties": {
- altitudeMode:0,
- iconUrl: onemapUrlConfig.gcmsServiceUrl+'/file'+options['properties']['style']['iconUrl'],
- iconSize: options['properties']['style']['iconSize'],
- iconAnchor: options['properties']['style']['iconAnchor'],
- popupAnchor: [0,-options['properties']['style']['iconAnchor'][1]]
- },
- "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.gcmsPoint = {
- init:init,
- remove:remove
- }
- });
|