1

I want to let Marker to other style.

This is my code:

<script>   

    var url = 'leaflet/WGS84.kml';
    doSomething(url);

    function doSomething(url) {
        var runlayer = omnivore.kml('leaflet/WGS84.kml').on('ready', function (layer) {
            this.eachLayer(function (value) {
            });
            var a0 = runlayer.toGeoJSON().features.length;
            var array = [], array2 = [];
            var array1 = [], array3 = [];

            for (var i = 0; i < a0; i++) {
                if (runlayer.toGeoJSON().features[i].geometry.hasOwnProperty("coordinates")) {
                    var a1 = runlayer.toGeoJSON().features[i].geometry.coordinates.length;
                    //for (var j = 0; j < a1; j++) {
                    array2 = [runlayer.toGeoJSON().features[i].geometry.coordinates[1], runlayer.toGeoJSON().features[i].geometry.coordinates[0]];
                    array.push(array2);
                    //}
                    var myMarker = new L.marker(array2).addTo(map);
                    array = [];
                }
                else {
                    /*
                    var a2 = runlayer.toGeoJSON().features[i].geometry.geometries.length;
                    for (var k = 0; k < a2; k++) {
                        var a3 = runlayer.toGeoJSON().features[i].geometry.geometries[k].coordinates.length;
                        for (var l = 0; l < a3; l++) {
                            array3 = [runlayer.toGeoJSON().features[i].geometry.geometries[k].coordinates[l][1], runlayer.toGeoJSON().features[i].geometry.geometries[k].coordinates[l][0]];
                            array1.push(array3);
                        }
                        var polyline = L.polyline(array, { color: 'red' }).addTo(map);
                        array1 = [];  
                     */
                }
            }
        });
    }

</script>

closed as unclear what you're asking by Ian Turton Aug 29 at 8:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What exactly does it mean 'This line can't work'? What is the content of array when you try to add new marker? – TomazicM Aug 29 at 7:46
  • Oh,I found the problem,"var myMarker = new L.Marker(array2).addTo(map);" This is right code. And I want to know how can let Marker convert to other style? – wei shiuan Aug 29 at 8:38
  • Reading documentation can be sometimes of some help: leafletjs.com/reference-1.5.0.html#marker – TomazicM Aug 29 at 8:53
  • Thank you! I do it successfully. – wei shiuan Aug 30 at 3:58