@draganfilipovic/confluence-map
Advanced tools
Comparing version 1.2.4 to 1.2.5
{ | ||
"name": "@draganfilipovic/confluence-map", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "embed OSM into Confluence pages", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
import { RouteController } from './route.js'; | ||
import { renderStyle } from './style.js'; | ||
import { config } from './config.js'; | ||
import { NS } from './ns.js'; | ||
@@ -9,13 +10,7 @@ export class RouteButtons extends HTMLElement { | ||
this.attachShadow({ mode: 'open' }); | ||
this.NS = this.bindNamespace(); | ||
this.RouteController = new RouteController(); | ||
} | ||
bindNamespace() { | ||
window.NC_CONFLUENCE_MAP = window.NC_CONFLUENCE_MAP || {}; | ||
return window.NC_CONFLUENCE_MAP; | ||
} | ||
get points() { | ||
return Object.values(this.NS.state) | ||
return Object.values(NS.state) | ||
.filter(item => item.active) | ||
@@ -22,0 +17,0 @@ .map(item => item?.location); |
import { LeafletMap } from './map.js'; | ||
import { Dependencies } from './dependencies.js'; | ||
import { renderStyle } from './style.js'; | ||
import { NS } from './ns.js'; | ||
@@ -9,3 +10,2 @@ export class MapElement extends HTMLElement { | ||
this.attachShadow({ mode: 'open' }); | ||
this.leafletMap = new LeafletMap(); | ||
} | ||
@@ -44,3 +44,6 @@ | ||
dependencies.load().then((data) => { | ||
this.leafletMap.init($map); | ||
// add plugin | ||
NS.L = window.L; | ||
// Map init | ||
NS.map = new LeafletMap($map, NS); | ||
}); | ||
@@ -47,0 +50,0 @@ } |
import { config } from './config.js'; | ||
import { NS } from './ns.js'; | ||
export class LeafletMap { | ||
constructor() { | ||
this.NS = this.bindNamespace(); | ||
constructor($map) { | ||
return this.init($map); | ||
} | ||
bindNamespace() { | ||
window.NC_CONFLUENCE_MAP = window.NC_CONFLUENCE_MAP || {}; | ||
return window.NC_CONFLUENCE_MAP; | ||
} | ||
init($map) { | ||
const map = this.initMap($map, NS.config.initialCenter, NS.config.defaultZoom); | ||
this.addTiles(map); | ||
this.addMarkers(map, NS.state); | ||
init($map) { | ||
this.NS.L = window.L; | ||
this.NS.map = this.initMap($map, this.NS.config.initialCenter, this.NS.config.defaultZoom); | ||
this.addTiles(this.NS.map); | ||
this.addMarkers(this.NS.map, this.NS.state); | ||
return map; | ||
} | ||
initMap($el, center, zoom) { | ||
return new this.NS.L.map($el, { | ||
return new NS.L.map($el, { | ||
center, | ||
@@ -28,3 +25,3 @@ zoom | ||
addTiles(map) { | ||
this.NS.L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
NS.L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
@@ -36,5 +33,5 @@ attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' | ||
addMarkers(map, state) { | ||
this.NS.L.Icon.Default.imagePath = `${config.LEAFLET.PATH}/images/`; | ||
NS.L.Icon.Default.imagePath = `${config.LEAFLET.PATH}/images/`; | ||
Object.values(state).forEach(({ location, label }) => { | ||
const marker = this.NS.L.marker(location); | ||
const marker = NS.L.marker(location); | ||
marker.bindPopup(label).openPopup(); | ||
@@ -41,0 +38,0 @@ marker.addTo(map); |
@@ -0,11 +1,8 @@ | ||
import { NS } from './ns.js'; | ||
export class RouteController { | ||
constructor() { | ||
this.routingControl = null; | ||
this.NS = this.bindNamespace(); | ||
this.NS = NS; | ||
} | ||
bindNamespace() { | ||
window.NC_CONFLUENCE_MAP = window.NC_CONFLUENCE_MAP || {}; | ||
return window.NC_CONFLUENCE_MAP; | ||
} | ||
addRoutingControl(waypoints) { | ||
@@ -15,7 +12,7 @@ this.removeRoutingControl(); | ||
this.routingControl = L.Routing.control({ | ||
this.routingControl = NS.L.Routing.control({ | ||
waypoints, | ||
routeWhileDragging: true | ||
}).addTo(this.NS.map); | ||
L.Routing.Itinerary.hide(); | ||
}).addTo(NS.map); | ||
NS.L.Routing.Itinerary.hide(); | ||
} | ||
@@ -37,6 +34,6 @@ | ||
addMultiRoutingControlPart(waypoints, i = 0) { | ||
this.multiRoutingControl[i] = L.Routing.control({ | ||
this.multiRoutingControl[i] = NS.L.Routing.control({ | ||
waypoints, | ||
routeWhileDragging: true | ||
}).addTo(this.NS.map); | ||
}).addTo(NS.map); | ||
} | ||
@@ -47,3 +44,3 @@ | ||
Object.values(this.multiRoutingControl).map(control => { | ||
this.NS.map.removeControl(control); | ||
NS.map.removeControl(control); | ||
}) | ||
@@ -56,3 +53,3 @@ this.multiRoutingControl = null; | ||
if (this.routingControl) { | ||
this.NS.map.removeControl(this.routingControl); | ||
NS.map.removeControl(this.routingControl); | ||
this.routingControl = null; | ||
@@ -66,3 +63,3 @@ } | ||
return points.map(coord => { | ||
return L.latLng(coord[0], coord[1]) | ||
return NS.L.latLng(coord[0], coord[1]) | ||
}); | ||
@@ -86,12 +83,12 @@ } | ||
async zoomToCenter(map, state) { | ||
const points = Object.values(state).map(({ location }) => location); | ||
const bounds = new this.NS.L.LatLngBounds(points); | ||
await map.fitBounds(bounds); | ||
async zoomToCenter() { | ||
const points = Object.values(NS.state).map(({ location }) => location); | ||
const bounds = new NS.L.LatLngBounds(points); | ||
await NS.map.fitBounds(bounds); | ||
} | ||
async getCenter() { | ||
await this.zoomToCenter(this.NS.map, this.NS.state); | ||
return this.NS.map.getCenter(); | ||
await this.zoomToCenter(); | ||
return NS.map.getCenter(); | ||
} | ||
} |
@@ -11,11 +11,4 @@ import { renderStyle } from './style.js'; | ||
} | ||
this._state = {}; | ||
this.NS = this.bindNamespace(); | ||
} | ||
bindNamespace() { | ||
window.NC_CONFLUENCE_MAP = window.NC_CONFLUENCE_MAP || {}; | ||
return window.NC_CONFLUENCE_MAP; | ||
} | ||
init() { | ||
@@ -27,4 +20,3 @@ this.elements = this.getElements(); | ||
this.NS.state = this.state; | ||
this.NS.config = this.config; | ||
NS.config = this.config; | ||
@@ -42,14 +34,2 @@ renderStyle(document.head, ` | ||
get state() { | ||
return this._state; | ||
} | ||
updateState(key, data, field) { | ||
if (field) { | ||
this._state[key][field] = data; | ||
} else { | ||
this._state[key] = data; | ||
} | ||
} | ||
getElements() { | ||
@@ -70,3 +50,3 @@ return { | ||
$configRow.addEventListener('click', () => { | ||
this.NS.map.setView(initialCenter, defaultZoom); | ||
NS.map.setView(initialCenter, defaultZoom); | ||
}); | ||
@@ -123,3 +103,6 @@ | ||
const { id, active } = this.getPointData($point); | ||
this.updateState(id, { label, location, active }); | ||
NS.state = ({ | ||
id, | ||
data: { label, location, active } | ||
}); | ||
}); | ||
@@ -139,7 +122,11 @@ } | ||
const { id, active } = this.getPointData($point); | ||
this.updateState(id, active, 'active'); | ||
NS.state = ({ | ||
id, | ||
data: active, | ||
filed: 'active' | ||
}); | ||
}); | ||
$colLabel.addEventListener('click', () => { | ||
this.NS.map.setView(location, this.config.locationZoom); | ||
NS.map.setView(location, this.config.locationZoom); | ||
}); | ||
@@ -146,0 +133,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
432
43614