gis-map-universal 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/gismap.umd.js +122 -23
  2. package/package.json +1 -1
package/gismap.umd.js CHANGED
@@ -266740,7 +266740,8 @@ var CityAreaLayer_component = normalizeComponent(
266740
266740
  stroke: new Stroke["default"]({
266741
266741
  color: lineItem.color,
266742
266742
  width: lineItem.width,
266743
- lineDash: lineItem.lineDash ? [10, 10] : undefined
266743
+ lineDash: lineItem.lineDash ? [10, 10] : undefined,
266744
+ lineCap: lineItem.lineCap || "butt"
266744
266745
  })
266745
266746
  }));
266746
266747
  lineFeature.set("popoup", lineItem.popoup);
@@ -266769,7 +266770,7 @@ var CityAreaLayer_component = normalizeComponent(
266769
266770
  });
266770
266771
  this.map.addLayer(this.lineLayer);
266771
266772
  },
266772
- // 高亮指定的线
266773
+ // 高亮指定的线(支持单条线或多条线)
266773
266774
  highlightLine(layerId, lineData, highlightColor = "#54f6ffff", highlightWidth = null) {
266774
266775
  // 首先清除之前的高亮
266775
266776
  this.clearLineHighlight(layerId);
@@ -266780,27 +266781,125 @@ var CityAreaLayer_component = normalizeComponent(
266780
266781
  // 查找对应的线要素
266781
266782
  const source = lineLayer.getSource();
266782
266783
  const features = source.getFeatures();
266783
- features.forEach(feature => {
266784
- const lineItemData = feature.get("lineItemData");
266785
- // 根据线数据的唯一标识或坐标匹配
266786
- if (this.isLineDataMatch(lineItemData, lineData)) {
266787
- // 应用高亮样式
266788
- const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266789
- feature.setStyle(new Style["default"]({
266790
- stroke: new Stroke["default"]({
266791
- color: highlightColor,
266792
- // 使用自定义高亮颜色
266793
- width: lineWidth,
266794
- // 使用自定义或默认高亮线宽
266795
- lineDash: lineItemData.lineDash ? [10, 10] : undefined
266796
- })
266797
- }));
266798
- // 保存高亮状态
266799
- feature.set("isHighlighted", true);
266800
- // 保存当前高亮样式信息
266801
- feature.set("highlightColor", highlightColor);
266802
- feature.set("highlightWidth", lineWidth);
266803
- }
266784
+
266785
+ // 将线数据转换为数组格式,以便统一处理
266786
+ const lineDataArray = Array.isArray(lineData) ? lineData : [lineData];
266787
+
266788
+ // 遍历所有线数据
266789
+ lineDataArray.forEach(currentLineData => {
266790
+ // 遍历所有线要素
266791
+ features.forEach(feature => {
266792
+ const lineItemData = feature.get("lineItemData");
266793
+ // 根据线数据的唯一标识或坐标匹配
266794
+ if (this.isLineDataMatch(lineItemData, currentLineData)) {
266795
+ // 获取当前要素的样式
266796
+ let currentStyle = feature.getStyle();
266797
+
266798
+ // 如果没有样式,使用默认样式(保持现有行为)
266799
+ if (!currentStyle) {
266800
+ // 应用默认高亮样式
266801
+ const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266802
+ feature.setStyle(new Style["default"]({
266803
+ stroke: new Stroke["default"]({
266804
+ color: highlightColor,
266805
+ // 使用自定义高亮颜色
266806
+ width: lineWidth,
266807
+ // 使用自定义或默认高亮线宽
266808
+ lineDash: lineItemData.lineDash ? [10, 10] : undefined
266809
+ })
266810
+ }));
266811
+ } else {
266812
+ // 复制当前样式并只修改线宽
266813
+ let newStyle;
266814
+
266815
+ // 处理多样式情况
266816
+ if (Array.isArray(currentStyle)) {
266817
+ // 找到包含stroke的样式
266818
+ const strokeStyleIndex = currentStyle.findIndex(style => style.getStroke() !== null);
266819
+ if (strokeStyleIndex !== -1) {
266820
+ // 复制样式数组
266821
+ newStyle = [...currentStyle];
266822
+ // 复制当前的stroke样式
266823
+ const currentStroke = currentStyle[strokeStyleIndex].getStroke();
266824
+ // 计算新的线宽
266825
+ const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266826
+
266827
+ // 创建新的stroke对象,保持原有颜色和其他属性,只修改宽度
266828
+ newStyle[strokeStyleIndex] = new Style["default"]({
266829
+ stroke: new Stroke["default"]({
266830
+ color: currentStroke.getColor(),
266831
+ // 保持原有颜色
266832
+ width: lineWidth,
266833
+ // 只修改线宽
266834
+ lineDash: currentStroke.getLineDash(),
266835
+ // 保持原有虚线样式
266836
+ lineCap: currentStroke.getLineCap(),
266837
+ // 保持原有线帽
266838
+ lineJoin: currentStroke.getLineJoin(),
266839
+ // 保持原有线连接
266840
+ miterLimit: currentStroke.getMiterLimit() // 保持原有斜接限制
266841
+ })
266842
+ });
266843
+ } else {
266844
+ // 如果没有找到stroke样式,使用默认行为
266845
+ const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266846
+ feature.setStyle(new Style["default"]({
266847
+ stroke: new Stroke["default"]({
266848
+ color: highlightColor,
266849
+ width: lineWidth,
266850
+ lineDash: lineItemData.lineDash ? [10, 10] : undefined
266851
+ })
266852
+ }));
266853
+ }
266854
+ } else {
266855
+ // 单样式情况
266856
+ const currentStroke = currentStyle.getStroke();
266857
+ if (currentStroke) {
266858
+ // 计算新的线宽
266859
+ const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266860
+
266861
+ // 创建新的样式,保持原有颜色和其他属性,只修改宽度
266862
+ newStyle = new Style["default"]({
266863
+ stroke: new Stroke["default"]({
266864
+ color: currentStroke.getColor(),
266865
+ // 保持原有颜色
266866
+ width: lineWidth,
266867
+ // 只修改线宽
266868
+ lineDash: currentStroke.getLineDash(),
266869
+ // 保持原有虚线样式
266870
+ lineCap: currentStroke.getLineCap(),
266871
+ // 保持原有线帽
266872
+ lineJoin: currentStroke.getLineJoin(),
266873
+ // 保持原有线连接
266874
+ miterLimit: currentStroke.getMiterLimit() // 保持原有斜接限制
266875
+ })
266876
+ });
266877
+ } else {
266878
+ // 如果没有stroke样式,使用默认行为
266879
+ const lineWidth = highlightWidth || lineItemData.originalWidth + 3;
266880
+ feature.setStyle(new Style["default"]({
266881
+ stroke: new Stroke["default"]({
266882
+ color: highlightColor,
266883
+ width: lineWidth,
266884
+ lineDash: lineItemData.lineDash ? [10, 10] : undefined
266885
+ })
266886
+ }));
266887
+ }
266888
+ }
266889
+
266890
+ // 应用新样式
266891
+ if (newStyle) {
266892
+ feature.setStyle(newStyle);
266893
+ }
266894
+ }
266895
+
266896
+ // 保存高亮状态
266897
+ feature.set("isHighlighted", true);
266898
+ // 保存当前高亮样式信息
266899
+ feature.set("highlightColor", highlightColor);
266900
+ feature.set("highlightWidth", highlightWidth || lineItemData.originalWidth + 3);
266901
+ }
266902
+ });
266804
266903
  });
266805
266904
  },
266806
266905
  // 清除线图层的所有高亮
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gis-map-universal",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "GIS通用组件",
5
5
  "main": "gismap.umd.js",
6
6
  "private": false,