GithubHelp home page GithubHelp logo

lipton-ice-tea / leaflet-canvas-markers Goto Github PK

View Code? Open in Web Editor NEW
55.0 1.0 18.0 30 KB

Adding all images to one canvas, together with the base L.CircleMarker! And you can create a direction arrow just by pointing to the previous waypoint.

Home Page: https://www.npmjs.com/package/leaflet-canvas-markers

JavaScript 100.00%

leaflet-canvas-markers's Introduction

一 A JavaScript Integrated Leaflet Map API

Leaflet-canvas-markers

Adding all images to one canvas, together with the base L.CircleMarker! And you can create a direction arrow just by pointing to the previous waypoint.

Demo

Live Demo >>

Base Usage

const map = L.map('map', {preferCanvas: true}).setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);

L.canvasMarker(L.latLng(51.495, -0.06), {
    radius: 20,
    img: {
        url: 'icon.png',    //image link
        size: [40, 40],     //image size ( default [40, 40] )
        rotate: 10,         //image base rotate ( default 0 )
        offset: { x: 0, y: 0 }, //image offset ( default { x: 0, y: 0 } )
    },
}).addTo(map);

Direction Arrow

You can specify the previous point (prevLatlng: latlng). The picture will automatically show the direction of movement.

const map = L.map('map', {preferCanvas: true}).setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);

L.canvasMarker(L.latLng(51.495, -0.06), {
    radius: 20,
    prevLatlng: L.latLng(51.503, -0.09),    //previous point
    img: {
        url: 'arrow.png',
        size: [40, 40],
        rotate: 0,
    },
}).addTo(map);

Options

Option Type Description
img Object Image properties
prevLatlng LatLng The coordinates of the previous point. If indicated - The image automatically shows the direction

Options img

Option Type Default Description
url String Image link
size Array [40, 40] Image size in map
rotate Number 0 Image rotate in map
offset Object { x: 0, y: 0 } Image offset in Canvas

leaflet-canvas-markers's People

Contributors

lipton-ice-tea 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

Watchers

 avatar

leaflet-canvas-markers's Issues

setting className and zIndexOffset

would be nice to be able to set className on either the image or the marker to be able to use css on it

currently both className and zIndexOffset dont do anything sadly

this._renderer._updateImg is not a function

I get this error:

this._renderer._updateImg is not a function

when set regular png image.

here is my code:

let map = L.map("map", {
  center: [0, 0],
  zoom: 5
});

new L.tileLayer("http://tiles.maps.sputnik.ru/{z}/{x}/{y}.png").addTo(map);

let marker = L.canvasMarker(L.latLng(0, 0), {
  radius: 20,
  img: {
    url: 'icon.png',
    // url: "https://cdn2.iconfinder.com/data/icons/wsd-map-markers-1/512/wsd_markers_45-512.png", //image link
    size: [40, 40], //image size ( default [40, 40] )
    rotate: 0, //image base rotate ( default 0 )
    offset: { x: 0, y: 0 } //image offset ( default { x: 0, y: 0 } )
  }
}).addTo(map);

and here is sandbox online project playground:
https://codesandbox.io/s/prod-moon-xvnj8

I can't run this plugin even on my local html-directory.
Do you have any idea what can be wrong?

Clicking on the image (not directly on the coordinates) does not work

When I use classic L.marker(... clicking is possible anywhere on the entire image (and not outside of it). When I use L.canvasMarker(... it behaves differently. Clicking is possible in a circle around the coordinate of the point (regardless of the location - e.g. rotation or offset - of the image) But for example, when the image is large and just to the right of the point coordinate, it is not possible to click anywhere in the area of this image.
My usage would be:

  • I have two different points on almost identical coordinates
  • for one I have an image on the left and for the other on the right
  • by clicking on one or the other image, I can display a popup of the relevant point

Thanks for the responses or advice. And sorry for my bad english

zIndexOffset

Thanks for this awesome package - it's improved performance on my map significantly but I've lost the ability to sort markers using zIndexOffset. Is it possible for this to be added back?

iconAnchor

What exactly is the intended use of the offset: {x: 0, y: 0} property? wouldn't it be better to use iconAnchor: [0, 0] like when styling the icon with L.marker(... ? I've tried using offset with different values, and it works, but it's not very intuitive. But I came to problem when I combined offset with rotate - then the possibility of using offset is not very possible

Thanks for the responses or advice. And sorry for my bad english

Color of svg is discarded. How can I use svg with filled color?

I am using this canvas marker plugin to draw arrows with direction on canvas for better performance.
Everything works fine except that I am seeing the arrow marker as black even though my svg is red.

Here's my svg content for your reference.

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 172.5 172.4" style="enable-background:new 0 0 172.5 172.4;" xml:space="preserve">
<path d="M89.4,165.2l-20.9-61.2L7.3,83c-9.4-3.2-9.8-16.3-0.6-20.1l151-62.1c8.8-3.6,17.6,5.2,14,14l-62.1,150.9C105.7,174.9,92.6,174.5,89.4,165.2L89.4,165.2z" fill="red" />
</svg>

I am not sure how I can change the color from default black to red.
Thanks in advance!

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.