question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken Leaflet 1.0.2 map for basic ionic2 app

See original GitHub issue

LeafletJS - 1.0.2 Chrome 54.0.2840.98 / Safari 10.0.1 (12602.2.14.0.7) Mac Sierra 10.12.1

Expecting to see a good map, getting weird tile assembly , incoherent, with gaps between tiles and and shuffled around tiles. I observed it with all map sources I tried.

map

I added a new page to my ionic2 blank page project

ionic start myBlank blank --v2 
cd myBlank

npm install leaflet --save
npm install @types/leaflet --save

ionic g page custom-view

Code in two new files custom-view.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as Leaflet from 'leaflet';

/*
  Generated class for the CustomView page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'custom-view',
  templateUrl: 'custom-view.html'
})
export class CustomViewPage {

  private map: any;

  constructor(public navCtrl: NavController) {}

  ionViewDidLoad() {
    this.loadMap();
  }

  loadMap(){
    this.map = Leaflet.map('map').setView([32, -120], 14);
    Leaflet.tileLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", {attribution:""}).addTo(this.map);
  }

}
custom-view.html
<ion-header>

  <ion-navbar>
    <ion-title>custom-view</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
   <div id="map" style="width: 100%; height: 100%"></div>
</ion-content>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
auronsancommented, Nov 29, 2016

Oh I got the problem just need import css on your src/index.html

if not imported css will looks like this testrepov2

after I include it <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.2/dist/leaflet.css" />on src/index.html repro4s

0reactions
AIRUNGUcommented, Sep 27, 2018

<ion-app></ion-app>

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.2/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.0.2/dist/leaflet.js"></script>

The above code actually works, just make sure they are below the <ion-app></ion-app> tags

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet broken tiles with ionic - Stack Overflow
Ionic displays these broken tiles when loading a map. View. I've tried both loading bower and straight from Leaflet but nothing has changed....
Read more >
Ionic2 Leaflet remains blank in simulator - Ionic Forum
Hi there, I essentially copied this example to display LeafletJS maps with Ionic2. It works fine with ionic serve, but when I run...
Read more >
Untitled
A tiny, simple and fast heatmap plugin for Leaflet. ... Developing map applications in Contao with the modern Open Source Map library Leaflet...
Read more >
Isoline Mapping With HERE in an Ionic Framework ... - DZone
Building an Ionic Framework With HERE Maps Application ... code will be recycled from a previous tutorial that was centered around Leaflet, ...
Read more >
Untitled
I`m trying to make a Leaflet map with World Eckert IV projection using Proj4Lefalet. ... I am integrating Ionic App with OSM using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found