123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- /**
- * [ONEMAP.M.gcmsPointAPicture]
- * @return {[object]}
- */
- define([
- 'html!templates/gcms/gcmsPicture',
- 'vendorDir/handlebars/handlebars',
- 'css!styles/gcms/gcmsPicture'],
- function(tpcLayout,Handlebars){
- //数据存放和外部调用
- var modValue = {
- options:{},
- iviewer:null,
- pictureUrl:null,
- mapPointGroup:null,
- }
-
- /**
- * 模块初始化
- * @return {[type]} [description]
- */
- function init(options){
- remove();
- modValue.mapPointGroup = map23DControl.group({
- action: 'add'
- });
- modValue.options = {};
- for(var op in options){
- modValue.options[op] = options[op];
- }
- //获取内容数据
- getDetailData();
-
-
- //订阅推送
- subscribe();
- }
- 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');
- }
- if(JSON.parse(data['data']['record'][modValue.options['field_name']])['features'].length == 0){
- ONEMAP.C.publisher.publish({ type: 'warning', message: '没有图片数据' }, 'noteBar::add');
- remove();
- }else {
- ONEMAP.D.gcmsCurArticleData = data['data'];
- showPoint();
- }
- })
- .fail(function() {
- ONEMAP.V.loading.loaded();
- });
- }
- function showPoint(){
- 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 'PictureLocation'://点
- buildMarker(el);
- break;
- }
- });
- map2DViewer.map.fitBounds(map2DViewer.groups[modValue.mapPointGroup].getBounds());
-
- }else {
- ONEMAP.C.publisher.publish({ type: 'warning', message: '没有标注数据' }, 'noteBar::add');
- }
- };
- function buildMarker(options){
- var curGuid = map23DControl.marker({
- action: 'add',
- groupId: modValue.mapPointGroup,
- geojson: {
- "properties": {
- altitudeMode:0,
- iconUrl: onemapUrlConfig.gcmsServiceUrl+'/file'+options['properties']['style']['iconUrl']+'?jwt='+ONEMAP.D.user.ticket,
- iconSize: options['properties']['style']['iconSize'],
- iconAnchor: options['properties']['style']['iconAnchor'],
- popupAnchor: [0,-options['properties']['style']['iconAnchor'][1]]
- },
- "geometry": {
- "coordinates": options['geometry']['coordinates']
- }
- }
- });
- var file = options['properties']['file'];
- var oLabelObj = '<a href="javascript:ONEMAP.M.gcmsPointAPicture.setPictureModal(\''+file+'\')">显示图片</a>';
- var options_popup = {
- name:'',
- content:oLabelObj
- };
- var new_popupHtml = ONEMAP.M.gcmsNav.creatPopupHtml(options_popup);
- map2DViewer.markers[curGuid].bindPopup(new_popupHtml,{
- closeButton:false,
- maxWidth:60,
- minWidth:40});
- map2DViewer.markers[curGuid].openPopup();
- map2DViewer.markers[curGuid].on('mouseover',function(){
- this.openPopup();
- })
- }
- /**
- * 设置容器
- */
- function setPictureModal(file){
- modValue.pictureUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+file+'?jwt='+ONEMAP.D.user.ticket;
- $('#gcmsPictureViewer').remove();
- $('body').append(tpcLayout);
- bindEvent();
- $('#gcmsPictureViewer').show();
- if(modValue.iviewer){
- modValue.iviewer.iviewer('loadImage', modValue.pictureUrl);
- return false;
- }else {
- modValue.iviewer = $("#gcmsPictureViewerBox").iviewer(
- {
- zoom_max:200,
- zoom_min:5,
- src: modValue.pictureUrl
- });
- }
- }
- /**
- * 事件绑定
- * @return {[type]} [description]
- */
- function bindEvent(){
- layoutResize();
- $('#gcmsPictureViewer .popup-ct .close').bind('click', function() {
- remove();
- });
- $('#gcmsPictureViewer .popup-ct').dragmove($('#gcmsPictureViewer'));
- var $box2 = $('#gcmsPictureViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) {
- var posix = {
- 'w': $box2.width(),
- 'h': $box2.height(),
- 'x': e.pageX,
- 'y': e.pageY
- };
-
- $.extend(document, {'move': true, 'call_down': function(e) {
- $box2.css({
- 'width': Math.max(30, e.pageX - posix.x + posix.w),
- 'height': Math.max(30, e.pageY - posix.y + posix.h)
- });
- var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-75;
- $("#gcmsPictureViewer .modal-body").css({height:bodyHeight});
- $("#gcmsPictureViewerBox").iviewer('update');
- }});
- return false;
- });
- }
- /**
- * 界面布局重置
- * @type {Function}
- */
- function layoutResize(){
- $('#gcmsPictureViewer .modal-body').css({height:$(window).height()/2});
- }
-
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe(){
- ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
- ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
- ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
- ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
- }
- /**
- * 取消监听
- * @type {Function}
- */
- function unSubscribe() {
- ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
- }
- function GroupControl(type) {
- if (type == "show") {
- map23DControl.group({
- action: 'show',
- guid: modValue.mapPointGroup
- })
- map23DControl.group({
- action: 'show',
- guid: modValue.mapPointGroup
- })
- } else if (type == "hide") {
- map23DControl.group({
- action: 'hide',
- guid: modValue.mapPointGroup
- })
- map23DControl.group({
- action: 'hide',
- guid: modValue.mapPointGroup
- })
- }
- }
- /**
- * 模块移除
- * @return {[type]} [description]
- */
- function remove(){
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.mapPointGroup
- })
- map23DControl.group({
- action: 'remove',
- guid: modValue.mapPointGroup
- })
- $('#gcmsPictureViewer').remove();
- unSubscribe();
- modValue.iviewer = null;
- }
- return ONEMAP.M.gcmsPointAPicture = {
- init:init,
- remove:remove,
- setPictureModal:setPictureModal
- }
- });
|