map-ol-utils 0.0.1 → 0.0.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.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +120 -22
- package/dist/index.d.ts +132 -46
- package/dist/index.js +1 -1
- package/package.json +3 -6
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ie=Object.create;var f=Object.defineProperty,ye=Object.defineProperties,le=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols,ge=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var B=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,M=(t,e)=>{for(var r in e||(e={}))I.call(e,r)&&B(t,r,e[r]);if(b)for(var r of b(e))ue.call(e,r)&&B(t,r,e[r]);return t},F=(t,e)=>ye(t,me(e));var fe=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},D=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pe(e))!I.call(t,s)&&s!==r&&f(t,s,{get:()=>e[s],enumerable:!(o=le(e,s))||o.enumerable});return t};var p=(t,e,r)=>(r=t!=null?ie(ge(t)):{},D(e||!t||!t.__esModule?f(r,"default",{value:t,enumerable:!0}):r,t)),he=t=>D(f({},"__esModule",{value:!0}),t);var ve={};fe(ve,{activeMarkerByUid:()=>ae,addMassMarksLayer:()=>se,buildMassMarksStyles:()=>S,createBaseLayer:()=>h,createGeoJsonLayer:()=>g,createMapInstance:()=>U,createMapWorldLayer:()=>Y,createMassMarksLayer:()=>C,createSelectByLayer:()=>A,createVectorFaceLayer:()=>te,createVectorLineLayer:()=>re,disposeMap:()=>j,emitter:()=>x,getMapInstance:()=>P,instance:()=>a,resetActiveMarker:()=>oe,resetActiveVector:()=>ee,resetMap:()=>T,resetZoomAndCenter:()=>V,updateMarksLayersByStatus:()=>ne});module.exports=he(ve);var E=p(require("mitt"),1),de=(0,E.default)(),x=de;var J=require("ol/source"),W=require("ol/source"),X=require("ol/tilegrid"),k=require("ol/layer");var G=p(require("ol/Map"),1),N=p(require("ol/View"),1),_=require("ol/control");var a,U=(t={})=>{let e=Object.assign({zoom:9,maxZoom:18,minZoom:9,baseLayer:"vec-layer",projection:"EPSG:4326",layers:[h()],smoothExtentConstraint:!1,tk:"c77eddc667c5bed016fded560baf93e7",center:[119.5326450625435,29.8845606679097]},t||{});return a?(a.getLayers().on("remove",o=>{let s=o.element;a.removeInteraction(s.get("_selectInteraction"))}),a):(a=new G.default({view:new N.default(e),controls:(0,_.defaults)({attribution:!1,zoom:!1,rotate:!1}),layers:e.layers||[h()]}),a.activeBaseLayer=e.baseLayer,a.getLayerByName=O,a.removeLayerByName=Z,a.changeLayersByNames=$,a.on("pointermove",o=>{a.getTargetElement().style.cursor=a.hasFeatureAtPixel(o.pixel)?"pointer":""}),a)},V=()=>{},P=()=>{},T=()=>{},j=()=>{a.getAllLayers().forEach(e=>{a.removeLayer(e)}),a.setTarget(""),a=void 0};var R=p(require("ol/tilegrid/WMTS"),1),h=(t=!0)=>new k.Tile({zIndex:1,minZoom:8,maxZoom:21,source:new J.XYZ({tileGrid:new X.TileGrid({tileSize:256,resolutions:[.005492298,.002746149,.0013730745,.00068653725,.000343268625,.0001716343125,8581715625e-14,42908578125e-15,214542890625e-16,1072714453125e-17,5363572265625e-18,26817861328125e-19,134089306640625e-20],origin:[118.122911693886,31.2869311022836],extent:[118.340502132662,29.2073269598186,120.724787992425,30.5617943760008]}),projection:"EPSG:4326",urls:t?["https://ywtg.citybrain.hangzhou.gov.cn:9456/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9457/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9458/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9459/hzsyvector_dark/{z}/{y}/{x}","https://cb.hangzhoumap.gov.cn/E36CCEA93443D1495DB9B9F2B2FFE348CB1A367D75176F815040AB19E54CDCA5DAAA25813AF965E2ABD0CC2463DD1223/PBS/rest/services/hzsyvector_dark/Mapserver/tile/{z}/{y}/{x}"]:["https://ywtg.citybrain.hangzhou.gov.cn:9456/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9457/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9458/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9459/hzsyvector/{z}/{y}/{x}","https://cb.hangzhoumap.gov.cn/E36CCEA93443D1495DB9B9F2B2FFE348CB1A367D75176F815040AB19E54CDCA5DAAA25813AF965E2ABD0CC2463DD1223/PBS/rest/services/hzsyvector/Mapserver/tile/{z}/{y}/{x}"]})}),Y=(t,e,r="c77eddc667c5bed016fded560baf93e7")=>{let[o,s]=t.split("_");return new k.Tile({className:e,cacheSize:20240,zIndex:-1,source:new W.WMTS({crossOrigin:"anonymous",projection:"EPSG:4326",wrapX:!0,layer:o,style:"default",version:"1.0.0",format:"image/png",matrixSet:s,tileGrid:new R.default({origin:[-180,90],matrixIds:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],resolutions:[.703125,.3515625,.17578125,.087890625,.0439453125,.02197265625,.010986328125,.0054931640625,.00274658203125,.001373291015625,.0006866455078125,.00034332275390625,.000171661376953125,858306884765625e-19,4291534423828125e-20,21457672119140625e-21,10728836059570312e-21,5364418029785156e-21,2682209014892578e-21]}),url:`https://t{0-7}.tianditu.gov.cn/${t}/wmts?tk=${r}`})})},O=t=>a.getAllLayers().find(e=>e.getClassName()===t),Z=t=>{let e=a.getAllLayers().find(r=>r.getClassName()===t);e&&a.removeLayer(e)},$=(t,e)=>{a.getAllLayers().filter(o=>e.includes(o.getClassName())).forEach(o=>{o.setVisible(t==null?void 0:t.includes(o.getClassName()))})};var q=require("ol"),H=require("ol/geom");var K=require("ol/interaction"),w=p(require("ol/layer/Vector"),1),z=p(require("ol/source/Vector"),1),i=require("ol/style"),Q=require("ol/format");var ee=()=>{a.getLayers().forEach(e=>{let r=e.get("_selectInteraction");r&&r.getFeatures().clear()})},Le=(t,e)=>{let{key:r,isLine:o}=e,s=[];return t.forEach(n=>{try{let c=Array.isArray(n[r])?n[r]:JSON.parse(n[r]||"[]");c.length&&s.push({type:"Feature",properties:M({},n),geometry:{coordinates:c,type:o?"Polyline":"Polygon"}})}catch(c){console.error(c),console.error(`\u521B\u5EFA\u7EBF\u72B6\u6570\u636E\u5931\u8D25\uFF1A${n.toString()}`)}}),{type:"FeatureCollection",features:s}},g=(t,e)=>{let{isLine:r,layerName:o}=e||{},s=Le(t,e),n=new w.default({className:o||"ol-layer",source:new z.default({features:new Q.GeoJSON().readFeatures(s)}),style:r?new i.Style({stroke:new i.Stroke({color:"red",lineDash:[10],width:3})}):new i.Style({stroke:new i.Stroke({color:"red",lineDash:[10],width:3}),fill:new i.Fill({color:"rgba(0, 0, 255, 0.1)"})})});return n.set("_layerName",o),n},te=(t=[],e)=>g(t,Object.assign(e,{isLine:!1})),re=(t=[],e)=>g(t,Object.assign(e,{isLine:!0}));var oe=()=>{},ae=t=>(e,r=!0)=>{console.log("activeMarkerByUid",e,r,t)},S=t=>e=>{let{baseUrl:r,markerIcon:o,markerSize:s=[32,32],statusNum:n=5,activeScale:c=1.3}=e,d=t(r),[L,v]=s,u=new Array(n*2);for(let y=0;y<n;y++){let l=d(`${o}-${y}`,".webp");u[y]=new i.Style({zIndex:88+y,image:new i.Icon({src:l,anchor:[L/2,v]})});let m=d(`${o}-${y}-active`,".webp");u[y+n]=new i.Style({zIndex:102,image:new i.Icon({src:m||l,anchor:[L/2*c,v*c],size:s.map(ce=>ce*c)})})}return u},A=t=>{let e=new K.Select({style:null,layers:[t]});return e.on("select",r=>{let{selected:o,deselected:s}=r;if(o.length){let n=o[0],c=n.getProperties();n.setStyle(c.activeStyle),x.emit("marker-click",c)}if(s.length){let n=s[0],c=n.getProperties();n.setStyle(c.unActiveStyle)}}),a.addInteraction(e),t.set("_selectInteraction",e),e},C=(t,e=[])=>{let r=t.map(s=>{let n=new q.Feature({geometry:new H.Point([+s.lnglat[0],+s.lnglat[1]])});return n.setProperties(F(M({},s),{unActiveStyle:e[s.style],activeStyle:e[s.style+e.length/2]})),n.setStyle(e[s.style]),n}),o=new w.default({source:new z.default({features:r})});return o.setProperties({_isCustom:!0,_dataList:t,_isMassMarksLayer:!0,_statusNum:e.length/2}),o},se=t=>(e=[],r,o=!0)=>{let{baseUrl:s,hasLine:n,hasFace:c,isDynamic:d,statusNum:L,markerIcon:v,markerSize:u}=r,y=S(t)({baseUrl:s,markerIcon:v,markerSize:u,activeScale:1.3,statusNum:L||5}),l=C(e,y);if(o&&A(l),n){let m=g(e,{key:"line",isLine:!0,strokeColor:"rgba(29, 235, 255, 0.8)"});a.addLayer(m)}if(c){let m=g(e,{isLine:!1,key:"faceList",fillOpacity:.1,fillColor:"#4247DF",strokeWeight:1,strokeStyle:"dashed",strokeColor:"#4247DF"});a.addLayer(m)}return l.setProperties({_hasLine:n,_hasFace:c,_isDynamic:d}),l.setMap(a),l},ne=(t=[])=>{console.log(t)};0&&(module.exports={activeMarkerByUid,addMassMarksLayer,buildMassMarksStyles,createBaseLayer,createGeoJsonLayer,createMapInstance,createMapWorldLayer,createMassMarksLayer,createSelectByLayer,createVectorFaceLayer,createVectorLineLayer,disposeMap,emitter,getMapInstance,instance,resetActiveMarker,resetActiveVector,resetMap,resetZoomAndCenter,updateMarksLayersByStatus});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { Map } from 'ol';
|
|
1
|
+
import { Map, Feature } from 'ol';
|
|
2
2
|
import { Layer, Tile } from 'ol/layer';
|
|
3
|
-
import { Source, XYZ } from 'ol/source';
|
|
3
|
+
import { Source, XYZ, WMTS } from 'ol/source';
|
|
4
4
|
import { Emitter, EventType } from 'mitt';
|
|
5
|
-
import
|
|
5
|
+
import * as ol_geom from 'ol/geom';
|
|
6
|
+
import { Point } from 'ol/geom';
|
|
7
|
+
import { Select } from 'ol/interaction';
|
|
8
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
9
|
+
import { StyleLike } from 'ol/style/Style';
|
|
10
|
+
import VectorSource from 'ol/source/Vector';
|
|
6
11
|
|
|
7
12
|
interface CustomMap extends Map {
|
|
8
13
|
activeBaseLayer?: string;
|
|
@@ -11,6 +16,8 @@ interface CustomMap extends Map {
|
|
|
11
16
|
getLayerByName?: (name: string) => Layer<Source> | undefined;
|
|
12
17
|
changeLayersByNames?: (activeNames: Array<string>, allLayerNames: Array<string>) => void;
|
|
13
18
|
}
|
|
19
|
+
type GetImgUrl = (name: string, ext?: string) => string;
|
|
20
|
+
type GetImgUrlFn = (baseUrl: string) => GetImgUrl;
|
|
14
21
|
type LayerConfig = {
|
|
15
22
|
zIndex?: number;
|
|
16
23
|
visible?: boolean;
|
|
@@ -18,33 +25,124 @@ type LayerConfig = {
|
|
|
18
25
|
maxZoom?: number;
|
|
19
26
|
layerName: string;
|
|
20
27
|
};
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
type VectorConfig = {
|
|
29
|
+
key: string;
|
|
30
|
+
zIndex?: number;
|
|
31
|
+
isRaw?: boolean;
|
|
32
|
+
isLine: boolean;
|
|
33
|
+
layerName?: string;
|
|
34
|
+
openClick?: boolean;
|
|
35
|
+
fillColor?: string;
|
|
36
|
+
fillOpacity?: number;
|
|
37
|
+
strokeColor?: string;
|
|
38
|
+
strokeStyle?: string;
|
|
39
|
+
strokeWeight?: number;
|
|
40
|
+
};
|
|
41
|
+
type LineConfig = {
|
|
42
|
+
key: string;
|
|
43
|
+
width?: number;
|
|
44
|
+
isRaw?: boolean;
|
|
45
|
+
openClick?: boolean;
|
|
46
|
+
strokeColor?: string;
|
|
47
|
+
strokeStyle?: string;
|
|
48
|
+
};
|
|
49
|
+
type MassData = {
|
|
50
|
+
style: number;
|
|
51
|
+
_uuid?: string;
|
|
52
|
+
status?: number | string | undefined;
|
|
53
|
+
_status?: number | string | undefined;
|
|
54
|
+
lnglat: [string, string] | [number, number];
|
|
34
55
|
};
|
|
35
|
-
type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
56
|
+
type IconConfig = {
|
|
57
|
+
baseUrl: string;
|
|
58
|
+
hasLine?: boolean;
|
|
59
|
+
hasFace?: boolean;
|
|
60
|
+
statusNum: number;
|
|
61
|
+
isDynamic?: boolean;
|
|
62
|
+
markerIcon: string;
|
|
63
|
+
activeScale?: number;
|
|
64
|
+
markerSize: [number, number];
|
|
65
|
+
};
|
|
66
|
+
type MassMarkersStyleOptions = {
|
|
67
|
+
url: string;
|
|
68
|
+
zIndex?: number;
|
|
69
|
+
rotation: number;
|
|
70
|
+
size: [number, number];
|
|
71
|
+
anchor?: [number, number];
|
|
39
72
|
};
|
|
40
73
|
|
|
41
74
|
declare const emitter: Emitter<Record<EventType, any>>;
|
|
42
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 创建杭州规资地图
|
|
78
|
+
* @param isDark
|
|
79
|
+
*/
|
|
43
80
|
declare const createBaseLayer: (isDark?: boolean) => Tile<XYZ>;
|
|
81
|
+
/**
|
|
82
|
+
* 创建天地图
|
|
83
|
+
* @param layerName - 图层名称
|
|
84
|
+
* @param className - className
|
|
85
|
+
* @param tk - 天地图TK
|
|
86
|
+
*/
|
|
87
|
+
declare const createMapWorldLayer: (layerName: string, className: string, tk?: string) => Tile<WMTS>;
|
|
44
88
|
|
|
45
|
-
declare
|
|
89
|
+
declare let instance: CustomMap;
|
|
90
|
+
declare const createMapInstance: (config?: {}) => CustomMap;
|
|
91
|
+
declare const resetZoomAndCenter: () => void;
|
|
46
92
|
declare const getMapInstance: () => void;
|
|
47
93
|
declare const resetMap: () => void;
|
|
48
94
|
declare const disposeMap: () => void;
|
|
49
95
|
|
|
50
|
-
|
|
96
|
+
/**
|
|
97
|
+
* 重置激活的矢量数据
|
|
98
|
+
*/
|
|
99
|
+
declare const resetActiveVector: () => void;
|
|
100
|
+
declare const createGeoJsonLayer: (dataList: any, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
101
|
+
/**
|
|
102
|
+
* 创建面状数据
|
|
103
|
+
* @param dataList
|
|
104
|
+
* @param config
|
|
105
|
+
*/
|
|
106
|
+
declare const createVectorFaceLayer: (dataList: never[] | undefined, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
107
|
+
/**
|
|
108
|
+
* 创建矢量线图层
|
|
109
|
+
* @param dataList
|
|
110
|
+
* @param config
|
|
111
|
+
*/
|
|
112
|
+
declare const createVectorLineLayer: (dataList: any[] | undefined, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
113
|
+
/**
|
|
114
|
+
* 重置激活Marker
|
|
115
|
+
*/
|
|
116
|
+
declare const resetActiveMarker: () => void;
|
|
117
|
+
/**
|
|
118
|
+
* 激活标注点
|
|
119
|
+
* @param getAnimationUrl
|
|
120
|
+
*/
|
|
121
|
+
declare const activeMarkerByUid: (getAnimationUrl: GetImgUrl) => (uid: string, setFitView?: boolean) => void;
|
|
122
|
+
/**
|
|
123
|
+
* 构建MassMarks样式数组
|
|
124
|
+
*/
|
|
125
|
+
declare const buildMassMarksStyles: (getImgUrlFn: GetImgUrlFn) => (iconConfig: IconConfig) => any[];
|
|
126
|
+
/**
|
|
127
|
+
* 创建点击交互
|
|
128
|
+
* @param vectorLayer
|
|
129
|
+
*/
|
|
130
|
+
declare const createSelectByLayer: (vectorLayer: VectorLayer) => Select;
|
|
131
|
+
/**
|
|
132
|
+
* 创建massMarksLayer
|
|
133
|
+
* @param dataList
|
|
134
|
+
* @param styleList
|
|
135
|
+
*/
|
|
136
|
+
declare const createMassMarksLayer: (dataList: MassData[], styleList?: StyleLike[]) => VectorLayer<VectorSource<Feature<Point>>, Feature<Point>>;
|
|
137
|
+
/**
|
|
138
|
+
* 添加massMarksLayer
|
|
139
|
+
* @param getImgUrlFn
|
|
140
|
+
*/
|
|
141
|
+
declare const addMassMarksLayer: (getImgUrlFn: GetImgUrlFn) => (dataList: never[] | undefined, iconConfig: IconConfig, openClick?: boolean) => VectorLayer<VectorSource<Feature<Point>>, Feature<Point>>;
|
|
142
|
+
/**
|
|
143
|
+
* 更新图层根据选中状态列表
|
|
144
|
+
* @param checkedStatusList
|
|
145
|
+
*/
|
|
146
|
+
declare const updateMarksLayersByStatus: (checkedStatusList?: any[]) => void;
|
|
147
|
+
|
|
148
|
+
export { type CustomMap, type GetImgUrl, type GetImgUrlFn, type IconConfig, type LayerConfig, type LineConfig, type MassData, type MassMarkersStyleOptions, type VectorConfig, activeMarkerByUid, addMassMarksLayer, buildMassMarksStyles, createBaseLayer, createGeoJsonLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, disposeMap, emitter, getMapInstance, instance, resetActiveMarker, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,62 +1,148 @@
|
|
|
1
|
-
import {Map} from 'ol';
|
|
2
|
-
import {Layer, Tile} from 'ol/layer';
|
|
3
|
-
import {Source, XYZ} from 'ol/source';
|
|
4
|
-
import {Emitter, EventType} from 'mitt';
|
|
5
|
-
import
|
|
1
|
+
import { Map, Feature } from 'ol';
|
|
2
|
+
import { Layer, Tile } from 'ol/layer';
|
|
3
|
+
import { Source, XYZ, WMTS } from 'ol/source';
|
|
4
|
+
import { Emitter, EventType } from 'mitt';
|
|
5
|
+
import * as ol_geom from 'ol/geom';
|
|
6
|
+
import { Point } from 'ol/geom';
|
|
7
|
+
import { Select } from 'ol/interaction';
|
|
8
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
9
|
+
import { StyleLike } from 'ol/style/Style';
|
|
10
|
+
import VectorSource from 'ol/source/Vector';
|
|
6
11
|
|
|
7
12
|
interface CustomMap extends Map {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
activeBaseLayer?: string;
|
|
14
|
+
changeBaseLayer?: () => void;
|
|
15
|
+
removeLayerByName?: (name: string) => void;
|
|
16
|
+
getLayerByName?: (name: string) => Layer<Source> | undefined;
|
|
17
|
+
changeLayersByNames?: (activeNames: Array<string>, allLayerNames: Array<string>) => void;
|
|
13
18
|
}
|
|
14
|
-
|
|
19
|
+
type GetImgUrl = (name: string, ext?: string) => string;
|
|
20
|
+
type GetImgUrlFn = (baseUrl: string) => GetImgUrl;
|
|
15
21
|
type LayerConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
zIndex?: number;
|
|
23
|
+
visible?: boolean;
|
|
24
|
+
minZoom?: number;
|
|
25
|
+
maxZoom?: number;
|
|
26
|
+
layerName: string;
|
|
27
|
+
};
|
|
28
|
+
type VectorConfig = {
|
|
29
|
+
key: string;
|
|
30
|
+
zIndex?: number;
|
|
31
|
+
isRaw?: boolean;
|
|
32
|
+
isLine: boolean;
|
|
33
|
+
layerName?: string;
|
|
34
|
+
openClick?: boolean;
|
|
35
|
+
fillColor?: string;
|
|
36
|
+
fillOpacity?: number;
|
|
37
|
+
strokeColor?: string;
|
|
38
|
+
strokeStyle?: string;
|
|
39
|
+
strokeWeight?: number;
|
|
40
|
+
};
|
|
41
|
+
type LineConfig = {
|
|
42
|
+
key: string;
|
|
43
|
+
width?: number;
|
|
44
|
+
isRaw?: boolean;
|
|
45
|
+
openClick?: boolean;
|
|
46
|
+
strokeColor?: string;
|
|
47
|
+
strokeStyle?: string;
|
|
21
48
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
offsetX?: number;
|
|
29
|
-
offsetY?: number;
|
|
30
|
-
scale?: number;
|
|
31
|
-
showText?: boolean;
|
|
32
|
-
anchor?: Array<number>;
|
|
33
|
-
rawData?: any;
|
|
34
|
-
rotation?: number;
|
|
49
|
+
type MassData = {
|
|
50
|
+
style: number;
|
|
51
|
+
_uuid?: string;
|
|
52
|
+
status?: number | string | undefined;
|
|
53
|
+
_status?: number | string | undefined;
|
|
54
|
+
lnglat: [string, string] | [number, number];
|
|
35
55
|
};
|
|
36
|
-
type
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
type IconConfig = {
|
|
57
|
+
baseUrl: string;
|
|
58
|
+
hasLine?: boolean;
|
|
59
|
+
hasFace?: boolean;
|
|
60
|
+
statusNum: number;
|
|
61
|
+
isDynamic?: boolean;
|
|
62
|
+
markerIcon: string;
|
|
63
|
+
activeScale?: number;
|
|
64
|
+
markerSize: [number, number];
|
|
65
|
+
};
|
|
66
|
+
type MassMarkersStyleOptions = {
|
|
67
|
+
url: string;
|
|
68
|
+
zIndex?: number;
|
|
69
|
+
rotation: number;
|
|
70
|
+
size: [number, number];
|
|
71
|
+
anchor?: [number, number];
|
|
40
72
|
};
|
|
41
73
|
|
|
42
74
|
declare const emitter: Emitter<Record<EventType, any>>;
|
|
43
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 创建杭州规资地图
|
|
78
|
+
* @param isDark
|
|
79
|
+
*/
|
|
44
80
|
declare const createBaseLayer: (isDark?: boolean) => Tile<XYZ>;
|
|
81
|
+
/**
|
|
82
|
+
* 创建天地图
|
|
83
|
+
* @param layerName - 图层名称
|
|
84
|
+
* @param className - className
|
|
85
|
+
* @param tk - 天地图TK
|
|
86
|
+
*/
|
|
87
|
+
declare const createMapWorldLayer: (layerName: string, className: string, tk?: string) => Tile<WMTS>;
|
|
45
88
|
|
|
46
|
-
declare
|
|
89
|
+
declare let instance: CustomMap;
|
|
90
|
+
declare const createMapInstance: (config?: {}) => CustomMap;
|
|
91
|
+
declare const resetZoomAndCenter: () => void;
|
|
47
92
|
declare const getMapInstance: () => void;
|
|
48
93
|
declare const resetMap: () => void;
|
|
49
94
|
declare const disposeMap: () => void;
|
|
50
95
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
96
|
+
/**
|
|
97
|
+
* 重置激活的矢量数据
|
|
98
|
+
*/
|
|
99
|
+
declare const resetActiveVector: () => void;
|
|
100
|
+
declare const createGeoJsonLayer: (dataList: any, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
101
|
+
/**
|
|
102
|
+
* 创建面状数据
|
|
103
|
+
* @param dataList
|
|
104
|
+
* @param config
|
|
105
|
+
*/
|
|
106
|
+
declare const createVectorFaceLayer: (dataList: never[] | undefined, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
107
|
+
/**
|
|
108
|
+
* 创建矢量线图层
|
|
109
|
+
* @param dataList
|
|
110
|
+
* @param config
|
|
111
|
+
*/
|
|
112
|
+
declare const createVectorLineLayer: (dataList: any[] | undefined, config: VectorConfig) => VectorLayer<VectorSource<Feature<ol_geom.Geometry>>, Feature<ol_geom.Geometry>>;
|
|
113
|
+
/**
|
|
114
|
+
* 重置激活Marker
|
|
115
|
+
*/
|
|
116
|
+
declare const resetActiveMarker: () => void;
|
|
117
|
+
/**
|
|
118
|
+
* 激活标注点
|
|
119
|
+
* @param getAnimationUrl
|
|
120
|
+
*/
|
|
121
|
+
declare const activeMarkerByUid: (getAnimationUrl: GetImgUrl) => (uid: string, setFitView?: boolean) => void;
|
|
122
|
+
/**
|
|
123
|
+
* 构建MassMarks样式数组
|
|
124
|
+
*/
|
|
125
|
+
declare const buildMassMarksStyles: (getImgUrlFn: GetImgUrlFn) => (iconConfig: IconConfig) => any[];
|
|
126
|
+
/**
|
|
127
|
+
* 创建点击交互
|
|
128
|
+
* @param vectorLayer
|
|
129
|
+
*/
|
|
130
|
+
declare const createSelectByLayer: (vectorLayer: VectorLayer) => Select;
|
|
131
|
+
/**
|
|
132
|
+
* 创建massMarksLayer
|
|
133
|
+
* @param dataList
|
|
134
|
+
* @param styleList
|
|
135
|
+
*/
|
|
136
|
+
declare const createMassMarksLayer: (dataList: MassData[], styleList?: StyleLike[]) => VectorLayer<VectorSource<Feature<Point>>, Feature<Point>>;
|
|
137
|
+
/**
|
|
138
|
+
* 添加massMarksLayer
|
|
139
|
+
* @param getImgUrlFn
|
|
140
|
+
*/
|
|
141
|
+
declare const addMassMarksLayer: (getImgUrlFn: GetImgUrlFn) => (dataList: never[] | undefined, iconConfig: IconConfig, openClick?: boolean) => VectorLayer<VectorSource<Feature<Point>>, Feature<Point>>;
|
|
142
|
+
/**
|
|
143
|
+
* 更新图层根据选中状态列表
|
|
144
|
+
* @param checkedStatusList
|
|
145
|
+
*/
|
|
146
|
+
declare const updateMarksLayersByStatus: (checkedStatusList?: any[]) => void;
|
|
147
|
+
|
|
148
|
+
export { type CustomMap, type GetImgUrl, type GetImgUrlFn, type IconConfig, type LayerConfig, type LineConfig, type MassData, type MassMarkersStyleOptions, type VectorConfig, activeMarkerByUid, addMassMarksLayer, buildMassMarksStyles, createBaseLayer, createGeoJsonLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, disposeMap, emitter, getMapInstance, instance, resetActiveMarker, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
var N=Object.defineProperty,_=Object.defineProperties;var U=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var M=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e)=>{for(var r in e||(e={}))V.call(e,r)&&M(t,r,e[r]);if(x)for(var r of x(e))P.call(e,r)&&M(t,r,e[r]);return t},k=(t,e)=>_(t,U(e));import T from"mitt";var j=T(),v=j;import{XYZ as q}from"ol/source";import{WMTS as H}from"ol/source";import{TileGrid as K}from"ol/tilegrid";import{Tile as A}from"ol/layer";import O from"ol/Map";import Z from"ol/View";import{defaults as $}from"ol/control";var o,J=(t={})=>{let e=Object.assign({zoom:9,maxZoom:18,minZoom:9,baseLayer:"vec-layer",projection:"EPSG:4326",layers:[h()],smoothExtentConstraint:!1,tk:"c77eddc667c5bed016fded560baf93e7",center:[119.5326450625435,29.8845606679097]},t||{});return o?(o.getLayers().on("remove",a=>{let n=a.element;o.removeInteraction(n.get("_selectInteraction"))}),o):(o=new O({view:new Z(e),controls:$({attribution:!1,zoom:!1,rotate:!1}),layers:e.layers||[h()]}),o.activeBaseLayer=e.baseLayer,o.getLayerByName=w,o.removeLayerByName=z,o.changeLayersByNames=S,o.on("pointermove",a=>{o.getTargetElement().style.cursor=o.hasFeatureAtPixel(a.pixel)?"pointer":""}),o)},W=()=>{},X=()=>{},R=()=>{},Y=()=>{o.getAllLayers().forEach(e=>{o.removeLayer(e)}),o.setTarget(""),o=void 0};import Q from"ol/tilegrid/WMTS";var h=(t=!0)=>new A({zIndex:1,minZoom:8,maxZoom:21,source:new q({tileGrid:new K({tileSize:256,resolutions:[.005492298,.002746149,.0013730745,.00068653725,.000343268625,.0001716343125,8581715625e-14,42908578125e-15,214542890625e-16,1072714453125e-17,5363572265625e-18,26817861328125e-19,134089306640625e-20],origin:[118.122911693886,31.2869311022836],extent:[118.340502132662,29.2073269598186,120.724787992425,30.5617943760008]}),projection:"EPSG:4326",urls:t?["https://ywtg.citybrain.hangzhou.gov.cn:9456/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9457/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9458/hzsyvector_dark/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9459/hzsyvector_dark/{z}/{y}/{x}","https://cb.hangzhoumap.gov.cn/E36CCEA93443D1495DB9B9F2B2FFE348CB1A367D75176F815040AB19E54CDCA5DAAA25813AF965E2ABD0CC2463DD1223/PBS/rest/services/hzsyvector_dark/Mapserver/tile/{z}/{y}/{x}"]:["https://ywtg.citybrain.hangzhou.gov.cn:9456/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9457/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9458/hzsyvector/{z}/{y}/{x}","https://ywtg.citybrain.hangzhou.gov.cn:9459/hzsyvector/{z}/{y}/{x}","https://cb.hangzhoumap.gov.cn/E36CCEA93443D1495DB9B9F2B2FFE348CB1A367D75176F815040AB19E54CDCA5DAAA25813AF965E2ABD0CC2463DD1223/PBS/rest/services/hzsyvector/Mapserver/tile/{z}/{y}/{x}"]})}),ee=(t,e,r="c77eddc667c5bed016fded560baf93e7")=>{let[a,n]=t.split("_");return new A({className:e,cacheSize:20240,zIndex:-1,source:new H({crossOrigin:"anonymous",projection:"EPSG:4326",wrapX:!0,layer:a,style:"default",version:"1.0.0",format:"image/png",matrixSet:n,tileGrid:new Q({origin:[-180,90],matrixIds:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],resolutions:[.703125,.3515625,.17578125,.087890625,.0439453125,.02197265625,.010986328125,.0054931640625,.00274658203125,.001373291015625,.0006866455078125,.00034332275390625,.000171661376953125,858306884765625e-19,4291534423828125e-20,21457672119140625e-21,10728836059570312e-21,5364418029785156e-21,2682209014892578e-21]}),url:`https://t{0-7}.tianditu.gov.cn/${t}/wmts?tk=${r}`})})},w=t=>o.getAllLayers().find(e=>e.getClassName()===t),z=t=>{let e=o.getAllLayers().find(r=>r.getClassName()===t);e&&o.removeLayer(e)},S=(t,e)=>{o.getAllLayers().filter(a=>e.includes(a.getClassName())).forEach(a=>{a.setVisible(t==null?void 0:t.includes(a.getClassName()))})};import{Feature as te}from"ol";import{Point as re}from"ol/geom";import{Select as oe}from"ol/interaction";import B from"ol/layer/Vector";import I from"ol/source/Vector";import{Fill as ae,Icon as C,Stroke as b,Style as d}from"ol/style";import{GeoJSON as se}from"ol/format";var ne=()=>{o.getLayers().forEach(e=>{let r=e.get("_selectInteraction");r&&r.getFeatures().clear()})},ce=(t,e)=>{let{key:r,isLine:a}=e,n=[];return t.forEach(s=>{try{let c=Array.isArray(s[r])?s[r]:JSON.parse(s[r]||"[]");c.length&&n.push({type:"Feature",properties:L({},s),geometry:{coordinates:c,type:a?"Polyline":"Polygon"}})}catch(c){console.error(c),console.error(`\u521B\u5EFA\u7EBF\u72B6\u6570\u636E\u5931\u8D25\uFF1A${s.toString()}`)}}),{type:"FeatureCollection",features:n}},p=(t,e)=>{let{isLine:r,layerName:a}=e||{},n=ce(t,e),s=new B({className:a||"ol-layer",source:new I({features:new se().readFeatures(n)}),style:r?new d({stroke:new b({color:"red",lineDash:[10],width:3})}):new d({stroke:new b({color:"red",lineDash:[10],width:3}),fill:new ae({color:"rgba(0, 0, 255, 0.1)"})})});return s.set("_layerName",a),s},ie=(t=[],e)=>p(t,Object.assign(e,{isLine:!1})),ye=(t=[],e)=>p(t,Object.assign(e,{isLine:!0}));var le=()=>{},me=t=>(e,r=!0)=>{console.log("activeMarkerByUid",e,r,t)},F=t=>e=>{let{baseUrl:r,markerIcon:a,markerSize:n=[32,32],statusNum:s=5,activeScale:c=1.3}=e,g=t(r),[u,f]=n,m=new Array(s*2);for(let i=0;i<s;i++){let y=g(`${a}-${i}`,".webp");m[i]=new d({zIndex:88+i,image:new C({src:y,anchor:[u/2,f]})});let l=g(`${a}-${i}-active`,".webp");m[i+s]=new d({zIndex:102,image:new C({src:l||y,anchor:[u/2*c,f*c],size:n.map(G=>G*c)})})}return m},D=t=>{let e=new oe({style:null,layers:[t]});return e.on("select",r=>{let{selected:a,deselected:n}=r;if(a.length){let s=a[0],c=s.getProperties();s.setStyle(c.activeStyle),v.emit("marker-click",c)}if(n.length){let s=n[0],c=s.getProperties();s.setStyle(c.unActiveStyle)}}),o.addInteraction(e),t.set("_selectInteraction",e),e},E=(t,e=[])=>{let r=t.map(n=>{let s=new te({geometry:new re([+n.lnglat[0],+n.lnglat[1]])});return s.setProperties(k(L({},n),{unActiveStyle:e[n.style],activeStyle:e[n.style+e.length/2]})),s.setStyle(e[n.style]),s}),a=new B({source:new I({features:r})});return a.setProperties({_isCustom:!0,_dataList:t,_isMassMarksLayer:!0,_statusNum:e.length/2}),a},pe=t=>(e=[],r,a=!0)=>{let{baseUrl:n,hasLine:s,hasFace:c,isDynamic:g,statusNum:u,markerIcon:f,markerSize:m}=r,i=F(t)({baseUrl:n,markerIcon:f,markerSize:m,activeScale:1.3,statusNum:u||5}),y=E(e,i);if(a&&D(y),s){let l=p(e,{key:"line",isLine:!0,strokeColor:"rgba(29, 235, 255, 0.8)"});o.addLayer(l)}if(c){let l=p(e,{isLine:!1,key:"faceList",fillOpacity:.1,fillColor:"#4247DF",strokeWeight:1,strokeStyle:"dashed",strokeColor:"#4247DF"});o.addLayer(l)}return y.setProperties({_hasLine:s,_hasFace:c,_isDynamic:g}),y.setMap(o),y},ge=(t=[])=>{console.log(t)};export{me as activeMarkerByUid,pe as addMassMarksLayer,F as buildMassMarksStyles,h as createBaseLayer,p as createGeoJsonLayer,J as createMapInstance,ee as createMapWorldLayer,E as createMassMarksLayer,D as createSelectByLayer,ie as createVectorFaceLayer,ye as createVectorLineLayer,Y as disposeMap,v as emitter,X as getMapInstance,o as instance,le as resetActiveMarker,ne as resetActiveVector,R as resetMap,W as resetZoomAndCenter,ge as updateMarksLayersByStatus};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "map-ol-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Openlayers utils library",
|
|
6
6
|
"files": [
|
|
@@ -26,12 +26,9 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"ol": "^10.5.0",
|
|
29
|
-
"mitt": "^3.0.1"
|
|
30
|
-
"proj4": "^2.15.0"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@types/proj4": "^2.5.6"
|
|
29
|
+
"mitt": "^3.0.1"
|
|
34
30
|
},
|
|
31
|
+
"devDependencies": {},
|
|
35
32
|
"peerDependencies": {
|
|
36
33
|
"ol": ">=10.5.0"
|
|
37
34
|
},
|