map-ol-utils 0.0.26 → 0.0.28
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.
- package/dist/index.cjs +21 -3
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +21 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -162,6 +162,24 @@ var import_control = require("ol/control");
|
|
|
162
162
|
// src/layer-utils.ts
|
|
163
163
|
var import_gcoord = __toESM(require("gcoord"), 1);
|
|
164
164
|
var import_geom = require("ol/geom");
|
|
165
|
+
|
|
166
|
+
// src/helper.ts
|
|
167
|
+
var hexToRgba = (hex, alpha) => {
|
|
168
|
+
if (hex.startsWith("#")) {
|
|
169
|
+
let tempHex = hex.replace("#", "");
|
|
170
|
+
if (tempHex.length === 3) {
|
|
171
|
+
tempHex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
172
|
+
}
|
|
173
|
+
const r = parseInt(tempHex.substring(0, 2), 16);
|
|
174
|
+
const g = parseInt(tempHex.substring(2, 4), 16);
|
|
175
|
+
const b = parseInt(tempHex.substring(4, 6), 16);
|
|
176
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
177
|
+
} else {
|
|
178
|
+
return hex;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/layer-utils.ts
|
|
165
183
|
var import_format2 = require("ol/format");
|
|
166
184
|
var import_ol = require("ol");
|
|
167
185
|
var import_interaction = require("ol/interaction");
|
|
@@ -224,7 +242,7 @@ var assembleGeoJson = (dataList, config) => {
|
|
|
224
242
|
return import_gcoord.default.transform({ type: "FeatureCollection", features: tempList }, import_gcoord.default.GCJ02, import_gcoord.default.WGS84);
|
|
225
243
|
};
|
|
226
244
|
var createVectorStyle = (data, config) => {
|
|
227
|
-
const { isLine, colorMap, fillColor, colorKey, strokeColor, strokeWeight } = config || {};
|
|
245
|
+
const { isLine, colorMap, fillColor, colorKey, strokeColor, strokeWeight, fillOpacity } = config || {};
|
|
228
246
|
const style = new import_style.Style({
|
|
229
247
|
stroke: new import_style.Stroke({
|
|
230
248
|
width: strokeWeight,
|
|
@@ -234,7 +252,7 @@ var createVectorStyle = (data, config) => {
|
|
|
234
252
|
if (!isLine) {
|
|
235
253
|
style.setFill(
|
|
236
254
|
new import_style.Fill({
|
|
237
|
-
color: colorKey ? (colorMap == null ? void 0 : colorMap.get(data[colorKey])) || fillColor : fillColor
|
|
255
|
+
color: hexToRgba((colorKey ? (colorMap == null ? void 0 : colorMap.get(data[colorKey])) || fillColor : fillColor) || "", fillOpacity || 1)
|
|
238
256
|
})
|
|
239
257
|
);
|
|
240
258
|
}
|
|
@@ -262,7 +280,7 @@ var removeAllLayers = (isClearAll = true) => {
|
|
|
262
280
|
removeOverlays();
|
|
263
281
|
console.log(isClearAll);
|
|
264
282
|
if (instance) {
|
|
265
|
-
instance.
|
|
283
|
+
instance.getAllLayers().forEach((layer) => {
|
|
266
284
|
if (!layer.get("_isBaseLayer")) {
|
|
267
285
|
instance.removeLayer(layer);
|
|
268
286
|
}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -107,6 +107,24 @@ import { defaults } from "ol/control";
|
|
|
107
107
|
// src/layer-utils.ts
|
|
108
108
|
import gcoord from "gcoord";
|
|
109
109
|
import { Point } from "ol/geom";
|
|
110
|
+
|
|
111
|
+
// src/helper.ts
|
|
112
|
+
var hexToRgba = (hex, alpha) => {
|
|
113
|
+
if (hex.startsWith("#")) {
|
|
114
|
+
let tempHex = hex.replace("#", "");
|
|
115
|
+
if (tempHex.length === 3) {
|
|
116
|
+
tempHex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
117
|
+
}
|
|
118
|
+
const r = parseInt(tempHex.substring(0, 2), 16);
|
|
119
|
+
const g = parseInt(tempHex.substring(2, 4), 16);
|
|
120
|
+
const b = parseInt(tempHex.substring(4, 6), 16);
|
|
121
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
122
|
+
} else {
|
|
123
|
+
return hex;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/layer-utils.ts
|
|
110
128
|
import { GeoJSON } from "ol/format";
|
|
111
129
|
import { Feature, Overlay } from "ol";
|
|
112
130
|
import { Select } from "ol/interaction";
|
|
@@ -169,7 +187,7 @@ var assembleGeoJson = (dataList, config) => {
|
|
|
169
187
|
return gcoord.transform({ type: "FeatureCollection", features: tempList }, gcoord.GCJ02, gcoord.WGS84);
|
|
170
188
|
};
|
|
171
189
|
var createVectorStyle = (data, config) => {
|
|
172
|
-
const { isLine, colorMap, fillColor, colorKey, strokeColor, strokeWeight } = config || {};
|
|
190
|
+
const { isLine, colorMap, fillColor, colorKey, strokeColor, strokeWeight, fillOpacity } = config || {};
|
|
173
191
|
const style = new Style({
|
|
174
192
|
stroke: new Stroke({
|
|
175
193
|
width: strokeWeight,
|
|
@@ -179,7 +197,7 @@ var createVectorStyle = (data, config) => {
|
|
|
179
197
|
if (!isLine) {
|
|
180
198
|
style.setFill(
|
|
181
199
|
new Fill({
|
|
182
|
-
color: colorKey ? (colorMap == null ? void 0 : colorMap.get(data[colorKey])) || fillColor : fillColor
|
|
200
|
+
color: hexToRgba((colorKey ? (colorMap == null ? void 0 : colorMap.get(data[colorKey])) || fillColor : fillColor) || "", fillOpacity || 1)
|
|
183
201
|
})
|
|
184
202
|
);
|
|
185
203
|
}
|
|
@@ -207,7 +225,7 @@ var removeAllLayers = (isClearAll = true) => {
|
|
|
207
225
|
removeOverlays();
|
|
208
226
|
console.log(isClearAll);
|
|
209
227
|
if (instance) {
|
|
210
|
-
instance.
|
|
228
|
+
instance.getAllLayers().forEach((layer) => {
|
|
211
229
|
if (!layer.get("_isBaseLayer")) {
|
|
212
230
|
instance.removeLayer(layer);
|
|
213
231
|
}
|