GithubHelp home page GithubHelp logo

vue3-demo-project's Introduction

vue-leaflet

Vue-leaflet, written and compatible with Vue 3!

This is a Beta version! And may yet be unstable! If you want to help, please reach out in an issue or on discord, or join the discussions.

What works

  • LCircle
  • LCircleMarker
  • LControl
  • LControlAttribution
  • LControlLayers
  • LControlScale
  • LControlZoom
  • LFeatureGroup
  • LGeoJson
  • LIcon
  • LImageOverlay
  • LMap
  • LMarker
  • LPolygon
  • LPolyline
  • LPopup
  • LRectangle
  • LTileLayer
  • LTooltip
  • LWmsTileLayer

Note that unlike the Vue 2 version, this library is fully compatible with SSR.

Installation

yarn add @vue-leaflet/vue-leaflet leaflet

or

npm i -D @vue-leaflet/vue-leaflet leaflet

Usage

Until the complete documentation is ready, please check the component playground examples or the demo project for usage with Vue 3. Most component props mimic the vanilla Leaflet options as closely as possible, and generally remain the same as in their Vue2Leaflet counterparts.

Quickstart

<template>
  <div style="height:600px; width:800px">
    <l-map ref="map" v-model:zoom="zoom" :center="[47.41322, -1.219482]">
      <l-tile-layer
        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        layer-type="base"
        name="OpenStreetMap"
      ></l-tile-layer>
    </l-map>
  </div>
</template>

<script>
import "leaflet/dist/leaflet.css";
import { LMap, LTileLayer } from "@vue-leaflet/vue-leaflet";

export default {
  components: {
    LMap,
    LTileLayer,
  },
  data() {
    return {
      zoom: 2,
    };
  },
};
</script>

<style></style>

Component playground

To see the component playground in action, clone this repo and run the local devserver, then visit http://127.0.0.1:5173,

git clone https://github.com/vue-leaflet/vue-leaflet.git
cd vue-leaflet
yarn
yarn dev

Server-side rendering (SSR)

Note that while the vue-leaflet library has the option of enabling SSR, Leaflet itself does not.

N.B. Using import L from "leaflet" or import { ... } from "leaflet" can lead to unexpected errors.

To provide server-side rendering and tree-shaking capabilities, vue-leaflet can be configured to use async imports from the Leaflet ESM, by disabling the useGlobalLeaflet option on the map component, <l-map :useGlobalLeaflet="false">.

This can lead to issues when importing additional methods from Leaflet, because the two instances of the Leaflet classes are technically no longer the same. See Issue 48 for more.

To avoid these issues, import any Leaflet methods asynchronously in response to the LMap component's @ready event:

<template>
  <div style="height:600px; width:800px">
    <p>vue-leaflet SSR Demo</p>
    <l-map :useGlobalLeaflet="false">
      <l-geo-json :geojson="geojson" :options="geojsonOptions" />
    </l-map>
  </div>
</template>

<script>
// DON'T load Leaflet components here!
// Its CSS is needed though, if not imported elsewhere in your application.
import "leaflet/dist/leaflet.css"
import { LMap, LGeoJson } from "@vue-leaflet/vue-leaflet";

export default {
  components: {
    LMap,
    LGeoJson,
  },
  data() {
    return {
      geojson: {
        type: "FeatureCollection",
        features: [
          // ...
        ],
      },
      geojsonOptions: {
        // Options that don't rely on Leaflet methods.
      },
    };
  },
  async beforeMount() {
    // HERE is where to load Leaflet components!
    const { circleMarker } = await import("leaflet/dist/leaflet-src.esm");

    // And now the Leaflet circleMarker function can be used by the options:
    this.geojsonOptions.pointToLayer = (feature, latLng) =>
      circleMarker(latLng, { radius: 8 });
    this.mapIsReady = true;
  },
};
</script>

vue3-demo-project's People

Contributors

donnicojs 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

Watchers

 avatar  avatar  avatar

vue3-demo-project's Issues

zoom in zoom Out error : Attempted to load an infinite number of tiles

i use vue 3 , leaflet can be seen in the browser, but there is a problem when zooming in and zooming out an error appears like this

Uncaught Error: Attempted to load an infinite number of tiles
_update GridLayer.js:665
_setView GridLayer.js:574
_resetView GridLayer.js:530
fire Events.js:195
_move Map.js:1231
_resetView Map.js:1186
setView Map.js:206
setZoom Map.js:218
zoomOut Map.js:232
_zoomOut Control.Zoom.js:78
handler DomEvent.js:108
addOne DomEvent.js:135
on DomEvent.js:34
_createButton Control.Zoom.js:96
onAdd Control.Zoom.js:45
addTo Control.js:70
addControl Control.js:137
Control.Zoom.js:137
callInitHooks Class.js:81
initialize Map.js:156
NewClass Class.js:24
createMap

latest version doesn't work

Hi
the project uses old version into package.json

"@vue-leaflet/vue-leaflet": "^0.3.0",

If i try to update the component to latest version, the project doesn't work

Can you fix the problem ?

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.