GithubHelp home page GithubHelp logo

bnolan001 / angular-ivy-leafletjs-map-popup Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 14 KB

Created with StackBlitz ⚡️

Home Page: https://stackblitz.com/edit/angular-ivy-leafletjs-map-popup

CSS 2.25% HTML 4.42% TypeScript 93.33%

angular-ivy-leafletjs-map-popup's Introduction

angular-ivy-leafletjs-map-popup

View on StackBlitz ⚡️

About

Demonstrates how to add a custom popup to location markers on a Leaflet map using an Angular.io Component.. A blog post going over the steps can be found at -----

To run this project locally clone the repository then run.

npm install

ng serve

angular-ivy-leafletjs-map-popup's People

Contributors

bnolan001 avatar

Watchers

 avatar  avatar

angular-ivy-leafletjs-map-popup's Issues

Popup pointer doesn't align with marker

I am using your function to inject my PopupComponent into the Leaflet popup and the popup should display a table with the data for that specific layer. However, the popup does not adjust to the table size:

But when I do set the width for the leaflet-popup-content:

.tmo_popup .leaflet-popup-content {
	margin: 0px !important;
	width: 100% !important;
}

the popup does not appear right above the point and gets shifted to the right:

The way I am displaying the popup is the following (in my popup service):

let popupOptions = {
   className: "popup",
   maxWidth: 250 // This doesn't do anything for some reason
};

L.popup(popupOptions)
   .setLatLng(latLng)
   .setContent(this.compilePopup(PopupComponent))
   .openOn(map);

You can see that I am using the this.compilePopup(PopupComponent) function to inject the PopupComponent into the Leaflet popup and the this.compile function looks exactly the same as what you have in your file. This is how my PopupComponent HTML looks like:

<ng-template>
    <table class="table table-striped table-bordered table-condensed table-hover">
        <tr>
            <th *ngFor="let col of columns;">
                {{columns}}
            </th>
        </tr>
        <tr>
            <td *ngFor="let col of columns;">
                {{columnDetails[columns]}}
            </td>
        </tr>
    </table>
</ng-template>

popup-component.ts:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-popup',
  templateUrl: './popup.component.html',
  styleUrls: ['./popup.component.css']
})
export class PopupComponent implements OnInit {
  columnDetails: any;
  columns: Array<string> = ["Column 1", "Column 2", "Column 3"];


  constructor(
    private popupService: PopupService,
    private popupStore: PopupStore
  ) {
    this.columnDetails= this.popupService.columnDetails;

  }
}

and the way I am initializing my Leaflet map is in my map-component.ts where I have:

  options: MapOptions = {
    center: latLng(47.5786262, -122.1654623),
    minZoom: 4,
    layers: [
      L.gridLayer.googleMutant({
        type: 'roadmap', // valid values are 'roadmap', 'satellite', 'terrain' and 'hybrid'
        styles: [
          {
            featureType: "poi.business",
            elementType: "labels",
            stylers:
              [
                {
                  visibility: "simplified"
                }
              ]
          }
        ]
      }),
    ],
    zoom: 5,
    zoomControl: false
  };

map-component.html:

<div id="map"
    leaflet [leafletOptions]="options"
    (leafletMapReady)="onMapReady($event)"
    (leafletMapMove)="onMapMove($event)"
    (leafletMapZoom)="onMapZoom($event)"
    (leafletClick)="onMapClick($event)">
</div>

Do you know how I can get it so the popup adjust to my table size AND that the popup is right above the marker that I click on? I'm pretty sure the UI is like this because I am injecting the PopupComponent into the Leaflet popup. Any ideas on how to resolve this issue? Any help is greatly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.