Custom coloring of countries in Google Maps : GWT?

梦想的初衷 提交于 2019-12-12 01:24:12

问题


I am trying to add a custom fusion table styling to my Google Map. Similar to here: https://developers.google.com/maps/documentation/javascript/examples/layer-fusiontables-styling

I want to color a country based on a particular value assigned to it let's say 0 = green, 50 = yellow and 100=red.

I have a Fusion table set up here: https://www.google.com/fusiontables/DataSource?docid=1tJkzVXTv-B2-rFeQVO9bX_vICCvJ9Xq1LU6xog5f
and I am able to achieve desired result here but not in my code.

I am using Google Maps API V3 with GWT.

    private void setupFusionTablesLayer(final MapWidget mapWidget) {

    final String select = "geometry";
    final String from = "1tJkzVXTv-B2-rFeQVO9bX_vICCvJ9Xq1LU6xog5f";
    final String where = "risk >= 0";

    final FusionTablesStyle fusionTablesStyle = FusionTablesStyle
            .newInstance();
    final FusionTablesPolygonOptions polygonOptions = FusionTablesPolygonOptions
            .newInstance();
    polygonOptions.setFillColor("#505050"); // grey
    polygonOptions.setFillOpacity(0.3);
    fusionTablesStyle.setPolygonOptions(polygonOptions);

    final FusionTablesQuery query = FusionTablesQuery.newInstance();
    query.setSelect(select);
    query.setFrom(from);
    query.setWhere(where);

    final FusionTablesLayerOptions options = FusionTablesLayerOptions
            .newInstance();
    options.setQuery(query);

    final JsArray arr = JavaScriptObject.createArray().cast();
    arr.push(fusionTablesStyle);
    options.setStyles(arr);

    final FusionTablesLayer layer = FusionTablesLayer.newInstance(options);
    layer.addClickHandler(new FusionTablesMouseMapHandler() {
        @Override
        public void onEvent(final FusionTablesMouseMapEvent event) {

            event.getInfoWindowHtml();
            final LatLng latlng = event.getLatLng();

            event.getPixelOffset();

            event.getRow();
            final String json = event.getRowAsJson();
            GWT.log("click on " + latlng.getToString() + "  json=" + json);
        }
    });
    layer.setMap(mapWidget);
}

This is what I have so far:

I have no clue why it is all red!!

Please help.
Thanks

EDIT#1 I did the code change and was able to change the whole map color to grey. But still not sure how to get risk column's value and update per country color.

来源:https://stackoverflow.com/questions/29577659/custom-coloring-of-countries-in-google-maps-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!