123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- /**
- * map操作类
- * Created by Administrator on 2017/11/8.
- */
- define([], function () {
- var map = {
- /**
- * 创建图层组
- */
- createLayer: function (clustering) {
- if (!clustering) clustering = false;
- return map23DControl.group({
- action: 'add',
- clustering: clustering //是否开启聚合
- })
- },
- /**
- * 清空图层组
- */
- clearLayer: function (Guid) {
- map23DControl.group({
- action: 'clearAll',
- guid: Guid
- })
- },
- /**
- * 移除图层组
- */
- removeLayer: function (Guid) {
- if (!Guid) return;
- map23DControl.group({
- action: 'remove',
- guid: Guid
- })
- },
- /**
- * 添加一个marker
- */
- addMarker: function (title, iconurl, iconSize, iconRorate, popupContent, lat, lng, groupId) {
- var markerOp = {
- action: 'add',//添加 //'delete'删除//'update'修改
- groupId: groupId, //所加载图层id
- visible2D: true,
- visible3D: true,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,//标题
- iconUrl: iconurl,//图标地址
- iconSize: [iconSize, iconSize],//图标大小
- iconAnchor: [iconSize / 2, iconSize / 2],//图标中心点偏移值
- popupAnchor: [0, 0],//冒泡窗与中心点的偏移值
- altitude: 0,//高度
- popupContent: popupContent,//冒泡窗内容
- iconRorate: iconRorate,//图标旋转角度
- },
- "geometry": {
- "type": "Point",
- "coordinates": [lng, lat]//经纬度
- }
- }
- }
- return map23DControl.marker(markerOp);
- },
- /**
- * 添加一个marker在2D地图
- */
- addMarkerTo2D: function (title, iconurl, iconSize, iconRorate, popupContent, lat, lng, groupId) {
- var markerOp = {
- action: 'add',//添加 //'delete'删除//'update'修改
- groupId: groupId, //所加载图层id
- visible2D: true,
- visible3D: false,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,//标题
- iconUrl: iconurl,//图标地址
- iconSize: [iconSize, iconSize],//图标大小
- iconAnchor: [iconSize / 2, iconSize / 2],//图标中心点偏移值
- popupAnchor: [0, 0],//冒泡窗与中心点的偏移值
- altitude: 0,//高度
- popupContent: popupContent,//冒泡窗内容
- iconRorate: iconRorate,//图标旋转角度
- },
- "geometry": {
- "type": "Point",
- "coordinates": [lng, lat]//经纬度
- }
- }
- }
- return map23DControl.marker(markerOp);
- },
- /**
- * 添加一个文字marker
- */
- addText: function (title, test, size, color, fontWeight, lat, lng, groupId, add3D, anchorX, anchorY) {
- if (anchorX != 0 && !anchorX) anchorX = size / 2;
- if (anchorY != 0 && !anchorY) anchorY = size / 2;
- var markerOp = {
- action: 'add',//添加 //'delete'删除//'update'修改
- groupId: groupId,
- visible2D: true,
- visible3D: true,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,//标题
- iconUrl: '/dist/images/marker.svg',
- iconSize: [size, size],//图标大小
- iconAnchor: [anchorX, anchorY],//图标中心点偏移值
- popupAnchor: [0, -14],//冒泡窗与中心点的偏移值
- altitude: 0,//高度
- fontIcon: test,//字体图标
- fontSize: size,//字体图标大小
- fontColor: color,//字体图标颜色
- fontWeight: fontWeight, //字体粗细
- popupContent: '',
- altitudeMode: 0
- },
- "geometry": {
- "type": "Point",
- "coordinates": [lng, lat]//经纬度
- }
- }
- }
- return map23DControl.marker(markerOp);
- },
- /**
- * 添加一条线
- * @param title 标题
- * @param color 颜色
- * @param weight 宽度
- * @param dash 虚线宽度 false未非虚线
- * @param points 点的集合(点为先lng后lat)
- * @param groupId 要添加的图层ID
- * @param addTo3D 是否添加到3D地图
- */
- addPolyline: function (title, color, weight, dash, points, groupId, addTo3D) {
- var alts = [];
- var type;
- if (dash) { //虚线
- type = 3;
- }
- for (var i = 0; i < points.length; i++) { //给定高度,防止3维遮挡
- alts.push(5000);
- }
- return map23DControl.polyline({
- action: 'add',
- groupId: groupId,
- visible2D: true,
- visible3D: addTo3D,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,
- color: color,
- weight: weight,
- opacity: 1,
- popupContent: '',
- altitude: alts,//高度
- // altitude: [10, 10, 10, 10, 10, 10, 10],
- lineJoin: 'miter',
- lineCap: 'butt',
- dashArray: dash,
- lineType: type
- },
- "geometry": {
- "type": "LineString",
- "coordinates": points //[lng, lat]
- }
- }
- })
- },
- /**
- * 添加一个圆
- */
- addCircle: function (title, radius, color, fillColor, lat, lng, layer) {
- return map23DControl.circle({
- action: 'add',
- groupId: layer,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,
- color: color,
- weight: 1,
- fillColor: fillColor,
- opacity: 1,
- fillOpacity: 0.5,
- // popupContent: '',
- // extrude: 18000, //拉伸高度
- // altitude: 11000, //点海拔高度
- // altitudeMode: 1, //海拔模式
- radius: radius
- },
- "geometry": {
- "type": "Circle",
- "coordinates": [lng, lat]
- }
- }
- });
- },
- /**
- * 添加填充区域
- */
- addPolygon: function (title, color, fillColor, lnglats, lnglats2, layer) {
- var alts = [];
- for (var i = 0; i < lnglats.length; i++) {
- alts.push(5000);
- }
- return map23DControl.polygon({
- action: 'add',
- groupId: layer,
- geojson: {
- "type": "Feature",
- "properties": {
- title: title,
- color: color,
- weight: 3,
- fillColor: fillColor,
- opacity: 1,
- fillOpacity: 0.5,
- popupContent: '',
- altitude: alts
- },
- "geometry": {
- "type": "Polygon",
- "coordinates": [lnglats, lnglats2]
- }
- }
- });
- },
- /**
- * 23D地图添加图片覆盖物
- */
- addImage: function (url, slat, slng, elat, elng, opacity) {
- if (!opacity && opacity != 0) opacity = 1;
- var guid = map23DControl.imageOverlay({
- action: 'add',
- from: '23D',
- type: 'imageOverlay',
- layers: {
- opacity: opacity,//2D透明度
- layerBounds: [[slng, slat], [elng, elat]],//左上角 右下角
- imageUrl2D: url,//2D图片地址
- imageUrl3D: url//3D图片服务地址
- }
- })
- return guid;
- },
- /**
- * 23D地图删除图片覆盖物
- */
- removeImage: function (guid) {
- map23DControl.imageOverlay({
- action: 'remove',
- from: '23D',
- guid: guid
- })
- },
- /**
- * 23D地图更新图片覆盖物(更改透明度)
- * @param guid
- * @param opacity
- */
- upDateImage: function (guid, opacity) {
- map23DControl.imageOverlay({
- action: 'update',
- from: '23D',
- guid: guid,
- type: 'imageOverlay',
- layers: {
- opacity: opacity,//2D透明度
- // layerBounds: [[100, 39], [120, -49]],//左上角 右下角
- // imageUrl2D: map23DConfig.map23DAssetsUrl + '/data/weixing/sdt_marker.png',//2D图片地址
- // imageUrl3D: map23DConfig.map23DAssetsUrl + '/data/weixing/sdt_marker.png'//3D图片服务地址
- }
- })
- },
- //-------------------------------地图状态工具方法----------------------------------------
- getBounds: function () { //获取当前显示范围
- if (map.mapType == '2d') {
- var se = [];
- se.push(map2DViewer.map.getBounds().getSouthWest().lat);
- se.push(map2DViewer.map.getBounds().getSouthWest().lng);
- se.push(map2DViewer.map.getBounds().getNorthEast().lat);
- se.push(map2DViewer.map.getBounds().getNorthEast().lng);
- return se;
- } else {
- var topLeft = map23DUtil.get3DPixToLnglat('topleft');
- var bottomRight = map23DUtil.get3DPixToLnglat('bottomright');
- var slat = topLeft.lat < bottomRight.lat ? topLeft.lat : bottomRight.lat;
- var slng = topLeft.lng < bottomRight.lng ? topLeft.lng : bottomRight.lng;
- var elat = topLeft.lat < bottomRight.lat ? bottomRight.lat : topLeft.lat;
- var elng = topLeft.lng < bottomRight.lng ? bottomRight.lng : topLeft.lng;
- var se = [];
- se.push(slat);
- se.push(slng);
- se.push(elat);
- se.push(elng);
- return se;
- }
- },
- getZoom: function () { //获取缩放层级
- if (map.mapType == '2d') {
- return map2DViewer.map._zoom;
- } else {
- return map.zoom3d;
- }
- },
- init: function () {
- //2D地图移动监听
- map2DViewer.map.on('moveend', function () {
- if (map.mapType != '2d') return;
- for (var key in meteo.f) {
- if (meteo.f[key].onMove) meteo.f[key].onMove();
- }
- });
- //23D地图切换监听
- ONEMAP.C.publisher.subscribe(function (type) {
- map.mapType = type;
- //修改时间轴2/3D地图背景样式
- $('.meteo-time-boxone').toggleClass('meteo-time-boxbg');
- }, 'change23D');
- //3D地图移动监听
- ONEMAP.C.publisher.subscribe(function (zoom) {
- if (map.mapType == '2d') return;
- map.zoom3d = zoom;
- var topLeft = map23DUtil.get3DPixToLnglat('topleft');
- var bottomRight = map23DUtil.get3DPixToLnglat('bottomright');
- if (!topLeft.lat || !topLeft.lng || !bottomRight.lat || !bottomRight.lng) {
- //只要当前有一个点没有数据,就不触发marker重绘
- return;
- }
- for (var key in meteo.f) {
- if (meteo.f[key].onMove) meteo.f[key].onMove();
- }
- }, 'mapChange23D');
- },
- mapType: '2d',
- zoom3d: null,
- }
- map.init();
- return map;
- })
|