|
| 1 | +import {newGuid} from '../../service/common/Util'; |
| 2 | +import { L } from '../core/Base.js'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @class L.mapgis.MapLayer |
| 6 | + * @classdesc 新版igserver地图服务加载类 |
| 7 | + * @extends L.TileLayer |
| 8 | + * @example |
| 9 | + //地图容器 |
| 10 | + var map = L.map('leaf_map', { |
| 11 | + //添加缩放控件 |
| 12 | + zoomControl: true, |
| 13 | + //投影坐标系 |
| 14 | + crs: L.CRS.EPSG4326, |
| 15 | + //中心点[y,x] |
| 16 | + center: [(30.86431739220 + 30.3383275329) / 2, (114.57307983700002 + 113.97889584400014)/ 2],//武汉建筑 |
| 17 | + //最大级数 |
| 18 | + maxZoom: 10, |
| 19 | + //最小级数 |
| 20 | + minZoom: 7, |
| 21 | + //显示级数 |
| 22 | + zoom: 8 |
| 23 | + }); |
| 24 | + |
| 25 | + //创建地图图层 |
| 26 | + var mapLayer = new L.mapgis.MapLayer("http://192.168.199.71:8089/igs/rest/services/layertest/武汉建筑/MapServer", { |
| 27 | + layers:'show:0', |
| 28 | + imageFormat: 'jpg', |
| 29 | + filters:{"0":{"where":"Floor>10"}}, |
| 30 | + styles: {"0":{"displayRegionBorder":true}}, |
| 31 | + imageTransparent:false, |
| 32 | + //只显示一个图层,不平铺显示 |
| 33 | + noWrap: true |
| 34 | + }).addTo(map); |
| 35 | + */ |
| 36 | + |
| 37 | +var MapLayer = L.TileLayer.extend({ |
| 38 | + options: { |
| 39 | + imageFormat: null, |
| 40 | + imageHeight: 512, |
| 41 | + imageWidth: 512, |
| 42 | + guid:null, |
| 43 | + imageTransparent: null, |
| 44 | + filters: null, |
| 45 | + styles: null, |
| 46 | + layers: null, |
| 47 | + crs: null, |
| 48 | + isAntialiasing: null |
| 49 | + }, |
| 50 | + /** |
| 51 | + * |
| 52 | + * @param url - {String} 必选,地图服务的基地址。例如"http://192.168.199.71:8089/igs/rest/services/layertest/武汉建筑/MapServer". |
| 53 | + * @param options - {Object} 属性键值对,地图属性字段。 |
| 54 | + * @param {String} [options.imageFormat = 'png'] 可选,图片的格式,支持png|jpg|gif。 |
| 55 | + * @param {Object} [options.filters = null] 可选,图层的过滤信息。例如,{"0":{"where":"Floor>10"}}。 |
| 56 | + * @param {Object} [options.styles = null] 可选,图层的样式。例如,{"0":{"displayRegionBorder":true}}。 |
| 57 | + * @param {String} [options.layers = null] 可选,指定需要被取图的图层序列号。格式:show/hide/include/exclude: layerid1,layerid2。 |
| 58 | + 1 show:仅仅显示指定了图层序号的图层 |
| 59 | + 2 hide :显示除hide参数指定图层外所有的图层 |
| 60 | + 3 include:除显示默认图层(地图文档内图层状态为可见的图层)外,另追加这些被指定的图 层显示,追加的这些图层必须为地图中包含的图层。 |
| 61 | + 4 exclude: 从默认图层列表里删除这些被指定的图层后,进行显示 |
| 62 | + * @param {String} [options.crs = null] 可选,投影空间参照系,支持mapgis参照系名称和epsg编号。 |
| 63 | + * @param {Number} [options.imageHeight = 512] 可选,图片的高度。 |
| 64 | + * @param {Number} [options.imageWidth = 512] 可选,图片的宽度。 |
| 65 | + * @param {Boolean} [options.isAntialiasing = false] 可选,返回的图片是否抗锯齿。 |
| 66 | + * @param {Boolean} [options.imageTransparent = true] 可选,返回的图片是否透明。 |
| 67 | + * @param {String} [options.guid = newGuid()] 可选。唯一ID,用户标识地图文档。 |
| 68 | + * |
| 69 | + */ |
| 70 | + initialize: function (url, options) { |
| 71 | + this.url = encodeURI(url + '/image'); |
| 72 | + L.TileLayer.prototype.initialize.apply(this, arguments); |
| 73 | + L.setOptions(this, options); |
| 74 | + L.stamp(this); |
| 75 | + }, |
| 76 | + |
| 77 | + onAdd: function (map) { |
| 78 | + this._crs = map.options.crs; |
| 79 | + this._initLayerUrl(); |
| 80 | + L.TileLayer.prototype.onAdd.call(this, map); |
| 81 | + }, |
| 82 | + |
| 83 | + getTileUrl: function (coords) { |
| 84 | + var tileBounds = this._tileCoordsToBounds(coords); |
| 85 | + var nw = this._crs.project(tileBounds.getNorthWest()); |
| 86 | + var se = this._crs.project(tileBounds.getSouthEast()); |
| 87 | + var params = '&bbox=' + nw.x + ',' + se.y + ',' + se.x + ',' + nw.y; |
| 88 | + return this._layerUrl + encodeURI(params); |
| 89 | + }, |
| 90 | + |
| 91 | + _initLayerUrl: function () { |
| 92 | + var vm = this; |
| 93 | + var layerUrl = vm.url + '?'; |
| 94 | + layerUrl += encodeURI(vm._initAllRequestParams().join('&')); |
| 95 | + this._layerUrl = layerUrl; |
| 96 | + }, |
| 97 | + |
| 98 | + _initAllRequestParams: function () { |
| 99 | + var vm = this, |
| 100 | + options = vm.options || {}, |
| 101 | + params = []; |
| 102 | + |
| 103 | + var imageHeight = this.options.imageHeight; |
| 104 | + var imageWidth = this.options.imageWidth; |
| 105 | + params.push('size=' + imageWidth + ',' + imageHeight); |
| 106 | + |
| 107 | + var guid = options.guid || newGuid(); |
| 108 | + params.push("clientId=" + guid); |
| 109 | + |
| 110 | + if (options.imageFormat) { |
| 111 | + params.push('format=' + options.imageFormat); |
| 112 | + } |
| 113 | + if (options.layers) { |
| 114 | + params.push('layers=' + options.layers); |
| 115 | + } |
| 116 | + if (options.filters) { |
| 117 | + params.push('layerFilters=' + JSON.stringify(options.filters)); |
| 118 | + } |
| 119 | + if (options.styles) { |
| 120 | + params.push('layerStyles=' + JSON.stringify(options.styles)); |
| 121 | + } |
| 122 | + if (options.imageTransparent !== undefined && options.imageTransparent !== null) { |
| 123 | + params.push('transparent=' + options.imageTransparent); |
| 124 | + } |
| 125 | + |
| 126 | + if (options.crs) { |
| 127 | + params.push('projectionSrs=' + options.crs); |
| 128 | + } |
| 129 | + |
| 130 | + if (options.isAntialiasing !== undefined && options.isAntialiasing !== null) { |
| 131 | + params.push('isAntialiasing=' + options.isAntialiasing); |
| 132 | + } |
| 133 | + |
| 134 | + params.push('f=image'); |
| 135 | + |
| 136 | + return params; |
| 137 | + } |
| 138 | +}); |
| 139 | + |
| 140 | +export { MapLayer }; |
| 141 | +L.mapgis.MapLayer = MapLayer; |
| 142 | +export { L }; |
0 commit comments