Created
March 10, 2022 12:08
-
-
Save IBue/c85bde4ee8a2c4bec5e8036fcee95ba9 to your computer and use it in GitHub Desktop.
ember-leaflet in tabs and IntersectionObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { action } from "@ember/object"; | |
import { schedule } from '@ember/runloop'; | |
import { htmlSafe } from '@ember/string'; | |
export default class extends Component { | |
lat = 51.92; | |
long = 35.68; | |
zoom = 3; | |
licenseAttribution = htmlSafe( | |
'<a href="https://miguelcobain.github.io/ember-leaflet/"><em>ember-leaflet</em></a> | © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> | © <a href="https://carto.com/about-carto/">light_all</a>' | |
); | |
map = null; | |
mapElem = null; | |
visibilityObserver = null; | |
invalidateSize() { | |
schedule('afterRender', () => { | |
this.map?.invalidateSize?.(); | |
}); | |
} | |
willDestroy() { | |
super.willDestroy(); | |
this.visibilityObserver.disconnect(); | |
this.visibilityObserver = null; | |
this.map = null; | |
this.mapElem = null; | |
} | |
@action | |
onMapLoad(event) { | |
this.map = event.target; | |
this.mapElem = event.target.getContainer(); | |
if (this.mapElem) { | |
this.visibilityObserver = new window.IntersectionObserver((entries) => { | |
if (entries?.[0].isIntersecting) { | |
this.invalidateSize(); | |
} | |
}); | |
this.visibilityObserver.observe(this.mapElem); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'ember-leaflet in tabs & IntersectionObserver'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.leaflet-container { | |
height: 300px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": false | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-bootstrap": "3.1.4", | |
"ember-leaflet": "4.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment