Skip to content

Instantly share code, notes, and snippets.

@miguelcobain
Created January 22, 2021 03:53
Show Gist options
  • Save miguelcobain/65e696c788b9a0b2433e110e6d32873f to your computer and use it in GitHub Desktop.
Save miguelcobain/65e696c788b9a0b2433e110e6d32873f to your computer and use it in GitHub Desktop.
New Twiddle
import Controller from '@ember/controller';
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@tracked lat = 38.77;
@tracked long = -100.79;
@tracked zoom = 3;
@action
onMapLoad(event) {
this.map = event.target;
this.invalidateSize();
}
@action
onTabChange(event) {
this.invalidateSize();
}
invalidateSize() {
// ember-bootstrap tabs do not have any event
// that fires when the tab is finished transitioning
// so we have to tell leaflet to
// recalculate its size after X ms, ideally equal to the
// css transition duration
setTimeout(() => {
this.map?.invalidateSize();
}, 200);
}
}
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.leaflet-container {
height: 300px;
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
{{outlet}}
<BsTab @onChange={{this.onTabChange}} as |tab|>
<tab.pane @title="Tab 1">
<LeafletMap class="esri-map" @lat={{this.lat}} @lng={{this.long}} @zoom={{this.zoom}} @onLoad={{this.onMapLoad}} as |layers|>
<layers.tile @url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"/>
</LeafletMap>
</tab.pane>
<tab.pane @title="Tab 2">
<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>
</tab.pane>
</BsTab>
<br>
<LeafletMap class="esri-map" @lat={{this.lat}} @lng={{this.long}} @zoom={{this.zoom}} as |layers|>
<layers.tile @url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"/>
</LeafletMap>
<br>
<br>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"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",
"leaflet": "1.7.1",
"bootstrap": "4.5.3"
},
"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