是否可以在Folium地图中绘制带箭头的线条?

时间:2016-08-23 05:47:49

标签: python maps jupyter-notebook folium

我在Jupyter Notebook Server 4.2.1上使用Python 2.7.11运行Folium 0.2.1'

我正在尝试在地图上绘制线条,这些线条有一个箭头来传达方向

import folium

#DFW, LGA coordinates
coordinates=[(32.900908, -97.040335),(40.768571, -73.861603)]

m = folium.Map(location=[32.900908, -97.040335], zoom_start=4)

#line going from dfw to lga
aline=folium.PolyLine(locations=coordinates,weight=2,color = 'blue')
m.add_children(aline)

enter image description here 有没有办法在线上添加箭头?

1 个答案:

答案 0 :(得分:2)

您可以使用常规多边形标记在终点绘制三角形...

import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';

@Component({
  selector: 'app-my-component',
  template: `
    <ngx-datatable
      class="bootstrap table table-striped"
      [rows]="rows"
      [columns]="columns"
      [columnMode]="'force'"
      [headerHeight]="50"
      [footerHeight]="50"
      [rowHeight]="'auto'"
      [externalPaging]="true"
      [externalSorting]="true"
      [count]="page.count"
      [offset]="page.offset"
      [limit]="page.limit"
      [sortType]="'single'"
      (page)="pageCallback($event)"
      (sort)="sortCallback($event)"
    ></ngx-datatable>
  `
})
export class MyComponent implements OnInit {
  page = {
    limit: 10,
    count: 0,
    offset: 0,
    orderBy: 'myColumn1',
    orderDir: 'desc'
  };

  rows: Object[];

  columns = [
    { name: 'myColumn1' },
    { name: 'myColumn2' },
    { name: 'myColumn3' },
  ];

  constructor(private httpClient: HttpClient) { }

  ngOnInit() {
    this.pageCallback({ offset: 0 });
  }

  /**
   * Called whenever the user changes page
   *
   * check: https://swimlane.gitbooks.io/ngx-datatable/content/api/table/outputs.html
   */
  pageCallback(pageInfo: { count?: number, pageSize?: number, limit?: number, offset?: number }) {
    this.page.offset = pageInfo.offset;
    this.reloadTable();
  }

  /**
   * Called whenever the user changes the sort order
   *
   * check: https://swimlane.gitbooks.io/ngx-datatable/content/api/table/outputs.html
   */
  sortCallback(sortInfo: { sorts: { dir: string, prop: string }[], column: {}, prevValue: string, newValue: string }) {
    // there will always be one "sort" object if "sortType" is set to "single"
    this.page.orderDir = sortInfo.sorts[0].dir;
    this.page.orderBy = sortInfo.sorts[0].prop;
    this.reloadTable();
  }

  /**
   * You will render the table once at the beginning in ngOnInit()
   * and then every time the page OR the sort order are changed
   */
  reloadTable() {

    // NOTE: those params key values depends on your API!
    const params = new HttpParams()
      .set('orderColumn', `${this.page.orderBy}`)
      .set('orderDir', `${this.page.orderDir}`)
      .set('pageNumber', `${this.page.offset}`)
      .set('pageSize', `${this.page.limit}`);

    this.httpClient.get(`http://www.your-api.com/path/resource`, { params })
      .subscribe((data) => {

        // NOTE: the format of the returned data depends on your API!
        this.page.count = data.count;
        this.rows = data.rows;
      });
  }
}

您必须使用一些三角法来计算三角形的旋转角度,使其指向正确的方向。任何此类标记的起始点都指向东方。