UNPKG

tdt-overlay-factory

Version:

天地图覆盖物工厂,通过vue组件直接生成天地图覆盖物类,支持vue2/vue3

122 lines (121 loc) 5.86 kB
const p = (o) => { const { defineComponent: s, createApp: h } = o; return { pointOverlayFactory: (i) => { const e = s(i); return T.Marker.extend({ initialize: function(t, n, l) { this.lnglat = t, this.props = n || {}, this._APP_ = null, this._MAP_ = null, this._DIV_ = null, this.setOptions(l), this.or = T.fq(t); }, onAdd: function(t) { this._APP_ = h(e, this.props), this._MAP_ = t, this._DIV_ = document.createElement("div"), this._DIV_.classList.add("extend-point-overlay-wrap"), this._APP_.mount(this._DIV_), this._MAP_.on("zoomend", this.update, this), this._MAP_.getPanes().overlayPane.appendChild(this._DIV_), this.update(this.lnglat); }, onRemove: function() { var t = this._DIV_.parentNode; this._MAP_.off("zoomend", this.update, this), t && (this._APP_.unmount(), t.removeChild(this._DIV_), this._MAP_ = null, this._DIV_ = null); }, setLngLat: function(t) { this.lnglat = t, this.update(); }, getLngLat: function() { return this.lnglat; }, setPos: function(t) { this.lnglat = this._MAP_.layerPointToLngLat(t), this.update(); }, update: function() { var t = this._MAP_.lngLatToLayerPoint(this.lnglat); this._DIV_.style.top = t.y + "px", this._DIV_.style.left = t.x + "px"; } }); }, blockOverlayFactory: (i) => { const e = s(i); return T.Overlay.extend({ initialize: function(t, n, l) { this._bounds = t, this.props = n || {}, this._APP_ = null, this._MAP_ = null, this._DIV_ = null, this.setOptions(l); }, onAdd: function(t) { this._APP_ = h(e, this.props), this._MAP_ = t, this._DIV_ = document.createElement("div"), this._DIV_.classList.add("extend-block-overlay-wrap"), this._APP_.mount(this._DIV_), this._MAP_.on("zoomend", this.update, this), this._MAP_.getPanes().overlayPane.appendChild(this._DIV_), this.update(this.lnglat); }, onRemove: function() { var t = this._DIV_.parentNode; this._MAP_.off("zoomend", this.update, this), t && (this._APP_.unmount(), t.removeChild(this._DIV_), this._MAP_ = null, this._DIV_ = null); }, update: function() { var t = this._MAP_.lngLatToLayerPoint(this._bounds.getNorthEast()), n = this._MAP_.lngLatToLayerPoint(this._bounds.getSouthWest()), l = Math.abs(t.x - n.x), r = Math.abs(t.y - n.y); this._DIV_.style.left = n.x + "px", this._DIV_.style.top = t.y + "px", this._DIV_.style.width = l + "px", this._DIV_.style.height = r + "px"; } }); } }; }, d = (o) => ({ pointOverlayFactory: (_) => { const a = o.extend(_); return T.Marker.extend({ initialize: function(i, e, t) { this.lnglat = i, this.props = e || {}, this._APP_ = null, this._MAP_ = null, this._DIV_ = null, this.setOptions(t), this.or = T.fq(i); }, onAdd: function(i) { this._APP_ = new a({ propsData: this.props }).$mount().$el, this._MAP_ = i, this._DIV_ = document.createElement("div"), this._DIV_.classList.add("extend-point-overlay-wrap"), this._DIV_.appendChild(this._APP_), this._MAP_.on("zoomend", this.update, this), this._MAP_.getPanes().overlayPane.appendChild(this._DIV_), this.update(this.lnglat); }, onRemove: function() { var i = this._DIV_.parentNode; this._MAP_.off("zoomend", this.update, this), i && (i.removeChild(this._DIV_), this._DIV_ = null, this._MAP_ = null); }, setLngLat: function(i) { this.lnglat = i, this.update(); }, getLngLat: function() { return this.lnglat; }, setPos: function(i) { this.lnglat = this._MAP_.layerPointToLngLat(i), this.update(); }, update: function() { var i = this._MAP_.lngLatToLayerPoint(this.lnglat); this._DIV_.style.top = i.y + "px", this._DIV_.style.left = i.x + "px"; } }); }, blockOverlayFactory: (_) => { const a = o.extend(_); return T.Overlay.extend({ initialize: function(i, e, t) { this._bounds = i, this.props = e || {}, this._APP_ = null, this._MAP_ = null, this._DIV_ = null, this.setOptions(t); }, onAdd: function(i) { this._APP_ = new a({ propsData: this.props }).$mount().$el, this._MAP_ = i, this._DIV_ = document.createElement("div"), this._DIV_.classList.add("extend-block-overlay-wrap"), this._DIV_.appendChild(this._APP_), this._MAP_.on("zoomend", this.update, this), this._MAP_.getPanes().overlayPane.appendChild(this._DIV_), this.update(this.lnglat); }, onRemove: function() { var i = this._DIV_.parentNode; this._MAP_.off("zoomend", this.update, this), i && (i.removeChild(this._DIV_), this._DIV_ = null, this._MAP_ = null); }, update: function() { var i = this._MAP_.lngLatToLayerPoint(this._bounds.getNorthEast()), e = this._MAP_.lngLatToLayerPoint(this._bounds.getSouthWest()), t = Math.abs(i.x - e.x), n = Math.abs(i.y - e.y); this._DIV_.style.left = e.x + "px", this._DIV_.style.top = i.y + "px", this._DIV_.style.width = t + "px", this._DIV_.style.height = n + "px"; } }); } }), u = { install(o, s) { s = s || o; let h = Number(s.version.split(".")[0]); if (h === 2) { console.log("\u5F53\u524D\u73AF\u5883Vue2"); const { pointOverlayFactory: _, blockOverlayFactory: a } = d(s); s.prototype.$pointOverlayFactory = _, s.prototype.$blockOverlayFactory = a; } else if (h === 3) { console.log("\u5F53\u524D\u73AF\u5883Vue3"); const { pointOverlayFactory: _, blockOverlayFactory: a } = p(s); o.provide("pointOverlayFactory", _), o.provide("blockOverlayFactory", a); } } }; export { u as default };