123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- define("gmap/Common",["gmap/SymbolMgr",
- "esri/SpatialReference", "esri/geometry/Extent", "esri/geometry/Point", "esri/geometry/ScreenPoint",
- "esri/graphic",
- "esri/tasks/QueryTask", "esri/tasks/query",
- "dojo/_base/declare", "dojo/io/script", "dojo/_base/lang"],
- function (SymbolMgr,
- SpatialReference, Extent, Point, ScreenPoint,
- Graphic,
- QueryTask, Query,
- declare, script, lang) {
- return declare(null, {
- constructor: function (map, mapload) {
- this._map = map;
- this._mapload = mapload;
- //缩放到矩形
- this._map.ZoomToExtent = lang.hitch(this, function (xmin, ymin, xmax, ymax, zoomfactor) {
- this._ZoomToExtent(xmin, ymin, xmax, ymax, zoomfactor);
- });
- //缩放到级别
- this._map.ZoomToLevel = lang.hitch(this, function (level, lon, lat) {
- this._ZoomToLevel(level, lon, lat);
- });
- //添加临时用户数据
- this._map.AddGraphic = lang.hitch(this, function (gra) {
- this._AddGraphic(gra);
- });
- //移除临时用户数据
- this._map.RemoveGraphic = lang.hitch(this, function (gra) {
- this._RemoveGraphic(gra);
- });
- //清空临时用户数据
- this._map.ClearGraphic = lang.hitch(this, function () {
- this._ClearGraphic();
- });
- //缩放至Geometry
- this._map.ZoomToGeometry = lang.hitch(this, function (geometry, layerinfo) {
- this._ZoomToGeometry(geometry, layerinfo);
- });
- this._map.MapToScreen = lang.hitch(this, function (x, y) {
- var point = new Point(x, y, new SpatialReference({ wkid: this._map.WGS84WKID }));
- var mapPoint = this._map.ToMapSR(point);
- return this._map.MainMap.toScreen(mapPoint);
- });
- this._map.SetFullExtent = lang.hitch(this, function (xmin, ymin, xmax, ymax) {
- this._FullExtent = new Extent(xmin, ymin, xmax, ymax, new SpatialReference({ wkid: this._map.WGS84WKID }));
- });
- this._map.ScreenToMap = lang.hitch(this, function (x, y) {
- var screenPoint = new ScreenPoint(x, y);
- var point = this._map.MainMap.toMap(screenPoint);
- return this._map.ToWGS84(point);
- });
- this._map.Hilight = lang.hitch(this, this._Hilight);
- this._map.ClearHilight = lang.hitch(this, this._ClearHilight);
- this._map._getScaleLevel = function (scale) {
- for (var i = 0, c = this.Lods.length; i < c; i++) {
- if (scale >= this.Lods[i].scale) {
- return this.Lods[i].level;
- }
- }
- return this.Lods[this.Lods.length - 1].level;
- };
- this._map._getLevelScale = function (level) {
- for (var i = 0, c = this.Lods.length; i < c; i++) {
- if (level >= this.Lods[i].level) {
- return this.Lods[i].scale;
- }
- }
- return this.Lods[this.Lods.length - 1].scale;
- };
- this._map.GetScale = lang.hitch(this, function () {
- return this._map.MainMap.getScale();
- });
- this._map.GetMinScale = lang.hitch(this, function () {
- return this._map.MainMap.getMinScale();
- });
- this._map.GetMaxScale = lang.hitch(this, function () {
- return this._map.MainMap.getMaxScale();
- });
- this._map.GetVisible = lang.hitch(this, function () {
- return this._map.MainMap.visible;
- });
- // 获取定位级别
- this._map._getShowScale = function (layerinfo, checkLabel) {
- if (checkLabel == null) checkLabel = false;
- if (checkLabel != true && checkLabel != false) checkLabel = false;
- var minScale = 0;
- var maxScale = 0;
- if (layerinfo.minScale != 0) {
- if (minScale == 0 || layerinfo.minScale < minScale) minScale = layerinfo.minScale;
- }
- if (layerinfo.maxScale != 0) {
- if (maxScale == 0 || layerinfo.maxScale > maxScale) maxScale = layerinfo.maxScale;
- }
- if (layerinfo.drawingInfo.labelingInfo && layerinfo.drawingInfo.labelingInfo.length > 0 && layerinfo.hasLabels == true && checkLabel == true) {
- for (var i = 0; i < layerinfo.drawingInfo.labelingInfo.length; i++) {
- var lblInfo = layerinfo.drawingInfo.labelingInfo[i];
- if (lblInfo.minScale != 0) {
- if (minScale == 0 || lblInfo.minScale < minScale) minScale = lblInfo.minScale;
- }
- if (lblInfo.maxScale != 0) {
- if (maxScale == 0 || lblInfo.maxScale > maxScale) maxScale = lblInfo.maxScale;
- }
- }
- }
- if (layerinfo.effectiveMinScale != null && layerinfo.effectiveMinScale != 0) {
- if (minScale == 0 || layerinfo.effectiveMinScale < minScale) minScale = layerinfo.effectiveMinScale;
- }
- if (layerinfo.effectiveMaxScale != null && layerinfo.effectiveMaxScale != 0) {
- if (maxScale == 0 || layerinfo.effectiveMaxScale > maxScale) maxScale = layerinfo.effectiveMaxScale;
- }
- return { maxScale: maxScale, minScale: minScale };
- }
- },
- _ZoomToGeometry: function (geometry, layerinfo) {
- var mapGeo = this._map.ToMapSR(geometry);
- var gcsGeo = this._map.ToWGS84(geometry);
- var geoWidthLevel = null;
- var geoHeightLevel = null;
- if (mapGeo.type == "polyline" || mapGeo.type == "polygon") {
- var extent = mapGeo.getExtent();
- var width = extent.xmax - extent.xmin;
- var resWidth = width / this._map.MainMap.width;
- geoWidthLevel = this._map.Lods[this._map.Lods.length - 1].level;
- for (var i = 0; i < this._map.Lods.length - 1; i++) {
- var lod1 = this._map.Lods[i];
- var lod2 = this._map.Lods[i + 1];
- if (resWidth < lod1.resolution && resWidth > lod2.resolution) {
- geoWidthLevel = lod1.level;
- break;
- }
- }
- var height = extent.ymax - extent.ymin;
- var resHeight = height / this._map.MainMap.height;
- geoHeightLevel = this._map.Lods[this._map.Lods.length - 1].level;
- for (var i = 0; i < this._map.Lods.length - 1; i++) {
- var lod1 = this._map.Lods[i];
- var lod2 = this._map.Lods[i + 1];
- if (resHeight < lod1.resolution && resHeight > lod2.resolution) {
- geoHeightLevel = lod1.level;
- break;
- }
- }
- }
- var geoLevel = (geoWidthLevel == null || geoHeightLevel == null) ?
- null : (geoHeightLevel < geoWidthLevel ? geoHeightLevel : geoWidthLevel);
- var level = this._getLocateLevel(layerinfo, geoLevel);
- var point = this._getPoint(gcsGeo);
- this._map.ZoomToLevel(level, point.x, point.y);
- },
- // 获取中心点
- _getPoint: function (geometry) {
- switch (geometry.type) {
- case "point":
- return geometry;
- case "extent":
- return geometry.getCenter();
- default:
- return geometry.getExtent().getCenter();
- }
- },
- // 获取定位级别
- _getLocateLevel: function (layerinfo, geoLevel) {
- var minLevel = this._map.MinLevel;
- var maxLevel = this._map.MaxLevel;
- var scaleInfo = this._map._getShowScale(layerinfo, true);
- if (scaleInfo.minScale != 0) {
- var level = this._map._getScaleLevel(scaleInfo.minScale);
- if (level > minLevel) minLevel = level;
- }
- if (scaleInfo.maxScale != 0) {
- var level = this._map._getScaleLevel(scaleInfo.maxScale) - 1;
- if (level < maxLevel) maxLevel = level;
- }
- if (geoLevel == null) {
- return Math.ceil((minLevel + maxLevel) / 2);//这种情况只有点
- }
- else {
- var level = geoLevel; //获取当前级别
- if (level > maxLevel) {
- return maxLevel;
- }
- else if (level < minLevel) {
- return minLevel;
- }
- else {
- return level;
- }
- }
- },
- _Hilight: function (geo) {
- geo = this._map.ToMapSR(geo);
- var gra = new Graphic();
- gra.geometry = geo;
- if (geo.type == "point") {
- gra.setSymbol(SymbolMgr.GetHilightPointCircleSymbol());
- }
- else if (geo.type == "polyline") {
- gra.setSymbol(SymbolMgr.GetHilightLineSymbol());
- }
- else if (geo.type == "polygon" || geo.type == "extent") {
- gra.setSymbol(SymbolMgr.GetHilightFillSymbol());
- }
- this._mapload.DrawHilightLayer.add(gra);
- },
- _ClearHilight: function () {
- this._mapload.DrawHilightLayer.clear();
- },
- //缩放到矩形
- _ZoomToExtent: function (xmin, ymin, xmax, ymax, zoomfactor) {
- var fromPt = this._map.ToMapSR(new Point(xmin, ymin, new SpatialReference({ wkid: this._map.WGS84WKID })));
- var toPt = this._map.ToMapSR(new Point(xmax, ymax, new SpatialReference({ wkid: this._map.WGS84WKID })));
- var extent = new Extent(fromPt.x, fromPt.y, toPt.x, toPt.y, fromPt.spatialReference);
- if (zoomfactor != null) extent = extent.expand(zoomfactor);
- this._map.MainMap.setExtent(extent);
- },
- //缩放到级别
- _ZoomToLevel: function (level, lon, lat) {
- var point = this._map.ToMapSR(new Point(lon, lat, new SpatialReference({ wkid: this._map.WGS84WKID })));
- this._map.MainMap.centerAndZoom(point, level - this._map.MinLevel);
- },
- //添加临时用户数据
- _AddGraphic: function (gra) {
- if (gra && gra.geometry && gra.geometry.type) {
- gra.geometry = this._map.ToWGS84(gra.geometry);
- if (gra.geometry.type == "point") {
- this._mapload.Temp_PointLayer.add(gra);
- return true;
- }
- else if (gra.geometry.type == "polyline") {
- this._mapload.Temp_LineLayer.add(gra);
- return true;
- }
- else if (gra.geometry.type == "polygon") {
- this._mapload.Temp_AreaLayer.add(gra);
- return true;
- }
- }
- return false;
- },
- //移除临时用户数据
- _RemoveGraphic: function (gra) {
- if (gra && gra.geometry && gra.geometry.type) {
- if (gra.geometry.type == "point") {
- this._mapload.Temp_PointLayer.remove(gra);
- return true;
- }
- else if (gra.geometry.type == "polyline") {
- this._mapload.Temp_LineLayer.remove(gra);
- return true;
- }
- else if (gra.geometry.type == "polygon") {
- this._mapload.Temp_AreaLayer.remove(gra);
- return true;
- }
- }
- return false;
- },
- //清空临时用户数据
- _ClearGraphic: function () {
- this._mapload.Temp_PointLayer.clear();
- this._mapload.Temp_LineLayer.clear();
- this._mapload.Temp_AreaLayer.clear();
- }
- });
- });
|