@spuermomonga/vue3-bmapgl 0.0.6 → 0.0.7
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.js +124 -45
- package/dist/index.prod.js +1 -1
- package/es/layer/xyz/index.d.ts +1 -1
- package/es/layer/xyz/src/xyz-props.d.ts +52 -6
- package/es/layer/xyz/src/xyz-props.mjs +48 -3
- package/es/layer/xyz/src/xyz-props.mjs.map +1 -1
- package/es/layer/xyz/src/xyz.d.ts +103 -7
- package/es/layer/xyz/src/xyz.mjs +78 -44
- package/es/layer/xyz/src/xyz.mjs.map +1 -1
- package/lib/layer/xyz/index.d.ts +1 -1
- package/lib/layer/xyz/src/xyz-props.d.ts +52 -6
- package/lib/layer/xyz/src/xyz-props.js +48 -3
- package/lib/layer/xyz/src/xyz-props.js.map +1 -1
- package/lib/layer/xyz/src/xyz.d.ts +103 -7
- package/lib/layer/xyz/src/xyz.js +77 -43
- package/lib/layer/xyz/src/xyz.js.map +1 -1
- package/package.json +2 -2
- package/es/node_modules/.pnpm/@rollup_plugin-typescript@1_b93953ac7ab797e62adf5212a782f0d9/node_modules/tslib/tslib.es6.mjs +0 -36
- package/es/node_modules/.pnpm/@rollup_plugin-typescript@1_b93953ac7ab797e62adf5212a782f0d9/node_modules/tslib/tslib.es6.mjs.map +0 -1
- package/lib/node_modules/.pnpm/@rollup_plugin-typescript@1_b93953ac7ab797e62adf5212a782f0d9/node_modules/tslib/tslib.es6.js +0 -38
- package/lib/node_modules/.pnpm/@rollup_plugin-typescript@1_b93953ac7ab797e62adf5212a782f0d9/node_modules/tslib/tslib.es6.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -387,9 +387,54 @@
|
|
|
387
387
|
type: Boolean,
|
|
388
388
|
default: true
|
|
389
389
|
},
|
|
390
|
-
|
|
391
|
-
type:
|
|
392
|
-
|
|
390
|
+
getTile: {
|
|
391
|
+
type: Function
|
|
392
|
+
},
|
|
393
|
+
useThumbData: {
|
|
394
|
+
type: Boolean,
|
|
395
|
+
default: false
|
|
396
|
+
},
|
|
397
|
+
xTemplate: {
|
|
398
|
+
type: Function
|
|
399
|
+
},
|
|
400
|
+
yTemplate: {
|
|
401
|
+
type: Function
|
|
402
|
+
},
|
|
403
|
+
zTemplate: {
|
|
404
|
+
type: Function
|
|
405
|
+
},
|
|
406
|
+
bTemplate: {
|
|
407
|
+
type: Function
|
|
408
|
+
},
|
|
409
|
+
minZoom: {
|
|
410
|
+
type: Number,
|
|
411
|
+
default: 3
|
|
412
|
+
},
|
|
413
|
+
maxZoom: {
|
|
414
|
+
type: Number,
|
|
415
|
+
default: 23
|
|
416
|
+
},
|
|
417
|
+
extent: {
|
|
418
|
+
type: Array
|
|
419
|
+
},
|
|
420
|
+
extentCRSIsWGS84: {
|
|
421
|
+
type: Boolean,
|
|
422
|
+
default: false
|
|
423
|
+
},
|
|
424
|
+
boundary: {
|
|
425
|
+
type: Array
|
|
426
|
+
},
|
|
427
|
+
zIndex: {
|
|
428
|
+
type: Number,
|
|
429
|
+
default: 1
|
|
430
|
+
},
|
|
431
|
+
zIndexTop: {
|
|
432
|
+
type: Boolean,
|
|
433
|
+
default: false
|
|
434
|
+
},
|
|
435
|
+
tms: {
|
|
436
|
+
type: Boolean,
|
|
437
|
+
default: false
|
|
393
438
|
}
|
|
394
439
|
};
|
|
395
440
|
|
|
@@ -399,54 +444,88 @@
|
|
|
399
444
|
setup(props) {
|
|
400
445
|
const mapInstance = useMapInstance();
|
|
401
446
|
let layer = null;
|
|
402
|
-
const
|
|
447
|
+
const setZIndex = (zIndex) => {
|
|
448
|
+
layer?.setZIndex(zIndex);
|
|
449
|
+
};
|
|
450
|
+
const setBoundary = (boundary) => {
|
|
451
|
+
boundary && !boundary.length ? layer?.addBoundary(boundary) : layer?.clearBoundary();
|
|
452
|
+
};
|
|
453
|
+
const setZIndexTop = (zIndexTop) => {
|
|
454
|
+
zIndexTop && layer?.setZIndexTop();
|
|
455
|
+
};
|
|
456
|
+
const initLayerOptions = () => {
|
|
403
457
|
const {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const key = this.getTileKey(tileInfo);
|
|
410
|
-
const handleImageLoad = (image) => {
|
|
411
|
-
image.tileInfo = tileInfo;
|
|
412
|
-
callback && callback(image, key);
|
|
413
|
-
};
|
|
414
|
-
const handleError = () => callback && callback(null, key);
|
|
415
|
-
getTile(tileInfo, (img) => {
|
|
416
|
-
if (typeof img === "string" || img instanceof HTMLCanvasElement) {
|
|
417
|
-
const image = new Image();
|
|
418
|
-
image.crossOrigin = "anonymous";
|
|
419
|
-
image.onload = () => handleImageLoad(image);
|
|
420
|
-
image.onerror = handleError;
|
|
421
|
-
image.src = typeof img === "string" ? img : img.toDataURL();
|
|
422
|
-
} else if (img instanceof HTMLImageElement) {
|
|
423
|
-
handleImageLoad(img);
|
|
424
|
-
} else {
|
|
425
|
-
handleError();
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
};
|
|
429
|
-
} else {
|
|
430
|
-
mapInstance().addTileLayer(layer2);
|
|
431
|
-
}
|
|
458
|
+
zIndex,
|
|
459
|
+
zIndexTop
|
|
460
|
+
} = props;
|
|
461
|
+
setZIndex(zIndex);
|
|
462
|
+
setZIndexTop(zIndexTop);
|
|
432
463
|
};
|
|
433
|
-
const
|
|
434
|
-
|
|
464
|
+
const startWatchProps = () => {
|
|
465
|
+
vue.watch(() => props.zIndex, setZIndex);
|
|
466
|
+
vue.watch(() => props.boundary, setBoundary);
|
|
435
467
|
};
|
|
436
|
-
const
|
|
437
|
-
if (layer) {
|
|
438
|
-
removeTileLayer(layer);
|
|
439
|
-
}
|
|
468
|
+
const init = () => {
|
|
440
469
|
const {
|
|
470
|
+
visible,
|
|
441
471
|
getTile,
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
472
|
+
xTemplate,
|
|
473
|
+
yTemplate,
|
|
474
|
+
zTemplate,
|
|
475
|
+
bTemplate,
|
|
476
|
+
minZoom,
|
|
477
|
+
maxZoom,
|
|
478
|
+
extent,
|
|
479
|
+
extentCRSIsWGS84,
|
|
480
|
+
boundary,
|
|
481
|
+
useThumbData,
|
|
482
|
+
tms
|
|
483
|
+
} = props;
|
|
484
|
+
layer = new BMapGL.XYZLayer({
|
|
485
|
+
xTemplate,
|
|
486
|
+
yTemplate,
|
|
487
|
+
zTemplate,
|
|
488
|
+
bTemplate,
|
|
489
|
+
minZoom,
|
|
490
|
+
maxZoom,
|
|
491
|
+
extent,
|
|
492
|
+
extentCRSIsWGS84,
|
|
493
|
+
boundary,
|
|
494
|
+
useThumbData,
|
|
495
|
+
tms
|
|
496
|
+
});
|
|
497
|
+
initLayerOptions();
|
|
498
|
+
if (visible) {
|
|
499
|
+
if (getTile) {
|
|
500
|
+
mapInstance().addTileLayer(layer);
|
|
501
|
+
layer.loadRasterTileData = function(tileInfo, callback) {
|
|
502
|
+
const key = this.getTileKey(tileInfo);
|
|
503
|
+
const handleImageLoad = (image) => {
|
|
504
|
+
image.tileInfo = tileInfo;
|
|
505
|
+
callback && callback(image, key);
|
|
506
|
+
};
|
|
507
|
+
const handleError = () => callback && callback(null, key);
|
|
508
|
+
getTile(tileInfo, (img) => {
|
|
509
|
+
if (typeof img === "string" || img instanceof HTMLCanvasElement) {
|
|
510
|
+
const image = new Image();
|
|
511
|
+
image.crossOrigin = "anonymous";
|
|
512
|
+
image.onload = () => handleImageLoad(image);
|
|
513
|
+
image.onerror = handleError;
|
|
514
|
+
image.src = typeof img === "string" ? img : img.toDataURL();
|
|
515
|
+
} else if (img instanceof HTMLImageElement) {
|
|
516
|
+
handleImageLoad(img);
|
|
517
|
+
} else {
|
|
518
|
+
handleError();
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
} else {
|
|
523
|
+
mapInstance().addTileLayer(layer);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
startWatchProps();
|
|
446
527
|
};
|
|
447
|
-
|
|
448
|
-
vue.watch(() => props.visible, (n) => layer && (n ? addTileLayer(layer) : removeTileLayer(layer)));
|
|
449
|
-
vue.watch(() => props.options, () => createLayer());
|
|
528
|
+
init();
|
|
450
529
|
vue.onUnmounted(() => {
|
|
451
530
|
if (layer) {
|
|
452
531
|
mapInstance().removeTileLayer(layer);
|
package/dist/index.prod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Vue3Bmapgl={},e.vue)}(this,function(e,t){"use strict";let a=!1;function o(e){return e.some(e=>!t.isVNode(e)||e.type!==Comment&&!(e.type===t.Fragment&&!o(e.children)))?e:null}function n(e,t){return t(e&&o(e())||null)}const l={ak:String,apiUrl:String,plugins:Array,mapConfig:Object},r=Symbol("b-config-provider");var i=t.defineComponent({name:"ConfigProvider",props:l,setup(e,{slots:o}){const n=t.ref("notload"),l=e.apiUrl?"_initBMap_":`_initBMap_${e.ak}`,i=e.apiUrl?`${e.apiUrl.replace(/&$/,"")}&callback=${l}`:`//api.map.baidu.com/api?type=webgl&v=1.0&ak=${e.ak}&callback=${l}`;n.value="pending",function(e){const{key:t,src:o,addCalToWindow:n=!0,timeout:l=1e4}=e;return a&&window.BMapGL?Promise.resolve():new Promise((e,r)=>{const i=document.createElement("script");i.src=o,i.type="text/javascript",i.defer=!0;const
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Vue3Bmapgl={},e.vue)}(this,function(e,t){"use strict";let a=!1;function o(e){return e.some(e=>!t.isVNode(e)||e.type!==Comment&&!(e.type===t.Fragment&&!o(e.children)))?e:null}function n(e,t){return t(e&&o(e())||null)}const l={ak:String,apiUrl:String,plugins:Array,mapConfig:Object},r=Symbol("b-config-provider");var i=t.defineComponent({name:"ConfigProvider",props:l,setup(e,{slots:o}){const n=t.ref("notload"),l=e.apiUrl?"_initBMap_":`_initBMap_${e.ak}`,i=e.apiUrl?`${e.apiUrl.replace(/&$/,"")}&callback=${l}`:`//api.map.baidu.com/api?type=webgl&v=1.0&ak=${e.ak}&callback=${l}`;n.value="pending",function(e){const{key:t,src:o,addCalToWindow:n=!0,timeout:l=1e4}=e;return a&&window.BMapGL?Promise.resolve():new Promise((e,r)=>{const i=document.createElement("script");i.src=o,i.type="text/javascript",i.defer=!0;const p=()=>{i.onload=null,i.onerror=null,document.body.contains(i)&&document.body.removeChild(i)},s=setTimeout(()=>{p(),r(new Error(`Script load timeout: ${o}`))},l),d=()=>{clearTimeout(s),a=!0,p(),e()};n?window[t]=d:i.onload=d,i.onerror=()=>{clearTimeout(s),p(),r(new Error(`Failed to load script: ${o}`))},document.body.appendChild(i)})}({key:l,src:i}).then(()=>{n.value="loaded"}).catch(()=>{n.value="failed"});const p=t.computed(()=>{const{mapConfig:t}=e;return t??{}});return t.provide(r,{mergedStatusRef:n,mergedMapSetRef:p}),()=>t.renderSlot(o,"default")}}),p=t.defineComponent({name:"TileLayer",setup:()=>()=>t.createVNode("div",null,[t.createTextVNode("Tile")])});const s=Symbol("b-map"),d={maxZoom:{type:Number,default:21},minZoom:{type:Number,default:0},heading:{type:Number,default:0},center:{type:Object,default:[116.403901,39.915185]},zoom:{type:Number,default:14},class:String,contentClass:String,enableScrollWheelZoom:{type:Boolean,default:!1},enableDragging:{type:Boolean,default:!0},tilt:{type:Number,default:0},enableTilt:{type:Boolean,default:!1},mapType:{type:String,default:"BMAP_NORMAL_MAP"},enableAutoResize:{type:Boolean,default:!0},enableTiltGestures:{type:Boolean,default:!1},enableRotate:{type:Boolean,default:!1},enableRotateGestures:{type:Boolean,default:!1},displayOptions:{type:Object},onInitd:Function};var u="map-module_b-map__29r3m",m="map-module_b-map-content__sMaJG",c="map-module_b-map-loading__qc4a8",f="map-module_b-map-failed__-w-tX";!function(e,t){void 0===t&&(t={});var a=t.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===a&&o.firstChild?o.insertBefore(n,o.firstChild):o.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}(".map-module_b-map-content__sMaJG,.map-module_b-map__29r3m{height:100%;overflow:hidden;position:relative;width:100%}.map-module_b-map-failed__-w-tX,.map-module_b-map-loading__qc4a8{color:#999;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}");var y=t.defineComponent({name:"Map",props:d,slots:Object,setup(e,{slots:a}){const{mergedMapSetRef:o,mergedStatusRef:l}=function(e={}){const a=t.inject(r,null);return{mergedStatusRef:a?.mergedStatusRef,mergedMapSetRef:t.computed(()=>{const{zoom:t,center:o,heading:n,minZoom:l,maxZoom:r,enableScrollWheelZoom:i,enableDragging:p,tilt:s,enableTilt:d,mapType:u,enableAutoResize:m,enableTiltGestures:c,enableRotate:f,enableRotateGestures:y,displayOptions:g}=e;return{zoom:t??a?.mergedMapSetRef.value?.zoom,center:o??a?.mergedMapSetRef.value?.center,heading:n??a?.mergedMapSetRef.value?.heading,minZoom:l??a?.mergedMapSetRef.value?.minZoom,maxZoom:r??a?.mergedMapSetRef.value?.maxZoom,enableScrollWheelZoom:i??a?.mergedMapSetRef.value?.enableScrollWheelZoom,enableDragging:p??a?.mergedMapSetRef.value?.enableDragging,tilt:s??a?.mergedMapSetRef.value?.tilt,enableTilt:d??a?.mergedMapSetRef.value?.enableTilt,mapType:u??a?.mergedMapSetRef.value?.mapType,enableAutoResize:m??a?.mergedMapSetRef.value?.enableAutoResize,enableTiltGestures:c??a?.mergedMapSetRef.value?.enableTiltGestures,enableRotate:f??a?.mergedMapSetRef.value?.enableRotate,enableRotateGestures:y??a?.mergedMapSetRef.value?.enableRotateGestures,displayOptions:g??a?.mergedMapSetRef.value?.displayOptions}})}}(e),i=t.ref();let p=null;const d=t.ref(!1);t.provide(s,{mapInstance:()=>p});const y=e=>{"string"==typeof e?p?.centerAndZoom(e,o.value.zoom):Array.isArray(e)?p?.centerAndZoom(new BMapGL.Point(e[0],e[1]),o.value.zoom):p?.centerAndZoom(e,o.value.zoom)},g=e=>{e?p.enableScrollWheelZoom():p.disableScrollWheelZoom()},b=e=>{p?.setDisplayOptions(e||{})},v=e=>{p?.setTilt(e??0)},T=e=>{p?.setHeading(e??0)},h=e=>{e?p.enableDragging():p.disableDragging()},S=e=>{void 0!==window[e]&&p.setMapType(window[e])},R=()=>{const{maxZoom:a,minZoom:n,enableTilt:l,mapType:r,enableAutoResize:s,enableTiltGestures:u,enableRotate:m,enableRotateGestures:c,displayOptions:f}=o.value;p=new BMapGL.Map(i.value,{maxZoom:a,minZoom:n,enableTilt:l,mapType:window[r],enableAutoResize:s,enableTiltGestures:u,enableRotate:m,enableRotateGestures:c,displayOptions:f});const{onInitd:R}=e;(()=>{const{center:e,heading:t,enableScrollWheelZoom:a,tilt:n,enableDragging:l}=o.value;T(t),y(e),g(a),v(n),h(l)})(),t.watch(()=>o.value.center,y,{deep:!0}),t.watch(()=>o.value.enableScrollWheelZoom,g),t.watch(()=>o.value.displayOptions,b),t.watch(()=>o.value.tilt,v),t.watch(()=>o.value.heading,T),t.watch(()=>o.value.enableDragging,h),t.watch(()=>o.value.mapType,S),R?.({map:p}),d.value=!0};return t.onMounted(()=>{t.watchEffect(()=>{"loaded"!==l?.value||d.value||t.nextTick(R)})}),t.onUnmounted(()=>{if(p)try{p?.destroy()}catch(e){console.error(`[Vue3 BMapGL]: ${e.message}`)}}),()=>t.createVNode("div",{class:[[u],e.class]},[t.createVNode("div",{ref:i,class:[m,e.contentClass]},["pending"===l?.value&&n(a.loading,()=>t.createVNode("div",{class:[c]},[t.createTextVNode("map loading...")])),"failed"===l?.value&&n(a.failed,()=>t.createVNode("div",{class:[f]},[t.createTextVNode("map failed")]))]),d.value&&a.default?.()])}});function g(){return t.inject(s,null).mapInstance}const b={visible:{type:Boolean,default:!0},getTile:{type:Function},useThumbData:{type:Boolean,default:!1},xTemplate:{type:Function},yTemplate:{type:Function},zTemplate:{type:Function},bTemplate:{type:Function},minZoom:{type:Number,default:3},maxZoom:{type:Number,default:23},extent:{type:Array},extentCRSIsWGS84:{type:Boolean,default:!1},boundary:{type:Array},zIndex:{type:Number,default:1},zIndexTop:{type:Boolean,default:!1},tms:{type:Boolean,default:!1}};var v=t.defineComponent({name:"XyzLayer",props:b,setup(e){const a=g();let o=null;const n=e=>{o?.setZIndex(e)},l=e=>{e&&!e.length?o?.addBoundary(e):o?.clearBoundary()},r=()=>{const{zIndex:t,zIndexTop:a}=e;n(t),(e=>{e&&o?.setZIndexTop()})(a)};return(()=>{const{visible:i,getTile:p,xTemplate:s,yTemplate:d,zTemplate:u,bTemplate:m,minZoom:c,maxZoom:f,extent:y,extentCRSIsWGS84:g,boundary:b,useThumbData:v,tms:T}=e;o=new BMapGL.XYZLayer({xTemplate:s,yTemplate:d,zTemplate:u,bTemplate:m,minZoom:c,maxZoom:f,extent:y,extentCRSIsWGS84:g,boundary:b,useThumbData:v,tms:T}),r(),i&&(p?(a().addTileLayer(o),o.loadRasterTileData=function(e,t){const a=this.getTileKey(e),o=o=>{o.tileInfo=e,t&&t(o,a)},n=()=>t&&t(null,a);p(e,e=>{if("string"==typeof e||e instanceof HTMLCanvasElement){const t=new Image;t.crossOrigin="anonymous",t.onload=()=>o(t),t.onerror=n,t.src="string"==typeof e?e:e.toDataURL()}else e instanceof HTMLImageElement?o(e):n()})}):a().addTileLayer(o)),t.watch(()=>e.zIndex,n),t.watch(()=>e.boundary,l)})(),t.onUnmounted(()=>{o&&a().removeTileLayer(o)}),()=>t.createVNode(t.Fragment,null,null)}});const T={visible:{type:Boolean,default:!0},points:{type:Array},strokeColor:{type:String,default:"#000"},fillColor:{type:String,default:"#fff"},strokeWeight:{type:Number,default:2},strokeOpacity:{type:Number,default:1},fillOpacity:{type:Number,default:.3},strokeStyle:{type:String,default:"solid"},enableMassClear:{type:Boolean,default:!0},enableEditing:{type:Boolean,default:!1},isBoundary:{type:Boolean},enableClicking:{type:Boolean,default:!0}};var h=t.defineComponent({name:"Polygon",props:T,setup:e=>{const a=g();let o=null;const n=e=>{o&&o.setStrokeColor(e)};return(()=>{const{points:l,visible:r,strokeColor:i,fillColor:p,strokeWeight:s,strokeOpacity:d,fillOpacity:u,strokeStyle:m,enableMassClear:c,enableEditing:f,enableClicking:y}=e;l&&l.length&&(o=new BMapGL.Polygon(function(e){if(!e||0===e.length)return[];const t=e[0];return Array.isArray(t)?e.map(([e,t])=>new BMapGL.Point(e,t)):e}(l),{strokeColor:i,fillColor:p,strokeWeight:s,strokeOpacity:d,fillOpacity:u,strokeStyle:m,enableMassClear:c,enableEditing:f,enableClicking:y}),r&&a().addOverlay(o),t.watch(()=>e.strokeColor,n),t.watch(()=>e.visible,e=>{a()[e?"addOverlay":"removeOverlay"](o)}))})(),t.onUnmounted(()=>{o&&a().removeOverlay(o)}),()=>t.createVNode(t.Fragment,null,null)}}),S=t.defineComponent({name:"Sector",setup:()=>()=>t.createVNode(t.Fragment,null,null)});e.BConfigProvider=i,e.BMap=y,e.BPolygon=h,e.BSector=S,e.BTileLayer=p,e.BXyzLayer=v,e.configProviderInjectionKey=r,e.configProviderProps=l,e.create=function({componentPrefix:e="B",components:t=[]}={}){const a=[];function o(t,a,o){t.component(e+a)||t.component(e+a,o)}return{componentPrefix:e,install:function(e){a.includes(e)||(a.push(e),t.forEach(t=>{const{name:a,alias:n}=t;o(e,a,t),n&&n.forEach(a=>{o(e,a,t)})}))}}},e.mapInjectionKey=s,e.mapProps=d,e.polygonProps=T,e.xyzLayerProps=b});
|
package/es/layer/xyz/index.d.ts
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
1
1
|
import type { PropType } from 'vue';
|
|
2
2
|
import type { ExtractPublicPropTypes } from '../../../_utils';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type TemplateFn = (x: number, y: number, z: number) => number;
|
|
4
|
+
type BTemplateFn = (x: number, y: number, z: number) => string;
|
|
5
|
+
type GetTile = (info: any, cb: (image: string | HTMLImageElement | HTMLCanvasElement) => void) => void;
|
|
6
6
|
export declare const xyzLayerProps: {
|
|
7
7
|
readonly visible: {
|
|
8
8
|
readonly type: BooleanConstructor;
|
|
9
9
|
readonly default: true;
|
|
10
10
|
};
|
|
11
|
-
readonly
|
|
12
|
-
readonly type: PropType<
|
|
13
|
-
|
|
11
|
+
readonly getTile: {
|
|
12
|
+
readonly type: PropType<GetTile>;
|
|
13
|
+
};
|
|
14
|
+
readonly useThumbData: {
|
|
15
|
+
readonly type: BooleanConstructor;
|
|
16
|
+
readonly default: false;
|
|
17
|
+
};
|
|
18
|
+
readonly xTemplate: {
|
|
19
|
+
readonly type: PropType<TemplateFn>;
|
|
20
|
+
};
|
|
21
|
+
readonly yTemplate: {
|
|
22
|
+
readonly type: PropType<TemplateFn>;
|
|
23
|
+
};
|
|
24
|
+
readonly zTemplate: {
|
|
25
|
+
readonly type: PropType<TemplateFn>;
|
|
26
|
+
};
|
|
27
|
+
readonly bTemplate: {
|
|
28
|
+
readonly type: PropType<BTemplateFn>;
|
|
29
|
+
};
|
|
30
|
+
readonly minZoom: {
|
|
31
|
+
readonly type: NumberConstructor;
|
|
32
|
+
readonly default: 3;
|
|
33
|
+
};
|
|
34
|
+
readonly maxZoom: {
|
|
35
|
+
readonly type: NumberConstructor;
|
|
36
|
+
readonly default: 23;
|
|
37
|
+
};
|
|
38
|
+
readonly extent: {
|
|
39
|
+
readonly type: PropType<number[]>;
|
|
40
|
+
};
|
|
41
|
+
readonly extentCRSIsWGS84: {
|
|
42
|
+
readonly type: BooleanConstructor;
|
|
43
|
+
readonly default: false;
|
|
44
|
+
};
|
|
45
|
+
readonly boundary: {
|
|
46
|
+
readonly type: PropType<string[]>;
|
|
47
|
+
};
|
|
48
|
+
readonly zIndex: {
|
|
49
|
+
readonly type: NumberConstructor;
|
|
50
|
+
readonly default: 1;
|
|
51
|
+
};
|
|
52
|
+
readonly zIndexTop: {
|
|
53
|
+
readonly type: BooleanConstructor;
|
|
54
|
+
readonly default: false;
|
|
55
|
+
};
|
|
56
|
+
readonly tms: {
|
|
57
|
+
readonly type: BooleanConstructor;
|
|
58
|
+
readonly default: false;
|
|
14
59
|
};
|
|
15
60
|
};
|
|
16
61
|
export type XyzLayerProps = ExtractPublicPropTypes<typeof xyzLayerProps>;
|
|
62
|
+
export {};
|
|
@@ -3,9 +3,54 @@ const xyzLayerProps = {
|
|
|
3
3
|
type: Boolean,
|
|
4
4
|
default: true
|
|
5
5
|
},
|
|
6
|
-
|
|
7
|
-
type:
|
|
8
|
-
|
|
6
|
+
getTile: {
|
|
7
|
+
type: Function
|
|
8
|
+
},
|
|
9
|
+
useThumbData: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: false
|
|
12
|
+
},
|
|
13
|
+
xTemplate: {
|
|
14
|
+
type: Function
|
|
15
|
+
},
|
|
16
|
+
yTemplate: {
|
|
17
|
+
type: Function
|
|
18
|
+
},
|
|
19
|
+
zTemplate: {
|
|
20
|
+
type: Function
|
|
21
|
+
},
|
|
22
|
+
bTemplate: {
|
|
23
|
+
type: Function
|
|
24
|
+
},
|
|
25
|
+
minZoom: {
|
|
26
|
+
type: Number,
|
|
27
|
+
default: 3
|
|
28
|
+
},
|
|
29
|
+
maxZoom: {
|
|
30
|
+
type: Number,
|
|
31
|
+
default: 23
|
|
32
|
+
},
|
|
33
|
+
extent: {
|
|
34
|
+
type: Array
|
|
35
|
+
},
|
|
36
|
+
extentCRSIsWGS84: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
boundary: {
|
|
41
|
+
type: Array
|
|
42
|
+
},
|
|
43
|
+
zIndex: {
|
|
44
|
+
type: Number,
|
|
45
|
+
default: 1
|
|
46
|
+
},
|
|
47
|
+
zIndexTop: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false
|
|
50
|
+
},
|
|
51
|
+
tms: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false
|
|
9
54
|
}
|
|
10
55
|
};
|
|
11
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xyz-props.mjs","sources":["../../../../src/layer/xyz/src/file:/D:/workspaces/personal-project/vue3-bmapgl/packages/vue3-bmapgl/src/layer/xyz/src/xyz-props.ts"],"sourcesContent":["import type { PropType } from 'vue'\r\nimport type { ExtractPublicPropTypes } from '../../../_utils'\r\n\r\
|
|
1
|
+
{"version":3,"file":"xyz-props.mjs","sources":["../../../../src/layer/xyz/src/file:/D:/workspaces/personal-project/vue3-bmapgl/packages/vue3-bmapgl/src/layer/xyz/src/xyz-props.ts"],"sourcesContent":["import type { PropType } from 'vue'\r\nimport type { ExtractPublicPropTypes } from '../../../_utils'\r\n\r\ntype TemplateFn = (x: number, y: number, z: number) => number\r\ntype BTemplateFn = (x: number, y: number, z: number) => string\r\ntype GetTile = (info: any, cb: (image: string | HTMLImageElement | HTMLCanvasElement) => void) => void\r\n\r\nexport const xyzLayerProps = {\r\n visible: {\r\n type: Boolean,\r\n default: true,\r\n },\r\n getTile: {\r\n type: Function as PropType<GetTile>,\r\n },\r\n useThumbData: {\r\n type: Boolean,\r\n default: false,\r\n },\r\n xTemplate: {\r\n type: Function as PropType<TemplateFn>,\r\n },\r\n yTemplate: {\r\n type: Function as PropType<TemplateFn>,\r\n },\r\n zTemplate: {\r\n type: Function as PropType<TemplateFn>,\r\n },\r\n bTemplate: {\r\n type: Function as PropType<BTemplateFn>,\r\n },\r\n minZoom: {\r\n type: Number,\r\n default: 3,\r\n },\r\n maxZoom: {\r\n type: Number,\r\n default: 23,\r\n },\r\n extent: {\r\n type: Array as PropType<number[]>,\r\n },\r\n extentCRSIsWGS84: {\r\n type: Boolean,\r\n default: false,\r\n },\r\n boundary: {\r\n type: Array as PropType<string[]>,\r\n },\r\n zIndex: {\r\n type: Number,\r\n default: 1,\r\n },\r\n zIndexTop: {\r\n type: Boolean,\r\n default: false,\r\n },\r\n tms: {\r\n type: Boolean,\r\n default: false,\r\n },\r\n} as const\r\n\r\nexport type XyzLayerProps = ExtractPublicPropTypes<typeof xyzLayerProps>\r\n"],"names":[],"mappings":"AAOO,MAAM,aAAA,GAAgB;AAAA,EAC3B,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,OAAA,EAAS;AAAA,IACP,IAAA,EAAM;AAAA,GACP;AAAA,EACD,YAAA,EAAc;AAAA,IACZ,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,SAAA,EAAW;AAAA,IACT,IAAA,EAAM;AAAA,GACP;AAAA,EACD,SAAA,EAAW;AAAA,IACT,IAAA,EAAM;AAAA,GACP;AAAA,EACD,SAAA,EAAW;AAAA,IACT,IAAA,EAAM;AAAA,GACP;AAAA,EACD,SAAA,EAAW;AAAA,IACT,IAAA,EAAM;AAAA,GACP;AAAA,EACD,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,MAAA,EAAQ;AAAA,IACN,IAAA,EAAM;AAAA,GACP;AAAA,EACD,gBAAA,EAAkB;AAAA,IAChB,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,QAAA,EAAU;AAAA,IACR,IAAA,EAAM;AAAA,GACP;AAAA,EACD,MAAA,EAAQ;AAAA,IACN,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,SAAA,EAAW;AAAA,IACT,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACV;AAAA,EACD,GAAA,EAAK;AAAA,IACH,IAAA,EAAM,OAAA;AAAA,IACN,OAAA,EAAS;AAAA;;;;;"}
|
|
@@ -3,21 +3,117 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
3
3
|
readonly type: BooleanConstructor;
|
|
4
4
|
readonly default: true;
|
|
5
5
|
};
|
|
6
|
-
readonly
|
|
7
|
-
readonly type: import("vue").PropType<
|
|
8
|
-
|
|
6
|
+
readonly getTile: {
|
|
7
|
+
readonly type: import("vue").PropType<(info: any, cb: (image: string | HTMLImageElement | HTMLCanvasElement) => void) => void>;
|
|
8
|
+
};
|
|
9
|
+
readonly useThumbData: {
|
|
10
|
+
readonly type: BooleanConstructor;
|
|
11
|
+
readonly default: false;
|
|
12
|
+
};
|
|
13
|
+
readonly xTemplate: {
|
|
14
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
15
|
+
};
|
|
16
|
+
readonly yTemplate: {
|
|
17
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
18
|
+
};
|
|
19
|
+
readonly zTemplate: {
|
|
20
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
21
|
+
};
|
|
22
|
+
readonly bTemplate: {
|
|
23
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => string>;
|
|
24
|
+
};
|
|
25
|
+
readonly minZoom: {
|
|
26
|
+
readonly type: NumberConstructor;
|
|
27
|
+
readonly default: 3;
|
|
28
|
+
};
|
|
29
|
+
readonly maxZoom: {
|
|
30
|
+
readonly type: NumberConstructor;
|
|
31
|
+
readonly default: 23;
|
|
32
|
+
};
|
|
33
|
+
readonly extent: {
|
|
34
|
+
readonly type: import("vue").PropType<number[]>;
|
|
35
|
+
};
|
|
36
|
+
readonly extentCRSIsWGS84: {
|
|
37
|
+
readonly type: BooleanConstructor;
|
|
38
|
+
readonly default: false;
|
|
39
|
+
};
|
|
40
|
+
readonly boundary: {
|
|
41
|
+
readonly type: import("vue").PropType<string[]>;
|
|
42
|
+
};
|
|
43
|
+
readonly zIndex: {
|
|
44
|
+
readonly type: NumberConstructor;
|
|
45
|
+
readonly default: 1;
|
|
46
|
+
};
|
|
47
|
+
readonly zIndexTop: {
|
|
48
|
+
readonly type: BooleanConstructor;
|
|
49
|
+
readonly default: false;
|
|
50
|
+
};
|
|
51
|
+
readonly tms: {
|
|
52
|
+
readonly type: BooleanConstructor;
|
|
53
|
+
readonly default: false;
|
|
9
54
|
};
|
|
10
55
|
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
11
56
|
readonly visible: {
|
|
12
57
|
readonly type: BooleanConstructor;
|
|
13
58
|
readonly default: true;
|
|
14
59
|
};
|
|
15
|
-
readonly
|
|
16
|
-
readonly type: import("vue").PropType<
|
|
17
|
-
|
|
60
|
+
readonly getTile: {
|
|
61
|
+
readonly type: import("vue").PropType<(info: any, cb: (image: string | HTMLImageElement | HTMLCanvasElement) => void) => void>;
|
|
62
|
+
};
|
|
63
|
+
readonly useThumbData: {
|
|
64
|
+
readonly type: BooleanConstructor;
|
|
65
|
+
readonly default: false;
|
|
66
|
+
};
|
|
67
|
+
readonly xTemplate: {
|
|
68
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
69
|
+
};
|
|
70
|
+
readonly yTemplate: {
|
|
71
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
72
|
+
};
|
|
73
|
+
readonly zTemplate: {
|
|
74
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => number>;
|
|
75
|
+
};
|
|
76
|
+
readonly bTemplate: {
|
|
77
|
+
readonly type: import("vue").PropType<(x: number, y: number, z: number) => string>;
|
|
78
|
+
};
|
|
79
|
+
readonly minZoom: {
|
|
80
|
+
readonly type: NumberConstructor;
|
|
81
|
+
readonly default: 3;
|
|
82
|
+
};
|
|
83
|
+
readonly maxZoom: {
|
|
84
|
+
readonly type: NumberConstructor;
|
|
85
|
+
readonly default: 23;
|
|
86
|
+
};
|
|
87
|
+
readonly extent: {
|
|
88
|
+
readonly type: import("vue").PropType<number[]>;
|
|
89
|
+
};
|
|
90
|
+
readonly extentCRSIsWGS84: {
|
|
91
|
+
readonly type: BooleanConstructor;
|
|
92
|
+
readonly default: false;
|
|
93
|
+
};
|
|
94
|
+
readonly boundary: {
|
|
95
|
+
readonly type: import("vue").PropType<string[]>;
|
|
96
|
+
};
|
|
97
|
+
readonly zIndex: {
|
|
98
|
+
readonly type: NumberConstructor;
|
|
99
|
+
readonly default: 1;
|
|
100
|
+
};
|
|
101
|
+
readonly zIndexTop: {
|
|
102
|
+
readonly type: BooleanConstructor;
|
|
103
|
+
readonly default: false;
|
|
104
|
+
};
|
|
105
|
+
readonly tms: {
|
|
106
|
+
readonly type: BooleanConstructor;
|
|
107
|
+
readonly default: false;
|
|
18
108
|
};
|
|
19
109
|
}>> & Readonly<{}>, {
|
|
110
|
+
readonly minZoom: number;
|
|
111
|
+
readonly maxZoom: number;
|
|
20
112
|
readonly visible: boolean;
|
|
21
|
-
readonly
|
|
113
|
+
readonly useThumbData: boolean;
|
|
114
|
+
readonly extentCRSIsWGS84: boolean;
|
|
115
|
+
readonly zIndex: number;
|
|
116
|
+
readonly zIndexTop: boolean;
|
|
117
|
+
readonly tms: boolean;
|
|
22
118
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
23
119
|
export default _default;
|
package/es/layer/xyz/src/xyz.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { defineComponent,
|
|
2
|
-
import { __rest } from '../../../node_modules/.pnpm/@rollup_plugin-typescript@1_b93953ac7ab797e62adf5212a782f0d9/node_modules/tslib/tslib.es6.mjs';
|
|
1
|
+
import { defineComponent, onUnmounted, createVNode, Fragment, watch } from 'vue';
|
|
3
2
|
import { xyzLayerProps } from './xyz-props.mjs';
|
|
4
3
|
import useMapInstance from '../../../_mixins/use-map-instance.mjs';
|
|
5
4
|
|
|
@@ -9,53 +8,88 @@ var xyz = /* @__PURE__ */ defineComponent({
|
|
|
9
8
|
setup(props) {
|
|
10
9
|
const mapInstance = useMapInstance();
|
|
11
10
|
let layer = null;
|
|
12
|
-
const
|
|
11
|
+
const setZIndex = (zIndex) => {
|
|
12
|
+
layer === null || layer === void 0 ? void 0 : layer.setZIndex(zIndex);
|
|
13
|
+
};
|
|
14
|
+
const setBoundary = (boundary) => {
|
|
15
|
+
boundary && !boundary.length ? layer === null || layer === void 0 ? void 0 : layer.addBoundary(boundary) : layer === null || layer === void 0 ? void 0 : layer.clearBoundary();
|
|
16
|
+
};
|
|
17
|
+
const setZIndexTop = (zIndexTop) => {
|
|
18
|
+
zIndexTop && (layer === null || layer === void 0 ? void 0 : layer.setZIndexTop());
|
|
19
|
+
};
|
|
20
|
+
const initLayerOptions = () => {
|
|
13
21
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const key = this.getTileKey(tileInfo);
|
|
20
|
-
const handleImageLoad = (image) => {
|
|
21
|
-
image.tileInfo = tileInfo;
|
|
22
|
-
callback && callback(image, key);
|
|
23
|
-
};
|
|
24
|
-
const handleError = () => callback && callback(null, key);
|
|
25
|
-
getTile(tileInfo, (img) => {
|
|
26
|
-
if (typeof img === "string" || img instanceof HTMLCanvasElement) {
|
|
27
|
-
const image = new Image();
|
|
28
|
-
image.crossOrigin = "anonymous";
|
|
29
|
-
image.onload = () => handleImageLoad(image);
|
|
30
|
-
image.onerror = handleError;
|
|
31
|
-
image.src = typeof img === "string" ? img : img.toDataURL();
|
|
32
|
-
} else if (img instanceof HTMLImageElement) {
|
|
33
|
-
handleImageLoad(img);
|
|
34
|
-
} else {
|
|
35
|
-
handleError();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
} else {
|
|
40
|
-
mapInstance().addTileLayer(layer2);
|
|
41
|
-
}
|
|
22
|
+
zIndex,
|
|
23
|
+
zIndexTop
|
|
24
|
+
} = props;
|
|
25
|
+
setZIndex(zIndex);
|
|
26
|
+
setZIndexTop(zIndexTop);
|
|
42
27
|
};
|
|
43
|
-
const
|
|
44
|
-
|
|
28
|
+
const startWatchProps = () => {
|
|
29
|
+
watch(() => props.zIndex, setZIndex);
|
|
30
|
+
watch(() => props.boundary, setBoundary);
|
|
45
31
|
};
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
const init = () => {
|
|
33
|
+
const {
|
|
34
|
+
visible,
|
|
35
|
+
getTile,
|
|
36
|
+
xTemplate,
|
|
37
|
+
yTemplate,
|
|
38
|
+
zTemplate,
|
|
39
|
+
bTemplate,
|
|
40
|
+
minZoom,
|
|
41
|
+
maxZoom,
|
|
42
|
+
extent,
|
|
43
|
+
extentCRSIsWGS84,
|
|
44
|
+
boundary,
|
|
45
|
+
useThumbData,
|
|
46
|
+
tms
|
|
47
|
+
} = props;
|
|
48
|
+
layer = new BMapGL.XYZLayer({
|
|
49
|
+
xTemplate,
|
|
50
|
+
yTemplate,
|
|
51
|
+
zTemplate,
|
|
52
|
+
bTemplate,
|
|
53
|
+
minZoom,
|
|
54
|
+
maxZoom,
|
|
55
|
+
extent,
|
|
56
|
+
extentCRSIsWGS84,
|
|
57
|
+
boundary,
|
|
58
|
+
useThumbData,
|
|
59
|
+
tms
|
|
60
|
+
});
|
|
61
|
+
initLayerOptions();
|
|
62
|
+
if (visible) {
|
|
63
|
+
if (getTile) {
|
|
64
|
+
mapInstance().addTileLayer(layer);
|
|
65
|
+
layer.loadRasterTileData = function(tileInfo, callback) {
|
|
66
|
+
const key = this.getTileKey(tileInfo);
|
|
67
|
+
const handleImageLoad = (image) => {
|
|
68
|
+
image.tileInfo = tileInfo;
|
|
69
|
+
callback && callback(image, key);
|
|
70
|
+
};
|
|
71
|
+
const handleError = () => callback && callback(null, key);
|
|
72
|
+
getTile(tileInfo, (img) => {
|
|
73
|
+
if (typeof img === "string" || img instanceof HTMLCanvasElement) {
|
|
74
|
+
const image = new Image();
|
|
75
|
+
image.crossOrigin = "anonymous";
|
|
76
|
+
image.onload = () => handleImageLoad(image);
|
|
77
|
+
image.onerror = handleError;
|
|
78
|
+
image.src = typeof img === "string" ? img : img.toDataURL();
|
|
79
|
+
} else if (img instanceof HTMLImageElement) {
|
|
80
|
+
handleImageLoad(img);
|
|
81
|
+
} else {
|
|
82
|
+
handleError();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
mapInstance().addTileLayer(layer);
|
|
88
|
+
}
|
|
49
89
|
}
|
|
50
|
-
|
|
51
|
-
getTile
|
|
52
|
-
} = _a, retProps = __rest(_a, ["getTile"]);
|
|
53
|
-
layer = new BMapGL.XYZLayer(retProps);
|
|
54
|
-
addTileLayer(layer);
|
|
90
|
+
startWatchProps();
|
|
55
91
|
};
|
|
56
|
-
|
|
57
|
-
watch(() => props.visible, (n) => layer && (n ? addTileLayer(layer) : removeTileLayer(layer)));
|
|
58
|
-
watch(() => props.options, () => createLayer());
|
|
92
|
+
init();
|
|
59
93
|
onUnmounted(() => {
|
|
60
94
|
if (layer) {
|
|
61
95
|
mapInstance().removeTileLayer(layer);
|