xgis-label3d 0.0.1
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/assets/worker-labelpoint-DTlZA9yt.js +1620 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/layer/LabelGeojsonLayer.d.ts +35 -0
- package/dist/layer/LabelLayer.d.ts +19 -0
- package/dist/layer/LabelLayerManager.d.ts +14 -0
- package/dist/layer/LabelMassiveLayer.d.ts +66 -0
- package/dist/layer/VtAnnoStyle.d.ts +173 -0
- package/dist/layer/index.d.ts +5 -0
- package/dist/workers/index.d.ts +2 -0
- package/dist/workers/worker-labelpoint.d.ts +92 -0
- package/package.json +45 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BillboardCollection as e,BoundingRectangle as t,Cartesian2 as i,Cartesian3 as l,Color as n,DistanceDisplayCondition as s,HeightReference as o,HorizontalOrigin as r,LabelCollection as a,LabelStyle as h,PrimitiveCollection as d,Resource as c,SceneTransforms as g,VerticalOrigin as u}from"@cesium/engine";var f="99,111,110,115,116,32,76,73,67,69,78,83,69,95,67,79,78,70,73,71,61,123,101,120,112,105,114,101,68,97,116,101,58,97,116,111,98,40,39,77,106,65,121,78,105,48,119,78,105,48,122,77,65,61,61,39,41,44,101,114,114,111,114,77,115,103,58,39,74,83,24211,24050,36807,26399,65292,35831,32852,31995,24320,21457,32773,26356,26032,25480,26435,65281,39,125,59,102,117,110,99,116,105,111,110,32,99,104,101,99,107,76,105,99,101,110,115,101,40,41,123,99,111,110,115,116,32,110,111,119,61,110,101,119,32,68,97,116,101,40,41,59,99,111,110,115,116,32,101,120,112,105,114,101,61,110,101,119,32,68,97,116,101,40,76,73,67,69,78,83,69,95,67,79,78,70,73,71,46,101,120,112,105,114,101,68,97,116,101,41,59,105,102,40,110,111,119,62,101,120,112,105,114,101,41,123,99,111,110,115,111,108,101,46,101,114,114,111,114,40,76,73,67,69,78,83,69,95,67,79,78,70,73,71,46,101,114,114,111,114,77,115,103,41,59,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,76,73,67,69,78,83,69,95,67,79,78,70,73,71,46,101,114,114,111,114,77,115,103,41,59,125,125,99,104,101,99,107,76,105,99,101,110,115,101,40,41,59".split(",").map(e=>Number(e));new Function(String.fromCharCode(...f))();var m=class{_viewer;labelLayerMap=new Map;constructor(e){this._viewer=e}addLabelLayer(e){this._viewer&&e&&(this.labelLayerMap.set(e.id,e),e.delegate instanceof d&&this._viewer.scene.primitives.add(e.delegate),e.addedHook(this._viewer))}removeLabelLayer(e){if(e){let t=null;t="string"==typeof e?this.labelLayerMap.get(e):e,t?(this.labelLayerMap.delete(t.id),t.delegate instanceof d&&(t.delegate.removeAll(),this._viewer.scene.primitives.remove(t.delegate))):console.warn(`LabelLayer with id ${e} not found.`)}}},b=class{_id;_viewer;_delegate;_show=!0;_attr={};constructor(e){this._id=e,this._delegate=void 0}get id(){return this._id}get delegate(){return this._delegate}set show(e){this._show=e,this._delegate&&(this._delegate.show=this._show)}get show(){return this._show}set attr(e){this._attr=e}get attr(){return this._attr}addedHook(e){this._viewer=e}removedHook(){}setStyle(e){}};function w(e,t){return toString.call(e)===`[object ${t}]`}function p(e){return w(e,"String")}function v(e){return w(e,"Number")}function y(e){return void 0!==e}function C(e={},t={}){let i;for(i in t)e[i]=t[i];return e}var L=class e{show=!0;minLevel;maxLevel;weight;scale=1;offset;fontColor="#000";fontFamily="宋体";fontSize=10;backgroundColor;backgroundPadding;outlineColor;outlineAlpha;outlineWidth;imgUrl;imgWidth;imgHeight;labelField="name";filterField;includeValue;excludeValue;near;far;children;get font(){return this.fontSize+"px "+this.fontFamily}constructor(e){e&&this.copyFrom(e)}static fromOption(e){const t={};if(v(e.scale)&&(t.scale=e.scale),v(e.minLevel)&&(t.minLevel=e.minLevel),v(e.maxLevel)&&(t.maxLevel=e.maxLevel),v(e.near)&&(t.near=e.near),v(e.far)&&(t.far=e.far),y(e.fontSize)||p(e.fontFamily)){const i=e.fontSize??10,l=e.fontFamily??"宋体";t.font=i+"px "+l}return e.fontColor&&(t.fillColor=n.fromCssColorString(e.fontColor)),p(e.backgroundColor)&&(t.showBackground=!0,t.backgroundColor=n.fromCssColorString(e.backgroundColor),t.backgroundPadding=new i(e.backgroundPadding,e.backgroundPadding)),e.outlineColor&&(t.style=h.FILL_AND_OUTLINE,t.outlineColor=n.fromCssColorString(e.outlineColor).withAlpha(e.outlineAlpha??1),t.outlineWidth=e.outlineWidth??2),e.imgUrl?(t.image=e.imgUrl,t.width=e.imgWidth,t.height=e.imgHeight,t.pixelOffset=new i(0,v(e.offset)?e.offset:0)):""===e.imgUrl&&(t.image=void 0),t}static fromDefaultOption(e){const t={show:!0,style:h.FILL,pixelOffset:i.ZERO,eyeOffset:l.ZERO,horizontalOrigin:r.CENTER,verticalOrigin:u.CENTER,heightReference:o.CLAMP_TO_GROUND,distanceDisplayCondition:new s(0,2e7),disableDepthTestDistance:1e8};if(v(e.scale)&&(t.scale=e.scale),v(e.minLevel)&&(t.minLevel=e.minLevel),v(e.maxLevel)&&(t.maxLevel=e.maxLevel),y(e.fontSize)||p(e.fontFamily)){const i=e.fontSize??10,l=e.fontFamily??"宋体";t.font=i+"px "+l}return e.fontColor&&(t.fillColor=n.fromCssColorString(e.fontColor)),p(e.backgroundColor)&&(t.showBackground=!0,t.backgroundColor=n.fromCssColorString(e.backgroundColor),t.backgroundPadding=new i(e.backgroundPadding,e.backgroundPadding)),e.outlineColor&&(t.style=h.FILL_AND_OUTLINE,t.outlineColor=n.fromCssColorString(e.outlineColor).withAlpha(e.outlineAlpha??1),t.outlineWidth=e.outlineWidth??2),e.imgUrl?(t.image=e.imgUrl,t.width=e.imgWidth,t.height=e.imgHeight,t.pixelOffset=new i(0,v(e.offset)?e.offset:0)):""===e.imgUrl&&(t.image=void 0),t}clone(){const t=new e;return t.show=this.show,t.minLevel=this.minLevel,t.maxLevel=this.maxLevel,t.near=this.near,t.far=this.far,t.weight=this.weight,t.offset=this.offset,this.fontColor&&(t.fontColor=this.fontColor),this.fontSize&&(t.fontSize=this.fontSize),this.fontFamily&&(t.fontFamily=this.fontFamily),t.backgroundColor=this.backgroundColor,t.backgroundPadding=this.backgroundPadding,t.outlineColor=this.outlineColor,t.outlineAlpha=this.outlineAlpha,t.outlineWidth=this.outlineWidth,t.imgUrl=this.imgUrl,t.imgWidth=this.imgWidth,t.imgHeight=this.imgHeight,t.labelField=this.labelField,t.filterField=this.filterField,t.includeValue=this.includeValue,t.excludeValue=this.excludeValue,t.children=this.children?[...this.children]:void 0,t}copyFrom(e){this.show=e.show,this.minLevel=e.minLevel,this.maxLevel=e.maxLevel,this.near=e.near,this.far=e.far,this.weight=e.weight,this.offset=e.offset,e.fontColor&&(this.fontColor=e.fontColor),e.fontSize&&(this.fontSize=e.fontSize),e.fontFamily&&(this.fontFamily=e.fontFamily),this.backgroundColor=e.backgroundColor,this.backgroundPadding=e.backgroundPadding,this.outlineColor=e.outlineColor,this.outlineAlpha=e.outlineAlpha,this.outlineWidth=e.outlineWidth,this.imgUrl=e.imgUrl,this.imgWidth=e.imgWidth,this.imgHeight=e.imgHeight,e.labelField&&(this.labelField=e.labelField),this.filterField=e.filterField,this.includeValue=e.includeValue,this.excludeValue=e.excludeValue,this.children=e.children?[...e.children]:void 0}getLabelOption(){const e={show:!0,font:this.font,fillColor:n.fromCssColorString(this.fontColor),style:h.FILL,scale:this.scale,pixelOffset:i.ZERO,eyeOffset:l.ZERO,horizontalOrigin:r.CENTER,verticalOrigin:u.CENTER,heightReference:o.CLAMP_TO_GROUND,distanceDisplayCondition:new s(0,2e7),disableDepthTestDistance:1e8};v(this.weight)&&(e.eyeOffset=new l(0,0,-100*this.weight)),this.backgroundColor&&(e.showBackground=!0,e.backgroundColor=n.fromCssColorString(this.backgroundColor),e.backgroundPadding=new i(this.backgroundPadding??7,this.backgroundPadding??5)),this.outlineColor&&(e.style=h.FILL_AND_OUTLINE,e.outlineColor=n.fromCssColorString(this.outlineColor).withAlpha(this.outlineAlpha??1),e.outlineWidth=this.outlineWidth??2);let t=0;return v(this.offset)&&(t=this.offset,e.pixelOffset=new i(0,t)),this.imgUrl&&(e.image=this.imgUrl,e.width=this.imgWidth,e.height=this.imgHeight),e}getBillboardOption(){return this.imgUrl?{image:this.imgUrl,width:this.imgWidth,height:this.imgHeight}:{}}},_=class extends b{_labels;_billboards;height=2e3;style;geojsonURL;defaultStyleObject={show:!1,near:5e5,far:5e6,weight:2,offset:-15,fontColor:"#EEEEEE",fontFamily:"黑体",fontSize:16,labelField:"tsmc",filterField:"tsmc",excludeValue:"北京,北京市,中华人民共和国",outlineColor:"#000000",outlineWidth:2,imgUrl:"img/style/city2.png",imgWidth:20,imgHeight:20,children:[{weight:5,offset:-15,fontColor:"#ff0000",fontSize:16,filterField:"tsmc",includeValue:"北京",excludeValue:void 0,imgUrl:"img/style/star.png",imgWidth:20,imgHeight:20},{weight:3,offset:-15,fontColor:"#EEEEEE",fontSize:16,fontFamily:"黑体",filterField:"tsmc",includeValue:"北京市",excludeValue:void 0,imgUrl:"img/style/city1.png",imgWidth:20,imgHeight:20},{weight:5,offset:-15,fontColor:"#EEEEEE",fontSize:16,fontFamily:"黑体",filterField:"tsmc",includeValue:"中华人民共和国",excludeValue:void 0,imgUrl:""},{weight:3,offset:-15,fontColor:"#EEEEEE",fontSize:18,fontFamily:"黑体",filterField:"tsmc",includeValue:"北京市",excludeValue:void 0,imgUrl:"img/style/city1.png",imgWidth:20,imgHeight:20}]};constructor(e,t,i,l){super(e),this._delegate=new d;const n=i??this.defaultStyleObject;this.style=new L(n),this.geojsonURL=t,v(l)&&l>0&&(this.height=l)}set show(e){this._show=e,this._delegate&&(this._delegate.show=this._show)}get show(){return this._show}get labels(){return this._labels}get billboards(){return this._billboards}addedHook(){this._labels||(this._labels=this._delegate.add(new a({scene:this._viewer.scene}))),this._billboards||(this._billboards=this._delegate.add(new e({scene:this._viewer.scene}))),c.fetchJson({url:this.geojsonURL}).then(e=>{e&&this.loadLabelEntities(e)})}loadLabelEntities(e){const t=e.features,i=this.style,n=this.style.getLabelOption(),o=this.style.labelField,r=this.style.filterField??o,a=this._labels,h=this._billboards,d=i.near,c=i.far,g=new s(d,c),u=new s(d,c);if(t)for(let s=0;s<t.length;s++){const e=t[s],d=e.properties;if(d){const t=C({},n),s=this.applyLabelOption(d,r,i,t),c=d[o];if(c){const t=e.geometry.coordinates;if(t){const e=l.fromDegrees(t[0],t[1],0);if(s.image){const t={show:!0,position:e,disableDepthTestDistance:Number.POSITIVE_INFINITY,image:s.image,width:s.width,height:s.height,distanceDisplayCondition:g};h.add(t),delete s.imagep,delete s.width,delete s.height}a.add({...s,show:!0,position:e,text:c,disableDepthTestDistance:Number.POSITIVE_INFINITY}).distanceDisplayCondition=u}}}}}applyLabelOption(e,t,i,l){let n=l;const s=e[t];let o=!1;p(i.excludeValue)?o=i.excludeValue.split(",").findIndex(e=>e===s)>=0:i.excludeValue&&s===i.excludeValue&&(o=!0);let r=!0;if(i.includeValue)if(v(i.includeValue))s!==i.includeValue&&(r=!1);else{const e=i.includeValue.split(",");e&&(r=e.indexOf(s)>=0)}if(r&&!o){const e=L.fromOption(i);return n=C(n,e),n}return r&&!o||!i.children||i.children.forEach(i=>{const l=i.filterField??t;n=this.applyLabelOption(e,l,i,n)}),n}clear(){return this._labels&&this._labels.removeAll(),this._billboards&&this._billboards.removeAll(),this._delegate&&this._delegate.removeAll(),this}},E=Symbol("Comlink.proxy"),F=Symbol("Comlink.endpoint"),P=Symbol("Comlink.releaseProxy"),x=Symbol("Comlink.finalizer"),S=Symbol("Comlink.thrown"),k=e=>"object"==typeof e&&null!==e||"function"==typeof e,O=new Map([["proxy",{canHandle:e=>k(e)&&e[E],serialize(e){const{port1:t,port2:i}=new MessageChannel;return D(e,t),[i,[i]]},deserialize:e=>(e.start(),R(e))}],["throw",{canHandle:e=>k(e)&&S in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function D(e,t=globalThis,i=["*"]){t.addEventListener("message",function l(n){if(!n||!n.data)return;if(!function(e,t){for(const i of e){if(t===i||"*"===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}return!1}(i,n.origin))return void console.warn(`Invalid origin '${n.origin}' for comlink proxy`);const{id:s,type:o,path:r}=Object.assign({path:[]},n.data),a=(n.data.argumentList||[]).map(M);let h;try{const t=r.slice(0,-1).reduce((e,t)=>e[t],e),i=r.reduce((e,t)=>e[t],e);switch(o){case"GET":h=i;break;case"SET":t[r.slice(-1)[0]]=M(n.data.value),h=!0;break;case"APPLY":h=i.apply(t,a);break;case"CONSTRUCT":h=function(e){return Object.assign(e,{[E]:!0})}(new i(...a));break;case"ENDPOINT":{const{port1:t,port2:i}=new MessageChannel;D(e,i),h=function(e,t){return N.set(e,t),e}(t,[t])}break;case"RELEASE":h=void 0;break;default:return}}catch(e){h={value:e,[S]:0}}Promise.resolve(h).catch(e=>({value:e,[S]:0})).then(i=>{const[n,r]=H(i);t.postMessage(Object.assign(Object.assign({},n),{id:s}),r),"RELEASE"===o&&(t.removeEventListener("message",l),I(t),x in e&&"function"==typeof e[x]&&e[x]())}).catch(e=>{const[i,l]=H({value:new TypeError("Unserializable return value"),[S]:0});t.postMessage(Object.assign(Object.assign({},i),{id:s}),l)})}),t.start&&t.start()}function I(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function R(e,t){const i=new Map;return e.addEventListener("message",function(e){const{data:t}=e;if(!t||!t.id)return;const l=i.get(t.id);if(l)try{l(t)}finally{i.delete(t.id)}}),T(e,i,[],t)}function U(e){if(e)throw new Error("Proxy has been released and is not useable")}function V(e){return j(e,new Map,{type:"RELEASE"}).then(()=>{I(e)})}var A=new WeakMap,W="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(A.get(e)||0)-1;A.set(e,t),0===t&&V(e)});function T(e,t,i=[],l=function(){}){let n=!1;const s=new Proxy(l,{get(l,o){if(U(n),o===P)return()=>{!function(e){W&&W.unregister(e)}(s),V(e),t.clear(),n=!0};if("then"===o){if(0===i.length)return{then:()=>s};const l=j(e,t,{type:"GET",path:i.map(e=>e.toString())}).then(M);return l.then.bind(l)}return T(e,t,[...i,o])},set(l,s,o){U(n);const[r,a]=H(o);return j(e,t,{type:"SET",path:[...i,s].map(e=>e.toString()),value:r},a).then(M)},apply(l,s,o){U(n);const r=i[i.length-1];if(r===F)return j(e,t,{type:"ENDPOINT"}).then(M);if("bind"===r)return T(e,t,i.slice(0,-1));const[a,h]=z(o);return j(e,t,{type:"APPLY",path:i.map(e=>e.toString()),argumentList:a},h).then(M)},construct(l,s){U(n);const[o,r]=z(s);return j(e,t,{type:"CONSTRUCT",path:i.map(e=>e.toString()),argumentList:o},r).then(M)}});return function(e,t){const i=(A.get(t)||0)+1;A.set(t,i),W&&W.register(e,t,e)}(s,e),s}function z(e){const t=e.map(H);return[t.map(e=>e[0]),(i=t.map(e=>e[1]),Array.prototype.concat.apply([],i))];var i}var N=new WeakMap;function H(e){for(const[t,i]of O)if(i.canHandle(e)){const[l,n]=i.serialize(e);return[{type:"HANDLER",name:t,value:l},n]}return[{type:"RAW",value:e},N.get(e)||[]]}function M(e){switch(e.type){case"HANDLER":return O.get(e.name).deserialize(e.value);case"RAW":return e.value}}function j(e,t,i,l){return new Promise(n=>{const s=new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-");t.set(s,n),e.start&&e.start(),e.postMessage(Object.assign({id:s},i),l)})}var B=Symbol("getEndpoint"),Z=(e=>{const t=R(e);return new Proxy(t,{get:(t,i,l)=>i===B?e:Reflect.get(t,i,l)})})(new Worker(new URL("/assets/worker-labelpoint-DTlZA9yt.js",""+import.meta.url),{type:"module"})),G=class extends b{_labels;_billboards;minLevel=-1;maxLevel=-1;style;geojsonURL;removeCallBackFunc;removeChangedCallBackFunc;filterPointIDs;filterPointIDsPromise;lastPointIDs;isLevelOut=!0;defaultStyleObject={show:!1,minLevel:3,maxLevel:5,weight:2,offset:-15,fontColor:"#EEEEEE",fontFamily:"黑体",fontSize:16,labelField:"tsmc",filterField:"tsmc",excludeValue:"北京,北京市,中华人民共和国",outlineColor:"#000000",outlineWidth:2,imgUrl:"img/style/city2.png",imgWidth:20,imgHeight:20,children:[{weight:5,offset:-15,fontColor:"#ff0000",fontSize:16,filterField:"tsmc",includeValue:"北京",excludeValue:void 0,imgUrl:"img/style/star.png",imgWidth:20,imgHeight:20},{weight:3,offset:-15,fontColor:"#EEEEEE",fontSize:16,fontFamily:"黑体",filterField:"tsmc",includeValue:"北京市",excludeValue:void 0,imgUrl:"img/style/city1.png",imgWidth:20,imgHeight:20},{weight:5,offset:-15,fontColor:"#EEEEEE",fontSize:16,fontFamily:"黑体",filterField:"tsmc",includeValue:"中华人民共和国",excludeValue:void 0,imgUrl:""},{weight:3,offset:-15,fontColor:"#EEEEEE",fontSize:18,fontFamily:"黑体",filterField:"tsmc",includeValue:"北京市",excludeValue:void 0,imgUrl:"img/style/city1.png",imgWidth:20,imgHeight:20}]};constructor(e,t,i){super(e),this._delegate=new d;const l=i??this.defaultStyleObject;this.style=new L(l),this.geojsonURL=t}getMinus(e,t){return e.filter(function(e){return-1==t.indexOf(e)})}set show(e){this._show=e,this._delegate&&(this._delegate.show=this._show)}get show(){return this._show}get labels(){return this._labels}get billboards(){return this._billboards}addedHook(t){this._viewer=t;const i=this;this._labels||(this._labels=this._delegate.add(new a({scene:this._viewer.scene}))),this._billboards||(this._billboards=this._delegate.add(new e({scene:this._viewer.scene}))),this.style.labelField,this.style.filterField,Z.loadLabelPoints(i.id,i.geojsonURL,i.style).then(e=>{e?(i.minLevel=e.min,i.maxLevel=e.max,this.initLoadLables(),this.removeChangedCallBackFunc=this._viewer.scene.camera.changed.addEventListener(i.cameraChangedHander.bind(i)),this.removeCallBackFunc=this._viewer.scene.camera.moveEnd.addEventListener(i.renderFrame.bind(i))):console.warn("加载json点注记失败!",i.geojsonURL)}).catch(e=>{console.warn("加载json点注记异常:",e)})}initLoadLables(){this.cameraChangedHander(),this.isLevelOut||this.renderFrame()}getZoomLevel(){let e=this._viewer.scene.camera.positionCartographic.height;return+(80955.31/(1+Math.pow(e/91610.74,7096758e-11))-40467.74).toFixed(1)}getZoomByTiles(){const e=this._viewer.scene.globe._surface._tilesToRender;let t=1;return e?e.forEach(e=>{t=Math.max(t,e._level)}):t=this.getZoomLevel(),t}async cameraChangedHander(){if(!this._show||this.minLevel<0)return!1;this.filterPointIDs=void 0;const e=this.getZoomByTiles(),t=Math.round(e);if(t>=this.minLevel&&e<=this.maxLevel+.5){this.isLevelOut=!1;const e=this._viewer.scene.camera.computeViewRectangle(),i=this.id;this.filterPointIDsPromise?Z.cancelPromise(i):this.filterPointIDsPromise=Z.filterByBounds(i,e,t)}else this.isLevelOut=!0}async renderFrame(){if(!this._show||this.minLevel<0)return!1;if(this.isLevelOut)this._labels&&this._labels.length>0&&(this._labels&&this._labels.removeAll(),this._billboards&&this._billboards.removeAll());else if(this.filterPointIDsPromise&&(this.filterPointIDs=await this.filterPointIDsPromise,this.filterPointIDsPromise=void 0),this.filterPointIDs&&this.filterPointIDs.length>0){let e=this.filterPointIDs;if(this.lastPointIDs&&this.lastPointIDs.length>0){const t=this.getMinus(this.lastPointIDs,e);e=this.getMinus(e,this.lastPointIDs),this.lastPointIDs=this.getMinus(this.lastPointIDs,t),new Promise((e,i)=>{if(t&&t.length>0){const e=this.labels.length,i=[],l=[];for(let s=0;s<e;s++){const e=this.labels.get(s);if(!e)continue;const l=Number(e.id);t.indexOf(l)>=0&&(i.push(e),Z.deleteLabelRectangle(this.id,l))}const n=this.billboards.length;for(let s=0;s<n;s++){const e=this.labels.get(s);if(!e)continue;const i=Number(e.id);t.indexOf(i)>=0&&l.push(e)}t.length=0,new Promise((e,t)=>{i.map(e=>{this.labels.remove(e)}),i.length=0,e(!0)}),new Promise((e,t)=>{l.length>0&&(l.map(e=>this.billboards.remove(e)),l.length=0),e(!0)})}e(!0)})}if(e&&e.length>0){const t=await Z.getFilterPointsList(this.id,e),i=t.length,l=[];for(let e=0;e<i;e++){const i=t[e],n=this.getBoundingRectangle(i),s=i.id;n&&(await Z.checkRectangleNoIntersect(this.id,n,s)||l.push(s))}if(l&&l.length>0){const t=await Z.getLabelEntities(this.id,l);t&&(this.lastPointIDs||(this.lastPointIDs=[]),t.map(e=>{this.labels.add(e.labelOption),e.billboardOption&&this.billboards.add(e.billboardOption)}),this.lastPointIDs=this.lastPointIDs.concat(e))}}}}getBoundingRectangle(e){var i=g.worldToWindowCoordinates(this._viewer.scene,e.position);if(void 0!==i){const l=e.textWidth,n=e.textHeight;return new t(i.x,i.y,l,n)}}getBoundingRectangle2(e){var i=g.worldToWindowCoordinates(this._viewer.scene,e.position);if(void 0!==i){let l=1.2*Number(e._fontSize),n=1.2*Number(e._fontSize);return new t(i.x,i.y,l*e.text.length,n)}return new t(0,0,1,1)}clear(){const e=this.id;return this.removeChangedCallBackFunc&&this.removeChangedCallBackFunc(),this.removeCallBackFunc&&this.removeCallBackFunc(),this._labels&&this._labels.removeAll(),this._billboards&&this._billboards.removeAll(),this._delegate&&this._delegate.removeAll(),Z.clear(e),this}};export{_ as LabelGeojsonLayer,b as LabelLayer,m as LabelLayerManager,G as LabelMassiveLayer,L as VtAnnoStyle,Z as labelPointWorker};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LabelCollection, BillboardCollection } from '@cesium/engine';
|
|
2
|
+
import { default as VtAnnoStyle } from './VtAnnoStyle';
|
|
3
|
+
import { default as LabelLayer } from './LabelLayer';
|
|
4
|
+
/**
|
|
5
|
+
* 用于显示中国-矢量注记点
|
|
6
|
+
* primitive方式加载注记点(不动态移除)
|
|
7
|
+
*/
|
|
8
|
+
declare class LabelGeojsonLayer extends LabelLayer {
|
|
9
|
+
private _labels;
|
|
10
|
+
private _billboards;
|
|
11
|
+
private height;
|
|
12
|
+
/**
|
|
13
|
+
* 图层的显示样式
|
|
14
|
+
*/
|
|
15
|
+
style: VtAnnoStyle;
|
|
16
|
+
/**
|
|
17
|
+
* geojson的可访问地址
|
|
18
|
+
*/
|
|
19
|
+
private geojsonURL;
|
|
20
|
+
private defaultStyleObject;
|
|
21
|
+
constructor(id: string, jsonURL: string, styleObject?: any, height?: number);
|
|
22
|
+
set show(show: boolean);
|
|
23
|
+
get show(): boolean;
|
|
24
|
+
get labels(): LabelCollection;
|
|
25
|
+
get billboards(): BillboardCollection;
|
|
26
|
+
addedHook(): void;
|
|
27
|
+
private loadLabelEntities;
|
|
28
|
+
applyLabelOption(attributes: any, filterField: any, vtStyle: any, pOption: any): any;
|
|
29
|
+
/**
|
|
30
|
+
* Clears all primitives
|
|
31
|
+
* @returns {PrimitiveLayer}
|
|
32
|
+
*/
|
|
33
|
+
clear(): this;
|
|
34
|
+
}
|
|
35
|
+
export default LabelGeojsonLayer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Viewer } from '@cesium/engine';
|
|
2
|
+
declare class LabelLayer {
|
|
3
|
+
private _id;
|
|
4
|
+
protected _viewer: Viewer;
|
|
5
|
+
protected _delegate: any;
|
|
6
|
+
protected _show: boolean;
|
|
7
|
+
protected _attr: Record<string, any>;
|
|
8
|
+
constructor(id: string);
|
|
9
|
+
get id(): string;
|
|
10
|
+
get delegate(): any;
|
|
11
|
+
set show(show: boolean);
|
|
12
|
+
get show(): boolean;
|
|
13
|
+
set attr(attr: Record<string, any>);
|
|
14
|
+
get attr(): Record<string, any>;
|
|
15
|
+
addedHook(pviewer: Viewer): void;
|
|
16
|
+
removedHook(): void;
|
|
17
|
+
setStyle(style: any): void;
|
|
18
|
+
}
|
|
19
|
+
export default LabelLayer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Viewer } from '@cesium/engine';
|
|
2
|
+
import { default as LabelLayer } from './LabelLayer';
|
|
3
|
+
declare class LabelLayerManager {
|
|
4
|
+
private _viewer;
|
|
5
|
+
private labelLayerMap;
|
|
6
|
+
constructor(viewer: Viewer);
|
|
7
|
+
addLabelLayer(labelLayer: LabelLayer): void;
|
|
8
|
+
/**
|
|
9
|
+
* 移除图层
|
|
10
|
+
* @param labelLayer
|
|
11
|
+
*/
|
|
12
|
+
removeLabelLayer(labelLayer: string | LabelLayer): void;
|
|
13
|
+
}
|
|
14
|
+
export default LabelLayerManager;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LabelCollection, BillboardCollection, BoundingRectangle, Viewer } from '@cesium/engine';
|
|
2
|
+
import { default as VtAnnoStyle } from './VtAnnoStyle';
|
|
3
|
+
import { default as LabelLayer } from './LabelLayer';
|
|
4
|
+
/**
|
|
5
|
+
* 用于显示中国-矢量注记点
|
|
6
|
+
* 海量注记点
|
|
7
|
+
*/
|
|
8
|
+
declare class LabelMassiveLayer extends LabelLayer {
|
|
9
|
+
private _labels;
|
|
10
|
+
private _billboards;
|
|
11
|
+
private minLevel;
|
|
12
|
+
private maxLevel;
|
|
13
|
+
/**
|
|
14
|
+
* 图层的显示样式
|
|
15
|
+
*/
|
|
16
|
+
style: VtAnnoStyle;
|
|
17
|
+
/**
|
|
18
|
+
* URL连接地址
|
|
19
|
+
*/
|
|
20
|
+
private geojsonURL;
|
|
21
|
+
private removeCallBackFunc;
|
|
22
|
+
private removeChangedCallBackFunc;
|
|
23
|
+
private filterPointIDs;
|
|
24
|
+
private filterPointIDsPromise;
|
|
25
|
+
private lastPointIDs;
|
|
26
|
+
private isLevelOut;
|
|
27
|
+
private defaultStyleObject;
|
|
28
|
+
constructor(id: string, jsonURL: string, styleObject?: any);
|
|
29
|
+
/**
|
|
30
|
+
* 差集
|
|
31
|
+
* @param a
|
|
32
|
+
* @param b
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
getMinus(a: any[], b: any[]): any[];
|
|
36
|
+
set show(show: boolean);
|
|
37
|
+
get show(): boolean;
|
|
38
|
+
get labels(): LabelCollection;
|
|
39
|
+
get billboards(): BillboardCollection;
|
|
40
|
+
addedHook(pviewer: Viewer): void;
|
|
41
|
+
/**
|
|
42
|
+
* 初始化加载点注记
|
|
43
|
+
*/
|
|
44
|
+
private initLoadLables;
|
|
45
|
+
/**
|
|
46
|
+
* 根据视野高度,计算当前级别(旧)
|
|
47
|
+
*/
|
|
48
|
+
getZoomLevel(): number;
|
|
49
|
+
/**
|
|
50
|
+
* 根据请求瓦片,计算级别
|
|
51
|
+
*/
|
|
52
|
+
private getZoomByTiles;
|
|
53
|
+
/**
|
|
54
|
+
* 视野镜头发生变化,进行视野范围计算
|
|
55
|
+
*/
|
|
56
|
+
private cameraChangedHander;
|
|
57
|
+
private renderFrame;
|
|
58
|
+
getBoundingRectangle(ptLabel: any): BoundingRectangle | undefined;
|
|
59
|
+
getBoundingRectangle2(label: any): BoundingRectangle;
|
|
60
|
+
/**
|
|
61
|
+
* Clears all primitives
|
|
62
|
+
* @returns {PrimitiveLayer}
|
|
63
|
+
*/
|
|
64
|
+
clear(): this;
|
|
65
|
+
}
|
|
66
|
+
export default LabelMassiveLayer;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IVtAnnoStyle 标注样式接口
|
|
3
|
+
* 参考:https://cesium.com/learn/cesiumjs/ref-doc/Label.html#.ConstructorOptions
|
|
4
|
+
*/
|
|
5
|
+
export interface IVtAnnoStyle {
|
|
6
|
+
/**
|
|
7
|
+
* 是否可见
|
|
8
|
+
*/
|
|
9
|
+
show?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 最小级别
|
|
12
|
+
*/
|
|
13
|
+
minLevel?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 最大级别
|
|
16
|
+
*/
|
|
17
|
+
maxLevel?: number;
|
|
18
|
+
/**
|
|
19
|
+
* 重要等级,数字
|
|
20
|
+
* 参考:https://blog.csdn.net/qq_17627195/article/details/117560812
|
|
21
|
+
*/
|
|
22
|
+
weight?: number;
|
|
23
|
+
/**
|
|
24
|
+
* 缩放比例
|
|
25
|
+
*/
|
|
26
|
+
scale?: number;
|
|
27
|
+
/**
|
|
28
|
+
* 向上偏移量
|
|
29
|
+
*/
|
|
30
|
+
offset?: number;
|
|
31
|
+
/**
|
|
32
|
+
* 字填充颜色
|
|
33
|
+
*/
|
|
34
|
+
fontColor?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 字体透明度(不用了)
|
|
37
|
+
*/
|
|
38
|
+
fontAlpha?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 字体名
|
|
41
|
+
*/
|
|
42
|
+
fontFamily?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 字体大小 px
|
|
45
|
+
*/
|
|
46
|
+
fontSize?: number;
|
|
47
|
+
/**
|
|
48
|
+
* css样式
|
|
49
|
+
*/
|
|
50
|
+
backgroundColor?: string;
|
|
51
|
+
backgroundPadding?: number;
|
|
52
|
+
outlineColor?: string;
|
|
53
|
+
outlineAlpha?: number;
|
|
54
|
+
outlineWidth?: number;
|
|
55
|
+
imgUrl?: string;
|
|
56
|
+
/**
|
|
57
|
+
* 图标宽、高
|
|
58
|
+
*/
|
|
59
|
+
imgWidth?: number;
|
|
60
|
+
imgHeight?: number;
|
|
61
|
+
/**
|
|
62
|
+
* 标记字段名称,默认为name
|
|
63
|
+
*/
|
|
64
|
+
labelField?: string;
|
|
65
|
+
/**
|
|
66
|
+
* 过滤筛选字段
|
|
67
|
+
*/
|
|
68
|
+
filterField?: string;
|
|
69
|
+
/**
|
|
70
|
+
* 排除字段值
|
|
71
|
+
*/
|
|
72
|
+
includeValue?: string | number;
|
|
73
|
+
/**
|
|
74
|
+
* 排除字段值
|
|
75
|
+
*/
|
|
76
|
+
excludeValue?: string | number;
|
|
77
|
+
/**
|
|
78
|
+
* 最近距离
|
|
79
|
+
*/
|
|
80
|
+
near?: number;
|
|
81
|
+
/**
|
|
82
|
+
* 最远视
|
|
83
|
+
*/
|
|
84
|
+
far?: number;
|
|
85
|
+
children?: Array<IVtAnnoStyle>;
|
|
86
|
+
}
|
|
87
|
+
export declare class VtAnnoStyle implements IVtAnnoStyle {
|
|
88
|
+
/**
|
|
89
|
+
* 是否可见
|
|
90
|
+
*/
|
|
91
|
+
show?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* 最小级别
|
|
94
|
+
*/
|
|
95
|
+
minLevel?: number;
|
|
96
|
+
/**
|
|
97
|
+
* 最大级别
|
|
98
|
+
*/
|
|
99
|
+
maxLevel?: number;
|
|
100
|
+
/**
|
|
101
|
+
* 重要等级,数字
|
|
102
|
+
* 参考:https://blog.csdn.net/qq_17627195/article/details/117560812
|
|
103
|
+
*/
|
|
104
|
+
weight?: number;
|
|
105
|
+
/**
|
|
106
|
+
* 缩放比例
|
|
107
|
+
*/
|
|
108
|
+
scale: number;
|
|
109
|
+
/**
|
|
110
|
+
* 向上偏移量
|
|
111
|
+
*/
|
|
112
|
+
offset?: number;
|
|
113
|
+
/**
|
|
114
|
+
* 字填充颜色
|
|
115
|
+
*/
|
|
116
|
+
fontColor: string;
|
|
117
|
+
/**
|
|
118
|
+
* 字体名
|
|
119
|
+
*/
|
|
120
|
+
fontFamily: string;
|
|
121
|
+
/**
|
|
122
|
+
* 字体大小 px
|
|
123
|
+
*/
|
|
124
|
+
fontSize: number;
|
|
125
|
+
backgroundColor?: string;
|
|
126
|
+
backgroundPadding?: number;
|
|
127
|
+
outlineColor?: string;
|
|
128
|
+
outlineAlpha?: number;
|
|
129
|
+
outlineWidth?: number;
|
|
130
|
+
imgUrl?: string;
|
|
131
|
+
/**
|
|
132
|
+
* 图标宽、高
|
|
133
|
+
*/
|
|
134
|
+
imgWidth?: number;
|
|
135
|
+
imgHeight?: number;
|
|
136
|
+
/**
|
|
137
|
+
* 标记字段名称,默认为name
|
|
138
|
+
*/
|
|
139
|
+
labelField: string;
|
|
140
|
+
/**
|
|
141
|
+
* 过滤筛选字段
|
|
142
|
+
*/
|
|
143
|
+
filterField?: string;
|
|
144
|
+
/**
|
|
145
|
+
* 排除字段值
|
|
146
|
+
*/
|
|
147
|
+
includeValue?: string | number;
|
|
148
|
+
/**
|
|
149
|
+
* 排除字段值
|
|
150
|
+
*/
|
|
151
|
+
excludeValue?: string | number;
|
|
152
|
+
/**
|
|
153
|
+
* 最近距离
|
|
154
|
+
*/
|
|
155
|
+
near?: number;
|
|
156
|
+
/**
|
|
157
|
+
* 最远视
|
|
158
|
+
*/
|
|
159
|
+
far?: number;
|
|
160
|
+
children?: Array<VtAnnoStyle>;
|
|
161
|
+
get font(): string;
|
|
162
|
+
constructor(src?: IVtAnnoStyle);
|
|
163
|
+
static fromOption(options: IVtAnnoStyle): any;
|
|
164
|
+
/**
|
|
165
|
+
* 合并默认值
|
|
166
|
+
*/
|
|
167
|
+
static fromDefaultOption(options: IVtAnnoStyle): any;
|
|
168
|
+
clone(): VtAnnoStyle;
|
|
169
|
+
copyFrom(src: IVtAnnoStyle): void;
|
|
170
|
+
getLabelOption(): any;
|
|
171
|
+
getBillboardOption(): {};
|
|
172
|
+
}
|
|
173
|
+
export default VtAnnoStyle;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as LabelLayerManager } from './LabelLayerManager';
|
|
2
|
+
export { default as LabelLayer } from './LabelLayer';
|
|
3
|
+
export { default as LabelGeojsonLayer } from './LabelGeojsonLayer';
|
|
4
|
+
export { default as LabelMassiveLayer } from './LabelMassiveLayer';
|
|
5
|
+
export { IVtAnnoStyle, VtAnnoStyle } from './VtAnnoStyle';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BoundingRectangle, Rectangle, Cartesian3 } from '@cesium/engine';
|
|
2
|
+
interface ILabelPoint {
|
|
3
|
+
id: number;
|
|
4
|
+
minZoom?: number;
|
|
5
|
+
maxZoom?: number;
|
|
6
|
+
name: string;
|
|
7
|
+
position: Cartesian3;
|
|
8
|
+
textWidth: number;
|
|
9
|
+
textHeight: number;
|
|
10
|
+
childOptions?: any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 初始化加载点注记图层数据
|
|
14
|
+
* @param layerID 图层ID
|
|
15
|
+
* @param labelGeojsonURL geojsonURL地址
|
|
16
|
+
* @param fieldName label字段属性
|
|
17
|
+
* @param filterField 过滤字段属性
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadLabelPoints(layerID: string, labelGeojsonURL: string, vtStyle: any): Promise<{
|
|
21
|
+
min: any;
|
|
22
|
+
max: any;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* 设置: 取消标志量
|
|
26
|
+
*/
|
|
27
|
+
export declare function cancelPromise(layerID: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* 范围内的所有点索引ID
|
|
30
|
+
* @param layerID 图层ID
|
|
31
|
+
* @param bounds 可视范围
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function filterByBounds(layerID: string, bounds: Rectangle, level?: number): number[] | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* 根据索引ID,获取点对象列表(用于空间计算)
|
|
37
|
+
* @param layerID
|
|
38
|
+
* @param ids
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare function getFilterPointsList(layerID: string, ids: number[]): Array<ILabelPoint> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* 获取Label注记实体列表
|
|
44
|
+
* @param layerID
|
|
45
|
+
* @param ids
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function getLabelEntities(layerID: string, ids: number[]): Array<{
|
|
49
|
+
labelOption: any;
|
|
50
|
+
billboardOption?: any;
|
|
51
|
+
}> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 判断点是否在球的正面
|
|
54
|
+
* @param position
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export declare function isPointOnFrontOfGlobe(point: Cartesian3, cameraPosition: Cartesian3): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 根据图层ID和索引数组,获取点列表
|
|
60
|
+
* @param layerID
|
|
61
|
+
* @param ids
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export declare function getLabelPointList(layerID: string, ids: number[]): Array<ILabelPoint> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* 判断是否相交
|
|
67
|
+
* 循环遍历
|
|
68
|
+
* @param layerID 图层ID
|
|
69
|
+
* @param ptRectBound 面
|
|
70
|
+
* @param numKey 索引号
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare function checkRectangleNoIntersect(layerID: string, ptRectBound: BoundingRectangle, numKey: number): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 移除标注范围
|
|
76
|
+
* @param layerID
|
|
77
|
+
* @param idNum
|
|
78
|
+
*/
|
|
79
|
+
export declare function deleteLabelRectangle(layerID: string, idNum: number): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* 检测两个屏幕空间矩形是否重叠
|
|
82
|
+
* @param {BoundingRectangle} rectA - 第一个矩形
|
|
83
|
+
* @param {BoundingRectangle} rectB - 第二个矩形
|
|
84
|
+
* @returns {boolean} 是否相交
|
|
85
|
+
*/
|
|
86
|
+
export declare function isOverlapping(rectA: BoundingRectangle, rectB: BoundingRectangle): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* 清空某个图层的缓存资源
|
|
89
|
+
* @param layerID
|
|
90
|
+
*/
|
|
91
|
+
export declare function clear(layerID: string): void;
|
|
92
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xgis-label3d",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "三维注记库,进行定制的内部使用版。非商业项目免费使用!",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"common": "dist/index.cjs",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite",
|
|
11
|
+
"build": "vite build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cesium",
|
|
15
|
+
"xgis",
|
|
16
|
+
"typescript",
|
|
17
|
+
"xgis-bdgrid"
|
|
18
|
+
],
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "zorrowm",
|
|
21
|
+
"email": "zorrowm@126.com"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rollup/plugin-alias": "^6.0.0",
|
|
26
|
+
"@rollup/plugin-commonjs": "^29.0.2",
|
|
27
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
28
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
29
|
+
"@vue/language-core": "^3.2.8",
|
|
30
|
+
"rimraf": "^6.1.3",
|
|
31
|
+
"rollup-plugin-esbuild": "^6.2.1",
|
|
32
|
+
"sass": "^1.99.0",
|
|
33
|
+
"terser": "^5.46.2",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vite": "^8.0.10",
|
|
36
|
+
"vite-plugin-comlink": "^5.3.0",
|
|
37
|
+
"vite-plugin-dts": "^5.0.0",
|
|
38
|
+
"vite-plugin-style-import": "^2.0.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@cesium/engine": "^25.0.0",
|
|
42
|
+
"comlink": "^4.4.2",
|
|
43
|
+
"kdbush": "^4.0.2"
|
|
44
|
+
}
|
|
45
|
+
}
|