Coder Social home page Coder Social logo

gnijuohz / echarts-leaflet Goto Github PK

View Code? Open in Web Editor NEW
128.0 9.0 65.0 882 KB

ECharts extension for visualizing data on leaftlet maps

Home Page: https://www.jing-zhou.xyz/echarts-leaflet/example/leaflet-multiple-layers.html

License: MIT License

HTML 40.85% JavaScript 59.15%

echarts-leaflet's Introduction

ECharts leaflet extension

Build Status

Install

npm i echarts-leaflet

Usage

There are two ways to use this extension, the two examples in the example folder demonstrate each approach.

Use it directly through the script tag

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" crossorigin="" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.4/echarts-en.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
<script src="../dist/echarts-leaflet.js"></script>

See this example.

Use it as ES Module

import echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/scatter';
import 'echarts/lib/chart/effectScatter';

import 'echarts-leaflet';

See this example. To run it, use parcel leaflet-single-layer.html. The usage of parcel can be found here.

ECharts Option

You can use one or more tile layers via the tiles option. It's an array of layers.

The default tile layer uses http://{s}.tile.osm.org/{z}/{x}/{y}.png

option = {
  leaflet: {
      center: [120.13066322374, 30.240018034923],
      zoom: 3,
      roam: true,
      tiles: [{
        label: 'OpenStreetMap',
        urlTemplate: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
        options: {
          attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
        }
      }]
  },
  series: [{
    coordinateSystem: 'leaflet',
  }]
}

Specify multiple layers. You can choose a base layer to use via the layer control.

{
  layerControl: {
    position: 'topleft'
  },
  tiles: [{
    label: '天地图',
    urlTemplate: 'http://t2.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}',
    options: {
      attribution: 'tianditu.com'
    }
  }, {
    label: 'Open Street Map',
    urlTemplate: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
    options: {
      attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
    }
  }]
}

If you don't specify a label for a tile, it won't show up in the layer control. Therefore the following option will add two base layers to the map and there is no way to switch between them.

{
  layerControl: {
    position: 'topleft'
  },
  tiles: [{
    urlTemplate: 'http://t2.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}',
    options: {
      attribution: 'tianditu.com'
    }
  }, {
    urlTemplate: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
    options: {
      attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
    }
  }]
}

Demo

Build

  • yarn install
  • rollup --config

Contributors

License

MIT

echarts-leaflet's People

Contributors

gnijuohz avatar kutugu avatar poyoman39 avatar ultramanweilai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

echarts-leaflet's Issues

about Option&API

  1. How to use this? Not limited to your ECharts Option. It's better to list Option and API like echarts documentation.
  2. Your Demo link cannot be accessed.
  3. I hope you keep improving and look forward to new features.

Bug using the brush-mode

Current behaviour

Using the brush-mode with leaflet is currently not possible, as the map always is moved when dragging.

Expected behaviour

The map is not moved, when one uses the brush

Idea for implementation

I was wondering if one could listen to the brush and brushEnd events from echarts to deactivate the dragging from leaflet

I tried to implement it today, but I didn't succeed yet. @gnijuohz, do you have an idea how to implement it?

Thanks for your awesome work!

How can I get L in order to set bounds?

I want to set bounds and making map bounce back if moved away. I can get _map through this.echart.getModel().getComponent('leaflet').__map, but how can I get L to setMaxBounds().

I can set bounds using Leaflet library by using below code :
const southWest = Leaflet.latLng(-89.98155760646617, -180),
northEast = Leaflet.latLng(89.99346179538875, 180);
const bounds = Leaflet.latLngBounds(southWest, northEast);
map.setMaxBounds(bounds);

How can I achieve the same thing using 'echarts-leaflet'? Thanks in advance for any help.

如何能得到L?

您好 现在通过 this.chart.getModel().getComponent('leaflet').__map 我已经能得到_map,请问如何能得到L,用来绘制另一层geojson数据。谢谢!!!!!

does not match the corresponding path on disk `Leaflet.js`

Hi,
I am trying use this library on react.But i get error the following error:

Module not found: `/Users/admin/Projects/DashboardBootstrap/node_modules/leaflet/src/leaflet.js` does not match the corresponding path on disk `Leaflet.js`.

I've detected the cause of the error. echarts-leaflet is imported from leaflet library as leaft/src/leaflet if you can update to echarts-leaflet.js file as follows it is fixed this error for react-scripts.

  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('echarts/lib/echarts'), require('leaflet/src/Leaflet')) :

Wron coordinate

When the map has different coordinates than the Chinese, the point appears in wrong coordinates
bug

The cache of zoom event -- variable's name bug

My god ! 😭
There's a bug of zoom cache's variable name -- this._oldZoomEndHandler, which should be this._oldZoomHandler at here.
It caused my other zoom events to be unusable. I even thought it was a problem of coordinate transformation. It trapped me for a few days. I found it after reading the source code for a long time . . .
And I suggest you add if conditional statements before deleting the listen event, so as not to affect other layers.

geoJSON support

I'm trying to use this plugin with the series of type 'map' in echarts. I have a geojson file that I can register with echarts. I know need to draw that geojson over the leaflet tile layer and have the ability to roam. Does this library support this use case, or am I limited to using lat/long points using the scatter series?

Using a visualMap

I've been trying to display a visualMap component by adding the visualMap property to the chart's option object. Unfortunately, this does not display the visualMap. For instance removing the color configuration of the series and adding the following property to the option object in ./example/single-layer.js

  visualMap: {
    min: 0,
    max: 300,
    calculable: true,
    inRange: {
        color: ['#50a3ba', '#eac736', '#d94e5d']
    },
    textStyle: {
        color: '#fff'
    },
    dimension: 2,
    seriesIndex: 1
  }

does not lead to the visualMap display like in the example here https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-map.

Is there any way to add a VisualMap on Maps displayed through echarts-leaflet? Thanks in advance for any help.

请教

你好,我按照你的示例来做,经纬度是美国(国外的)的就会跑到南极去,如下图
image

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.