Skip to content

Commit abc9490

Browse files
committed
【update】更新dist目录 review by zhaoqin
1 parent f06e90e commit abc9490

File tree

4 files changed

+561
-76
lines changed

4 files changed

+561
-76
lines changed

dist/openlayers/iclient9-openlayers-es6.js

Lines changed: 245 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64725,6 +64725,7 @@ external_ol_default.a.supermap.Util = core_Util_Util;
6472564725

6472664726

6472764727
external_ol_default.a.supermap = external_ol_default.a.supermap || {};
64728+
var padding = 8, doublePadding = padding*2;
6472864729

6472964730
/**
6473064731
* @class ol.supermap.StyleUtils
@@ -65362,22 +65363,215 @@ class StyleUtils_StyleUtils {
6536265363
lineDash: this.dashStyle(style, 1)
6536365364
});
6536465365
olStyle.setStroke(newStroke);
65365-
} else {
65366+
} else if(type === 'POLYGON' ||
65367+
type === 'MULTIPOLYGON'){
6536665368
newFill = new external_ol_default.a.style.Fill({
6536765369
color: fillColorArray
6536865370
});
6536965371
newStroke = new external_ol_default.a.style.Stroke({
6537065372
width: strokeWidth || ZERO,
6537165373
color: strokeColorArray,
6537265374
lineCap: lineCap || 'round',
65373-
lineDash: this.dashStyle(style, 1)
65375+
lineDash:this.dashStyle(style, 1)
6537465376
});
6537565377
olStyle.setFill(newFill);
6537665378
olStyle.setStroke(newStroke);
65379+
} else {
65380+
let result = this.getCanvas(style);
65381+
newImage = new external_ol_default.a.style.Icon({
65382+
img: result.canvas,
65383+
imgSize:[result.width,result.height],
65384+
scale: 1,
65385+
anchor : [0.5, 0.5]
65386+
});
65387+
olStyle.setImage(newImage);
6537765388
}
6537865389
return olStyle;
6537965390
}
6538065391

65392+
/**
65393+
* 获取文字标注对应的canvas
65394+
* @param style
65395+
* @returns {{canvas: *, width: number, height: number}}
65396+
*/
65397+
static getCanvas(style) {
65398+
let canvas;
65399+
if(style.canvas) {
65400+
if(document.querySelector("#"+style.canvas)) {
65401+
canvas = document.getElemntById(style.canvas);
65402+
} else {
65403+
canvas = this.createCanvas(style);
65404+
}
65405+
} else {
65406+
//不存在canvas,当前feature
65407+
canvas = this.createCanvas(style);
65408+
style.canvas = canvas.id;
65409+
}
65410+
canvas.style.display = "none";
65411+
var ctx = canvas.getContext("2d");
65412+
//行高
65413+
let lineHeight = Number(style.font.replace(/[^0-9]/ig,""));
65414+
let textArray = style.text.split('\r\n');
65415+
let lenght = textArray.length;
65416+
//在改变canvas大小后再绘制。否则会被清除
65417+
ctx.font = style.font;
65418+
let size = this.drawRect(ctx, style, textArray, lineHeight, canvas);
65419+
this.positionY = padding;
65420+
if(lenght > 1) {
65421+
textArray.forEach(function (text, i) {
65422+
if(i !== 0) {
65423+
this.positionY = this.positionY + lineHeight;
65424+
}
65425+
this.canvasTextAutoLine(text,style,ctx,lineHeight, size.width);
65426+
}, this);
65427+
} else {
65428+
this.canvasTextAutoLine(textArray[0],style,ctx,lineHeight, size.width);
65429+
}
65430+
return {
65431+
canvas: canvas,
65432+
width: size.width,
65433+
height: size.height
65434+
};
65435+
}
65436+
/**
65437+
* 创建当前feature对应的canvas
65438+
* @param style {object}
65439+
* @returns {HTMLElement}
65440+
*/
65441+
static createCanvas(style) {
65442+
let div = document.createElement('div');
65443+
document.body.appendChild(div);
65444+
let canvas = document.createElement('canvas');
65445+
canvas.id = style.canvas ? style.canvas : 'textCanvas' + core_Util_Util.newGuid(8);
65446+
div.appendChild(canvas);
65447+
return canvas;
65448+
}
65449+
/**
65450+
* 绘制矩形边框背景
65451+
* @param ctx
65452+
* @param style
65453+
* @param textArray
65454+
* @param lineHeight
65455+
* @param canvas
65456+
* @returns {{width: number, height: number}}
65457+
*/
65458+
static drawRect(ctx, style, textArray, lineHeight, canvas) {
65459+
let backgroundFill = style.backgroundFill, maxWidth = style.maxWidth - doublePadding;
65460+
let width, height = 0, lineCount=0, lineWidths = [];
65461+
//100的宽度,去掉左右两边3padding
65462+
textArray.forEach(function (arrText) {
65463+
let line='', isOverMax;
65464+
lineCount++;
65465+
for (var n = 0; n < arrText.length; n++) {
65466+
let textLine = line + arrText[n];
65467+
let metrics = ctx.measureText(textLine);
65468+
let textWidth = metrics.width;
65469+
if ((textWidth > maxWidth && n > 0) || arrText[n] === '\n') {
65470+
line = arrText[n];
65471+
lineCount++;
65472+
//有换行,记录当前换行的width
65473+
isOverMax = true;
65474+
} else {
65475+
line = textLine;
65476+
width = textWidth;
65477+
}
65478+
}
65479+
if(isOverMax) {
65480+
lineWidths.push(maxWidth);
65481+
} else {
65482+
lineWidths.push(width);
65483+
}
65484+
}, this);
65485+
width = this.getCanvasWidth(lineWidths, maxWidth);
65486+
height = lineCount * lineHeight;
65487+
height += doublePadding;
65488+
canvas.width = width;
65489+
canvas.height = height;
65490+
ctx.fillStyle = backgroundFill;
65491+
ctx.fillRect(0,0,width,height);
65492+
return {
65493+
width: width,
65494+
height: height
65495+
}
65496+
}
65497+
/**
65498+
* 获取自适应的宽度(如果没有超过最大宽度,就用文字的宽度)
65499+
* @param lineWidths
65500+
* @param maxWidth
65501+
* @returns {number}
65502+
*/
65503+
static getCanvasWidth(lineWidths, maxWidth) {
65504+
let width = 0;
65505+
for(let i=0; i< lineWidths.length; i++) {
65506+
let lineW = lineWidths[i];
65507+
if(lineW >= maxWidth) {
65508+
//有任何一行超过最大高度,就用最大高度
65509+
return maxWidth + doublePadding;
65510+
} else if(lineW > width) {
65511+
//自己换行,就要比较每行的最大宽度
65512+
width = lineW;
65513+
}
65514+
}
65515+
return width + doublePadding;
65516+
}
65517+
/**
65518+
* 绘制文字,解决换行问题
65519+
* @param text
65520+
* @param style
65521+
* @param ctx
65522+
* @param lineHeight
65523+
*/
65524+
static canvasTextAutoLine(text,style,ctx,lineHeight, canvasWidth) {
65525+
// 字符分隔为数组
65526+
ctx.font = style.font;
65527+
let textAlign = style.textAlign;
65528+
let x = this.getPositionX(textAlign, canvasWidth);
65529+
let arrText = text.split('');
65530+
let line = '', fillColor = style.fillColor;
65531+
//每一行限制的高度
65532+
let maxWidth= style.maxWidth - doublePadding;
65533+
for (var n = 0; n < arrText.length; n++) {
65534+
let testLine = line + arrText[n];
65535+
let metrics = ctx.measureText(testLine);
65536+
let testWidth = metrics.width;
65537+
if ((testWidth > maxWidth && n > 0) || arrText[n] === '\n') {
65538+
ctx.fillStyle = fillColor;
65539+
ctx.textAlign=textAlign;
65540+
ctx.textBaseline="top";
65541+
ctx.fillText(line, x, this.positionY);
65542+
line = arrText[n];
65543+
this.positionY += lineHeight;
65544+
} else {
65545+
line = testLine;
65546+
}
65547+
}
65548+
ctx.fillStyle = fillColor;
65549+
ctx.textAlign=textAlign;
65550+
ctx.textBaseline="top";
65551+
ctx.fillText(line, x, this.positionY);
65552+
}
65553+
/**
65554+
* 得到绘制的起点位置,根据align不同,位置也不同
65555+
* @param textAlign
65556+
* @returns {number}
65557+
*/
65558+
static getPositionX(textAlign, canvasWidth) {
65559+
let x;
65560+
let width = canvasWidth - doublePadding; //减去padding
65561+
switch (textAlign) {
65562+
case 'center':
65563+
x = width / 2;
65564+
break;
65565+
case 'right':
65566+
x = width;
65567+
break;
65568+
default:
65569+
x = 8;
65570+
break;
65571+
}
65572+
return x;
65573+
}
65574+
6538165575
/**
6538265576
* @function ol.supermap.StyleUtils.hexToRgb
6538365577
* @description 将16进制的颜色,转换成rgb格式
@@ -66877,6 +67071,7 @@ const transformTools = new external_ol_default.a.format.GeoJSON();
6687767071
* @param {function} [options.errorCallback] - 加载地图失败。
6687867072
* @param {string} [options.credentialKey] - 凭证密钥。
6687967073
* @param {string} [options.credentialValue] - 凭证值。
67074+
* @param {boolean} [options.excludePortalProxyUrl] - server传递过来的url是否带有代理
6688067075
* @param {function} [options.mapSetting.mapClickCallback] - 地图被点击的回调函数
6688167076
* @extends {ol.Observable}
6688267077
*/
@@ -66892,6 +67087,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6689267087
this.credentialKey = options.credentialKey;
6689367088
this.credentialValue = options.credentialValue;
6689467089
this.target = options.target || "map";
67090+
this.excludePortalProxyUrl = options.excludePortalProxyUrl || false;
6689567091
}
6689667092
this.createMap(options.mapSetting);
6689767093
this.createWebmap();
@@ -66935,13 +67131,23 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6693567131
* @description 创建webmap
6693667132
*/
6693767133
createWebmap() {
66938-
// let appUrl = this.mapUrl;
6693967134
let mapUrl = core_Util_Util.getRootUrl(this.mapUrl) + 'web/maps/' + this.mapId + '/map';
6694067135
if (this.credentialValue) {
6694167136
mapUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
66942-
// appUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
67137+
67138+
}
67139+
let filter = 'getUrlResource.json?url=';
67140+
if(this.excludePortalProxyUrl && this.mapUrl.indexOf(filter) > -1) {
67141+
//大屏需求,或者有加上代理的
67142+
let urlArray = this.mapUrl.split(filter);
67143+
if(urlArray.length > 1) {
67144+
let url = urlArray[1];
67145+
mapUrl = urlArray[0] + filter + core_Util_Util.getRootUrl(url) + 'web/maps/' + this.mapId + '/map.json';
67146+
}
6694367147
}
6694467148
//todo 请求用户以及更新时间和地图标签等参数,暂时不需要
67149+
// let appUrl = this.mapUrl;
67150+
// appUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
6694567151
// this.getAppInfo(appUrl);
6694667152
this.getMapInfo(mapUrl);
6694767153
}
@@ -66976,7 +67182,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6697667182
that.addLayers(mapInfo);
6697767183
}
6697867184
}).catch(function (error) {
66979-
that.errorCallback && that.errorCallback(error, 'getMapFaild');
67185+
that.errorCallback && that.errorCallback(error, 'getMapFaild', that.map);
6698067186
});
6698167187
}
6698267188
/**
@@ -66989,7 +67195,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6698967195
this.createView(mapInfo);
6699067196
let layer = this.createBaseLayer(mapInfo);
6699167197
this.map.addLayer(layer);
66992-
if (mapInfo.baseLayer && mapInfo.baseLayer.lableLayerVisible) {
67198+
if (mapInfo.baseLayer && mapInfo.baseLayer.labelLayerVisible) {
6699367199
let layerInfo = mapInfo.baseLayer;
6699467200
//存在天地图路网
6699567201
let labelLayer = new external_ol_default.a.layer.Tile({
@@ -67089,16 +67295,26 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6708967295
default:
6709067296
break;
6709167297
}
67092-
let layer = new external_ol_default.a.layer.Tile({
67298+
var layer = new external_ol_default.a.layer.Tile({
6709367299
source: source,
6709467300
zIndex: layerInfo.zIndex || 0,
6709567301
visible: layerInfo.visible
6709667302
});
67303+
var layerId = core_Util_Util.newGuid(8);
6709767304
if (layerInfo.name) {
6709867305
layer.setProperties({
67099-
name: layerInfo.name
67306+
name: layerInfo.name,
67307+
layerId: layerId
6710067308
});
6710167309
}
67310+
if(!mapInfo.baseLayer) {
67311+
//不是底图
67312+
layer.setVisible(layerInfo.visible);
67313+
layerInfo.opacity && layer.setOpacity(layerInfo.opacity);
67314+
}
67315+
//否则没有ID,对不上号
67316+
layerInfo.layer = layer;
67317+
layerInfo.layerId = layerId;
6710267318
return layer;
6710367319
}
6710467320
/**
@@ -67296,7 +67512,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6729667512
callback(layerInfo);
6729767513
}
6729867514
}).catch(function (error) {
67299-
that.errorCallback && that.errorCallback(error, 'getWmtsFaild')
67515+
that.errorCallback && that.errorCallback(error, 'getWmtsFaild', that.map)
6730067516
});
6730167517
}
6730267518

@@ -67447,6 +67663,13 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6744767663
}).then(function (response) {
6744867664
return response.json()
6744967665
}).then(function (data) {
67666+
if(!data.succeed === false) {
67667+
//请求失败
67668+
layerAdded++;
67669+
that.sendMapToUser(layerAdded, len);
67670+
that.errorCallback && that.errorCallback(data.error, 'getLayerFaild', that.map);
67671+
return;
67672+
}
6745067673
if (data && data.type) {
6745167674
if (data.type === "JSON" || data.type === "GEOJSON") {
6745267675
data.content = JSON.parse(data.content);
@@ -67461,7 +67684,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6746167684
}).catch(function (error) {
6746267685
layerAdded++;
6746367686
that.sendMapToUser(layerAdded, len);
67464-
that.errorCallback && that.errorCallback(error, 'getLayerFaild');
67687+
that.errorCallback && that.errorCallback(error, 'getLayerFaild', that.map);
6746567688
})
6746667689
} else if (layer.layerType === 'SUPERMAP_REST' || layer.layerType === "TILE" ||
6746767690
layer.layerType === "WMS" || layer.layerType === "WMTS") {
@@ -67496,7 +67719,7 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6749667719
}, function (err) {
6749767720
layerAdded++;
6749867721
that.sendMapToUser(layerAdded, len);
67499-
that.errorCallback && that.errorCallback(err, 'getFeatureFaild')
67722+
that.errorCallback && that.errorCallback(err, 'getFeatureFaild', that.map)
6750067723
});
6750167724
} else if (layer.dataSource.type === "REST_MAP" && layer.dataSource.url) {
6750267725
core_Util_Util.queryFeatureBySQL(layer.dataSource.url, layer.dataSource.layerName, 'smid=1', null, null, function (result) {
@@ -67515,10 +67738,13 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6751567738
that.addLayer(layer, features);
6751667739
layerAdded++;
6751767740
that.sendMapToUser(layerAdded, len);
67741+
},function (e) {
67742+
layerAdded++;
67743+
that.errorCallback && that.errorCallback(e, 'getFeatureFaild', that.map);
6751867744
});
6751967745
}
6752067746
}, function (e) {
67521-
that.errorCallback && that.errorCallback(e, 'getFeatureFaild');
67747+
that.errorCallback && that.errorCallback(e, 'getFeatureFaild', that.map);
6752267748
})
6752367749
}
6752467750
}, this);
@@ -67766,12 +67992,18 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6776667992
} else if (layerInfo.layerType === "MARKER") {
6776767993
layer = this.createMarkerLayer(layerInfo, features)
6776867994
}
67995+
let layerId = core_Util_Util.newGuid(8);
6776967996
if (layer && layerInfo.name) {
6777067997
layer.setProperties({
67771-
name: layerInfo.name
67998+
name: layerInfo.name,
67999+
layerId: layerId
6777268000
});
6777368001
}
6777468002
layer && this.map.addLayer(layer);
68003+
layerInfo.layer = layer;
68004+
layerInfo.opacity && layer.setOpacity(layerInfo.opacity);
68005+
layer.setVisible(layerInfo.visible);
68006+
layerInfo.layerId = layerId;
6777568007
if (layerInfo.labelStyle && layerInfo.labelStyle.labelField) {
6777668008
//存在标签专题图
6777768009
this.addLabelLayer(layerInfo, features);
@@ -67838,7 +68070,6 @@ class WebMap_WebMap extends external_ol_default.a.Observable {
6783868070
isHighLight: false,
6783968071
onClick: function () {}
6784068072
});
67841-
source.refresh();
6784268073
return new external_ol_default.a.layer.Image({
6784368074
source: source
6784468075
});

0 commit comments

Comments
 (0)