map-ol-utils 0.0.2 → 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 CHANGED
@@ -1 +1 @@
1
- "use strict";var A=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var F=(e,r)=>{for(var o in r)i(e,o,{get:r[o],enumerable:!0})},y=(e,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of D(r))!S.call(e,n)&&n!==o&&i(e,n,{get:()=>r[n],enumerable:!(a=E(r,n))||a.enumerable});return e};var s=(e,r,o)=>(o=e!=null?A(N(e)):{},y(r||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),M=e=>y(i({},"__esModule",{value:!0}),e);var I={};F(I,{createBaseLayer:()=>c,createMapInstance:()=>u,disposeMap:()=>d,emitter:()=>p,getMapInstance:()=>f,resetMap:()=>z});module.exports=M(I);var m=s(require("mitt"),1),G=(0,m.default)(),p=G;var w=require("ol/source"),B=require("ol/layer"),k=require("ol/source");var g=s(require("ol/Map"),1),l=s(require("ol/View"),1),h=require("ol/control");var t,u=(e={})=>{let r=Object.assign({zoom:9,maxZoom:18,minZoom:9,baseLayer:"vec-layer",projection:"EPSG:4326",center:[119.72,30.12],layers:[c()],tk:"c77eddc667c5bed016fded560baf93e7"},e||{});return t||(t=new g.default({layers:[c()],view:new l.default(r),controls:(0,h.defaults)({attribution:!1,zoom:!1,rotate:!1})}),t.activeBaseLayer=r.baseLayer,t.getLayerByName=x,t.removeLayerByName=v,t.changeLayersByNames=L,t.on("pointermove",o=>{t.getTargetElement().style.cursor=t.hasFeatureAtPixel(o.pixel)?"pointer":""}),t)},f=()=>{},z=()=>{},d=()=>{};var C=require("ol/tilegrid"),b=require("ol/format"),T=s(require("ol/layer/Vector"),1),P=s(require("ol/source/Vector"),1),_=s(require("ol/tilegrid/WMTS"),1),c=(e=!0)=>new B.Tile({minZoom:8,maxZoom:21,source:new w.XYZ({tileGrid:new C.TileGrid({tileSize:256,resolutions:[.005493214,.002746607,.001373303,686652e-9,343326e-9,171663e-9,85831e-9,42916e-9,21458e-9,10729e-9,5364e-9,2682e-9,1341e-9],origin:[118.122911693886,31.2869311022836],extent:[116.43263049006,28.6201742126026,123.705594256347,31.9765041681924]}),projection:"EPSG:4326",urls:e?["https://ywtg.citybrain.hangzhou.gov.cn/hzsyvector_dark/{z}/{y}/{x}","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/hzsyvector/{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}"]})});var x=e=>t.getAllLayers().find(r=>r.getClassName()===e),v=e=>{let r=t.getAllLayers().find(o=>o.getClassName()===e);r&&t.removeLayer(r)},L=(e,r)=>{t.getAllLayers().filter(a=>r.includes(a.getClassName())).forEach(a=>{a.setVisible(e==null?void 0:e.includes(a.getClassName()))})};0&&(module.exports={createBaseLayer,createMapInstance,disposeMap,emitter,getMapInstance,resetMap});
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,7 +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 * 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';
5
11
 
6
12
  interface CustomMap extends Map {
7
13
  activeBaseLayer?: string;
@@ -10,6 +16,8 @@ interface CustomMap extends Map {
10
16
  getLayerByName?: (name: string) => Layer<Source> | undefined;
11
17
  changeLayersByNames?: (activeNames: Array<string>, allLayerNames: Array<string>) => void;
12
18
  }
19
+ type GetImgUrl = (name: string, ext?: string) => string;
20
+ type GetImgUrlFn = (baseUrl: string) => GetImgUrl;
13
21
  type LayerConfig = {
14
22
  zIndex?: number;
15
23
  visible?: boolean;
@@ -17,33 +25,124 @@ type LayerConfig = {
17
25
  maxZoom?: number;
18
26
  layerName: string;
19
27
  };
20
- type DataItemConfig = {
21
- lng: string | number;
22
- lat: string | number;
23
- img: string | undefined;
24
- activeImg?: string | undefined;
25
- text?: string;
26
- offsetX?: number;
27
- offsetY?: number;
28
- scale?: number;
29
- showText?: boolean;
30
- anchor?: Array<number>;
31
- rawData?: any;
32
- rotation?: number;
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];
33
55
  };
34
- type GeoData = {
35
- id: string;
36
- geom: string;
37
- props: string;
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];
38
72
  };
39
73
 
40
74
  declare const emitter: Emitter<Record<EventType, any>>;
41
75
 
76
+ /**
77
+ * 创建杭州规资地图
78
+ * @param isDark
79
+ */
42
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>;
43
88
 
89
+ declare let instance: CustomMap;
44
90
  declare const createMapInstance: (config?: {}) => CustomMap;
91
+ declare const resetZoomAndCenter: () => void;
45
92
  declare const getMapInstance: () => void;
46
93
  declare const resetMap: () => void;
47
94
  declare const disposeMap: () => void;
48
95
 
49
- export { type CustomMap, type DataItemConfig, type GeoData, type LayerConfig, createBaseLayer, createMapInstance, disposeMap, emitter, getMapInstance, resetMap };
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,7 +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 * 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';
5
11
 
6
12
  interface CustomMap extends Map {
7
13
  activeBaseLayer?: string;
@@ -10,6 +16,8 @@ interface CustomMap extends Map {
10
16
  getLayerByName?: (name: string) => Layer<Source> | undefined;
11
17
  changeLayersByNames?: (activeNames: Array<string>, allLayerNames: Array<string>) => void;
12
18
  }
19
+ type GetImgUrl = (name: string, ext?: string) => string;
20
+ type GetImgUrlFn = (baseUrl: string) => GetImgUrl;
13
21
  type LayerConfig = {
14
22
  zIndex?: number;
15
23
  visible?: boolean;
@@ -17,33 +25,124 @@ type LayerConfig = {
17
25
  maxZoom?: number;
18
26
  layerName: string;
19
27
  };
20
- type DataItemConfig = {
21
- lng: string | number;
22
- lat: string | number;
23
- img: string | undefined;
24
- activeImg?: string | undefined;
25
- text?: string;
26
- offsetX?: number;
27
- offsetY?: number;
28
- scale?: number;
29
- showText?: boolean;
30
- anchor?: Array<number>;
31
- rawData?: any;
32
- rotation?: number;
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];
33
55
  };
34
- type GeoData = {
35
- id: string;
36
- geom: string;
37
- props: string;
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];
38
72
  };
39
73
 
40
74
  declare const emitter: Emitter<Record<EventType, any>>;
41
75
 
76
+ /**
77
+ * 创建杭州规资地图
78
+ * @param isDark
79
+ */
42
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>;
43
88
 
89
+ declare let instance: CustomMap;
44
90
  declare const createMapInstance: (config?: {}) => CustomMap;
91
+ declare const resetZoomAndCenter: () => void;
45
92
  declare const getMapInstance: () => void;
46
93
  declare const resetMap: () => void;
47
94
  declare const disposeMap: () => void;
48
95
 
49
- export { type CustomMap, type DataItemConfig, type GeoData, type LayerConfig, createBaseLayer, createMapInstance, disposeMap, emitter, getMapInstance, resetMap };
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 y from"mitt";var m=y(),p=m;import{XYZ as x}from"ol/source";import{Tile as v}from"ol/layer";import{WMTS as T}from"ol/source";import g from"ol/Map";import l from"ol/View";import{defaults as h}from"ol/control";var e,u=(r={})=>{let t=Object.assign({zoom:9,maxZoom:18,minZoom:9,baseLayer:"vec-layer",projection:"EPSG:4326",center:[119.72,30.12],layers:[s()],tk:"c77eddc667c5bed016fded560baf93e7"},r||{});return e||(e=new g({layers:[s()],view:new l(t),controls:h({attribution:!1,zoom:!1,rotate:!1})}),e.activeBaseLayer=t.baseLayer,e.getLayerByName=n,e.removeLayerByName=c,e.changeLayersByNames=i,e.on("pointermove",o=>{e.getTargetElement().style.cursor=e.hasFeatureAtPixel(o.pixel)?"pointer":""}),e)},f=()=>{},z=()=>{},d=()=>{};import{TileGrid as L}from"ol/tilegrid";import{GeoJSON as J,WKB as O}from"ol/format";import Z from"ol/layer/Vector";import V from"ol/source/Vector";import $ from"ol/tilegrid/WMTS";var s=(r=!0)=>new v({minZoom:8,maxZoom:21,source:new x({tileGrid:new L({tileSize:256,resolutions:[.005493214,.002746607,.001373303,686652e-9,343326e-9,171663e-9,85831e-9,42916e-9,21458e-9,10729e-9,5364e-9,2682e-9,1341e-9],origin:[118.122911693886,31.2869311022836],extent:[116.43263049006,28.6201742126026,123.705594256347,31.9765041681924]}),projection:"EPSG:4326",urls:r?["https://ywtg.citybrain.hangzhou.gov.cn/hzsyvector_dark/{z}/{y}/{x}","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/hzsyvector/{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}"]})});var n=r=>e.getAllLayers().find(t=>t.getClassName()===r),c=r=>{let t=e.getAllLayers().find(o=>o.getClassName()===r);t&&e.removeLayer(t)},i=(r,t)=>{e.getAllLayers().filter(a=>t.includes(a.getClassName())).forEach(a=>{a.setVisible(r==null?void 0:r.includes(a.getClassName()))})};export{s as createBaseLayer,u as createMapInstance,d as disposeMap,p as emitter,f as getMapInstance,z as resetMap};
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.2",
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
  },