123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- L.Control.MapChoose = L.Control.extend({
- options: {
- position: 'topright',
- },
- /**
- * 地图实例
- * @type {Object}
- * @private
- */
- _map: null,
- /**
- * 截图容器
- * @type {L}
- */
- _shotGroup: new L.FeatureGroup(),
- /**
- * 是否正在截图
- * @type {Boolean}
- * @default false
- * @private
- */
- _isScreenShot: false,
- initialize: function(options) {
- L.setOptions(this, options);
- return this;
- },
- onAdd: function(map) {
- this._map = map;
- this._map.addLayer(this._shotGroup);
- this.rectangle = new L.Draw.Rectangle(this._map);
- this._createControl();
- return this._container;
- },
- _createControl: function() {
- var _this = this;
- var className = 'leaflet-control-mapchoose',
- classNames = className + ' leaflet-bar leaflet-control';
- this._container = L.DomUtil.create('div', classNames);
- },
- /**
- * 初始化
- * @type {Function}
- */
- init: function() {
- var _this = this;
- _this.rectangle.enable();
- _this._shotGroup.clearLayers();
- _this._isScreenShot = true;
- L.DomUtil.addClass(_this._container, 'active');
- _this._map.on('draw:created', _this.drawCreated, this);
- _this._map.on('singleLayer:addToMap', _this.updatePanel, this);
- },
- layoutResize:function(){
- var curWindowHeigth = $(window).height();
- if(curWindowHeigth < 955){
- $("#mapHolder .leaflet-mapchoose-info").css({
- "left":-130
- })
- }else{
- $("#mapHolder .leaflet-mapchoose-info").css({
- "left":-179
- })
- }
- },
- /**
- * 更新截图信息面板
- * @param {[type]} layerObj [description]
- * @return {[type]} [description]
- */
- updatePanel: function(layerObj) {
- },
- updateShotBounds: function() {
- var _this = this;
- var bounds = _this.shotLayer.getBounds();
- console.log(bounds);
- },
- /**
- * 标注创建 添加到容器
- * @param e
- */
- drawCreated: function(e) {
- var _this = this;
- var type = e.layerType;
- _this.shotLayer = e.layer;
- _this._shotGroup.addLayer(_this.shotLayer);
- _this.shotLayer.editing.enable();
- var thematic = {
- curThematic: {
- min_zoom: 1,
- max_zoom: 19,
- translate: "未知",
- guid: 'null'
- }
- };
- var baseMapObj = {
- translate: null,
- guid: null
- }
- baseMapObj.guid = ONEMAP.M.mapHolder.modValue.mainLayers;
- thematic.curThematic.min_zoom = map2DViewer.map.getMinZoom(); //baseMapObj.options.minZoom
- thematic.curThematic.max_zoom = map2DViewer.map.getMaxZoom();
- if (baseMapObj.guid === 'gm') {
- baseMapObj.translate = '交通图';
- baseMapObj.guid = 'gm';
- }
- if (baseMapObj.guid === 'gr') {
- baseMapObj.translate = '影像图';
- baseMapObj.guid = 'gr';
- }
- if (baseMapObj.guid === 'gr') {
- baseMapObj.translate = '影像叠加地名图';
- baseMapObj.guid = 'gr';
- }
- if (baseMapObj.guid === 'gt') {
- baseMapObj.translate = '地势图';
- baseMapObj.guid = 'gt';
- }
- thematic.curThematic.translate = baseMapObj.translate;
- thematic.curThematic.guid = baseMapObj.guid;
- var thematicData = ONEMAP.D.ThematicInMapData;
- if (ONEMAP.D.overLayerCount > 0) {
- $(_this.labelThematic).show();
- $(_this.selectThematicType).show();
- $(_this.labelTypeP).hide();
- $(_this.labelTypeL).hide();
- } else {
- $(_this.labelThematic).hide();
- $(_this.selectThematicType).hide();
- $(_this.labelTypeP).show();
- $(_this.labelTypeL).show();
- }
- $(_this.selectThematicType).empty();
- $.each(thematicData, function(i, t) {
- var item = new Option(t.name, t.name);
- _this.selectThematicType.options.add(item);
- })
- _this.curLayerObj = thematic.curThematic;
- _this._map.on('editDraging', _this.updateShotBounds, this);
- var bounds = _this.shotLayer.getBounds();
- // console.log(bounds);
- },
- /**
- * 移除事件
- * @type {Function}
- */
- remove: function() {
- var _this = this;
- if (_this._map != null) {
- _this._isScreenShot = false;
- L.DomUtil.removeClass(_this._container, 'active');
- _this.rectangle.disable();
- _this._shotGroup.clearLayers();
- _this._map.off('draw:created', _this.drawCreated, this);
- _this._map.off('singleLayer:addToMap', _this.updatePanel, this);
- _this._map.off('editDraging', _this.updateShotBounds, this);
- }
- }
- });
- L.control.mapChoose = function(options) {
- return new L.Control.MapChoose(options);
- };
|