传单根据文本字段更改圆圈标记颜色

Suk*_*ale 3 html javascript geojson leaflet

我的传单地图上有圆形标记,使用下面的代码,一切正常。

不过,我想根据名为“stype”的属性字段以不同的颜色显示标记。

关于如何实现这一目标有任何帮助或指导吗?

        function siteslabels (feature, layer){
        layer.bindPopup("<p class='info header'>"+ 
        "<b>" + feature.properties.SITE + "</b>" + 
        "</br>" + feature.properties.Address1 +
        "</br>" + feature.properties.stype +
        "</p>");
        };


        var geojsonMarkerOptions = {
            radius: 8,
            fillColor: 'green',
            color: 'black',
            weight: 1,
            opacity: 1,
            fillOpacity: 0.8
        };

        L.geoJson(sites, {
            pointToLayer: function (feature, latlng) {
                return L.circleMarker(latlng, geojsonMarkerOptions);
            },
            onEachFeature: siteslabels
        }).addTo(map);
Run Code Online (Sandbox Code Playgroud)

Suk*_*ale 5

已经整理好了 这是我的代码

    <script>    
        <!-- long and lat for UK & Zoom level for whole of UK  -->
        var map = L.map('map',{ center:[54.038486, -1.948915], zoom: 5});

        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);



        <!-- LAYERS/SITES -->
        <!-- LAYERS/SITES POP UP CONTENT-->
        function siteslabels (feature, layer){
        layer.bindPopup("<p class='info header'>"+ 
        "<b>" + feature.properties.SITE + "</b>" + 
        "</br>" + feature.properties.Address1 +
        "</br>" + feature.properties.stype +
        "</p>");
        };

        <!-- LAYERS/SITES POP UP COLOUR CIRCLE MARKERS->
        function getColor(stype) {
          switch (stype) {
            case 'POP':
              return  'orange';
            case 'Regen':
              return 'green';
            case 'LLU':
              return 'blue';
            case 'Colo':
              return 'purple';
            case 'DMSU':
              return 'blue';
            default:
              return 'white';
          }
        }

        <!-- LAYERS/SITES ADD LAYER->
        L.geoJson(sites, {
            pointToLayer: function (feature, latlng) {
            return new L.CircleMarker(latlng, {radius: 8, 
                                                fillOpacity: 1, 
                                                color: 'black', 
                                                fillColor: getColor(feature.properties.stype), 
                                                weight: 1,});
            },
            onEachFeature: siteslabels
        }).addTo(map);


    </script>
Run Code Online (Sandbox Code Playgroud)