rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

Add support For Multiple colors for different features #274

Closed skudale24 closed 12 months ago

skudale24 commented 1 year ago

It would be nice to have support for features in different colors as seen in the Google maps API here: https://developers.google.com/maps/documentation/javascript/examples/boundaries-choropleth#maps_boundaries_choropleth-typescript

The overridestyle method should be able to achieve that I believe:


var jsonData = "{ \"type\": \"FeatureCollection\"," +
                       "  \"features\": [" +
                       "{ \"type\": \"Feature\"," +
                       " \"id\": 2," +
                       " \"properties\": { \"stroke\": \"#555555\", \"stroke-width\": 2, \"stroke-opacity\": 1 }, " +
                       " \"geometry\": {\"type\": \"LineString\",  \"coordinates\": [ [ 151.219, -33.888], [151.23, -33.869]]}}]}";

        await _map1.InteropObject.Data.AddGeoJson(jsonData);
        var feature = await _map1.InteropObject.Data.GetFeatureById(1);
        await _map1.InteropObject.Data.OverrideStyle(feature, new StyleOptions { StrokeColor = "green", StrokeWeight = 2 });
valentasm1 commented 1 year ago

Will take a look at weekend. Summer is over so maybe will have more time :).

valentasm1 commented 1 year ago

I changed that AddGeoJson to return features with their guid id. Not you could do request feature.GetId() to return real undeling id. Also added method to ovveride style, but not sure why it is not working. No error is returned. I will try investigate next time.

https://github.com/rungwiroon/BlazorGoogleMaps/commit/612359be5ec791c1193d11ed39fd8b618be0ed88#diff-79f1ab0b4c96e080517bf21bd3b2fbfdc041a9fa93848307a388912ef40485b9R603

valentasm1 commented 12 months ago

https://www.nuget.org/packages/BlazorGoogleMaps/3.1.4 Let me know if it works as expected