Code Monkey home page Code Monkey logo

Comments (2)

bbecquet avatar bbecquet commented on August 12, 2024 1

Hi, and thanks for using my plugin!

I hoped to find a way to have rotation on markers without any new class, as the plugin already relies on many, but maybe I shouldn't care, and your solution is really simple and elegant.

Can I add your L.MarkerWithAngle class to the source, and provide a boolean option like rotate on L.Symbol.Marker, to choose it instead of the simple L.Marker class? I think it would be a good fix to this issue.
Or maybe you want to contribute a pull-request yourself?

About your question, it is complex matter, as nothing is really "wrong" technically speaking. The angle at each point seems to be properly computed, but on complex polylines it may result in overlaping symbols or worse, like on your 1st example, symbols that seem wrong although they indicate the right direction at the local level.

I don't see any easy solution right now, mainly because the drawing process is independant from the one computing points on the polyline.
It is somewhat linked to the bug #3 about dashes, although in that case I see quite well how to do it at the drawing step...

Can you elaborate on your idea of interpolating the points please?

I will think on the problem, thanks for pointing it!

from leaflet.polylinedecorator.

gpbl avatar gpbl commented on August 12, 2024

Hello!

I'm trying to use your nice plugin for adding direction arrows to a polyline.

Marker's rotation is planned in a "future" milestone: Leaflet/Leaflet#143
Meanwhile I've extended the L.Marker in this way:

L.MarkerWithAngle = L.Marker.extend({
    options: {
        angle: 0
    },
    _setPos: function (pos) {
        L.Marker.prototype._setPos.call(this, pos);
        this._icon.style.MozTransform = this._icon.style.WebkitTransform + ' rotate(' + this.options.angle + 'deg)';
        this._icon.style.MsTransform = this._icon.style.WebkitTransform + ' rotate(' + this.options.angle + 'deg)';
        this._icon.style.OTransform = this._icon.style.WebkitTransform + ' rotate(' + this.options.angle + 'deg)';
        this._icon.style.WebkitTransform = this._icon.style.WebkitTransform + ' rotate(' + this.options.angle + 'deg)';
    }
});

and added a new Symbol using a DivIcon for the marker using a plain-text rightwards arrow as html.

L.Symbol.Arrow = L.Class.extend({
    buildSymbol: function (directionPoint, latLngs, map, index, total) {
        var marker = new L.MarkerWithAngle(directionPoint.latLng, {
            clickable: false,
            draggable: false,
            icon: new L.DivIcon({
                html: 'β†’'
            }),
            angle: directionPoint.heading - 90 // since icon's is a rightwards arrow
        });
        return marker;
    }
});

(You may need this CSS)

.leaflet-marker-icon.leaflet-div-icon {
    background: none;
    border: 0;
    color: blue;
    font-size: 18px;
}

While it works great for straight polylines, there're cases when it doesn't work (see attach), usually when there are curves. What would you do? The basic idea would just to not draw the decoration when it's "wrong", but also wecan interpolate the points in some way...

Screen Shot 2013-01-29 at 4 29 09 PM
Screen Shot 2013-01-29 at 4 27 00 PM

from leaflet.polylinedecorator.

Related Issues (20)

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.