123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- /**
- * 绘制点
- * [ONEMAP.M.gcmsDrawPoint]
- * @return {[object]}
- */
- define(function() {
- //数据存放和外部调用
- var modValue = {
- options: {},
- mapDrawGroup: null,
- };
- /**
- * 模块初始化
- * @return {[type]} [description]
- */
- function init(options) {
- 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() {
- showDrawPoint();
- }
- });
- }
- /**
- * 坐标反转
- * @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 showDrawPoint() {
- 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) {
- var coordinates = options.geometry.coordinates;
- for(var i=0;i<coordinates.length;i++){
- map23DControl.marker({
- action: 'add',
- groupId: modValue.mapDrawGroup,
- geojson: {
- "properties": {
- altitudeMode: 0,
- iconUrl: map23DConfig.map23DAssetsUrl+'/images/gcms/marker-icon.png',
- iconSize: [32,32],
- iconAnchor: [16,32]
- },
- "geometry": {
- "coordinates": coordinates[i]
- }
- }
- })
- }
- }
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'gcmsArticleShowRemove');
- ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
- ONEMAP.C.publisher.subscribe(GroupControl, 'gcmsGroupControl');
- }
- 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
- })
- }
- }
- /**
- * 取消监听
- * @type {Function}
- */
- function unSubscribe() {}
- /**
- * 模块移除
- * @return {[type]} [description]
- */
- function remove() {
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.mapDrawGroup
- })
- map23DControl.group({
- action: 'remove',
- guid: modValue.mapDrawGroup
- })
- 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 ONEMAP.M.gcmsDrawPoint = {
- init: init,
- remove: remove
- }
- });
|