GithubHelp home page GithubHelp logo

weiyuc / vue2leaflet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vue-leaflet/vue2leaflet

0.0 1.0 0.0 5.77 MB

Vue 2 components for Leaflet maps

License: MIT License

JavaScript 39.19% Shell 0.99% Vue 59.71% TypeScript 0.11%

vue2leaflet's Introduction

Vue2Leaflet

Downloads Downloads Version License Gitter

Vue2Leaflet is a JavaScript library for the Vue framework that wraps Leaflet making it easy to create reactive maps.

Image of Map

Documentation

Go here to check out live examples and docs.

If you want to hack around, here is a JS Fiddle to get started

⚠️ Breaking changes from v0.x.x to v1.x.x ⚠️

A new major release v1.x.x is available and come with some breaking changes.

❗ Components names

As some component where conflicting with reserved name like Circle with SVG Circle, from v1.x.x all components are prefixed with L.

For example Marker component became LMarker (l-marker in template).

❗ Events names

Event handling have been simplified and are now mapped directly to Leaflet event.

For example Marker move event was 'l-move' and became simply 'move'.

✨ Leaflet Controls

v1.0.0 introduces Leaflet Controls you can now use them using LControlAttribution, LControlLayers, LControlScale and LControlZoom.

When adding LControlAttribution or LControlZoom to your template, remember to desactivate the default one by using LMap options:

{
  zoomControl: false,
  attributionControl: false
}

Otherwise you will end up with two zoom/attribution control.

How to install

$ npm install vue2-leaflet --save

For more detailed informations you can follow the Quick Start Guide

Leaflet Plugins

Leaflet plugins can easily work with Vue2Leaflet, if you want to use one I would recommand to look at the awesome work made by the community in the list below.

Vue2Leafet plugins:

If you have created a plugin and want it to be listed here, let me know :-).

Vue2Leaflet is only a wrapper for Leaflet. I want to keep it as simple as possible so I don't want to add any plugin support into this repo.

FAQ

My map and/or markers don't fully render. What gives?

Depending on your project setup, you may have to try different solutions.

To fix map rendering issues, it may help to import the Leaflet stylesheet within the script section of your Vue component.

In most cases, though, it is Webpack messing with Leaflet marker icons' paths, resulting in warnings or even errors. You can alleviate that by either unsetting/replacing the default paths (alternate solution) or using Webpack aliases.

How can I access the Leaflet map object?

First add a ref to the map

  <l-map ref="map" :zoom=13 :center="[47.413220, -1.219482]">
    ...
  </l-map>

Then in you JavaScript you can use mapObject which is Leaflet map instance :

this.$refs.map.mapObject;

Note: mapObject is not available directly in vue's mounted hook. You need to wrap the call to this.$refs.map in a nextTick call:

data: () => ({map: null}),
mounted () {
  // DON'T
  this.map = this.$refs.map.mapObject // doesn't work, this.map is null

  // DO
  this.$nextTick(() => {
    this.map = this.$refs.map.mapObject // work as expected
  })
},

This also work for any other component (Marker, Polyline, etc...)

How can I bind events of Vue2Leaflet components?

All event binding can be done to event with the same name as in leaflet documentation.

For example if you want to listen to Vue2Leaflet.LMarker move event.

<l-marker :lat-lng="[47.413220, -1.219482]" @move="doSomething"></l-marker>

Run code locally for contributors

# clone the repository
$ git clone [email protected]:KoRiGaN/Vue2Leaflet.git
$ cd Vue2Leaflet
# install dependencies and build vue2-leaflet
$ npm install
$ npm run build
# create a symlink for vue2-leaflet
$ npm link
$ cd examples
$ npm install
# create a symbolic link for vue2-leaflet in node_modules/
$ npm link vue2-leaflet
# serve with hot reload at localhost:8080
$ npm run dev

Go to http://localhost:8080/ to see running examples

NOTE: If you make changes to the library you should run 'npm run build' again in the root folder. The dev server should detect modification and reload the examples

Authors

Mickaël Bouchaud

Inspired by many map wrapper (google and leaflet) for many framework (React, Angular and Vue 1.0)

Contributors

Thanks goes to these wonderful people

License

This project is licensed under the MIT License - see the LICENSE file for details

vue2leaflet's People

Contributors

korigan avatar donnicojs avatar bezany avatar zuck avatar jericopulvera avatar jperelli avatar semeleven avatar mikeu avatar ktmud avatar katafrakt avatar eymaddis avatar strixy avatar snickell avatar naderio avatar jteppinette avatar dorianamouroux avatar cl3mm avatar disarticulate avatar harti avatar johallar avatar antixrist avatar nparley avatar omrihar avatar yarl avatar gitter-badger avatar rootman avatar slurmulon avatar itanka9 avatar kino90 avatar

Watchers

desperado avatar

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.