spatialillusions / milsymbol

Military Symbols in JavaScript
www.spatialillusions.com/milsymbol
MIT License
531 stars 132 forks source link

Hi, How can we change the color of direction arrow? #258

Closed ajinra020307 closed 1 year ago

MattShawPhoto commented 2 years ago

It's not possible to directly change the colour of a single part within milsymbol because the draw instruction for it uses the colour specified for the rest of the symbol frame parts.

https://github.com/spatialillusions/milsymbol/blob/1c17e57282f505fb9ebcd42e04ef2ab1e1b102e6/src/symbolfunctions/directionarrow.js#L32

If you really need to change the colour of the direction arrow, you could instead create a custom symbol part instead. Essentially all you would have to do is copy the logic from src/symbolfunctions/directionarrow.js and then add the relevant options when creating your symbol:

Pseudo code example:


var custDirArrow = function (symbol, colour, dir) {
 // Implementation goes here...
}

ms.addSymbolPart(function () {
        var drawArray1 = []; 
        var drawArray2 = [];

       if (this.options.custDirArrowColor !== undefined && this.options.custDirArrowDir) {
           drawArray2.push(custDirArrow(this, this.options.custDirArrowColor, this.options.custDirArrowDir));
       }

        return {
            pre: drawArray1,
            post: drawArray2,
        };
})

var symb = new ms.Symbol("SFG*UCIZ--*****", {
    dtg: "30140000ZSEP97",
    location: "0900000.0E570306.0N",
    size: 35,
    custDirArrowColor:"#FF0000",
    custDirArrowDir:"290"
});

I have provided an example of a similar solution here https://github.com/spatialillusions/milsymbol/issues/249#issuecomment-931138101

Hope this helps