自定义Bing地图类型问题

时间:2017-10-19 19:26:23

标签: bing-maps

我在尝试纠正这个问题时遇到了问题。我创建了2个自定义Bing地图类型。用户可以通过自定义下拉框更改地图类型。当用户从默认更改为道路时。大多数情况下,如果用户更改回默认值,则道路会停留。我错过了一些如此明显的东西。我已经包含了我的代码。

地图类型

var defaultMapColors =
        {
            "version": "1.0",
            "settings":
                {
                    "landColor": "#686868"
                },
            "elements":
                {
                    "mapElement": { "labelVisible": false },
                    "area": { "visible": false },
                    "transportation": { "visible": false },
                    "countryRegion": {                          //country
                        "borderStrokeColor": "#444444",
                        "borderOutlineColor": "#00000000",
                        "borderWidthScale": 3,
                        "fillColor": "#888888",
                        "visible": true
                    },
                    "adminDistrict": {                          //states
                        "borderVisible": true,
                        "borderStrokeColor": "#444444",
                        "borderOutlineColor": "#00000000",
                        "borderWidthScale": 3,
                        "fillColor": "#888888",
                    },
                    "water": { "fillColor": "#4E5E6D" },
                    "point": { "visible": false }
                }
        };

    var defaultMapColorsWithRoads =
        {
            "version": "1.0",
            "settings":
                {
                    "landColor": "#686868"
                },
            "elements":
                {
                    "mapElement": { "labelVisible": false },
                    "area": { "visible": false },
                    "transportation": {
                        "visible": true,
                        "strokeColor": "#ffffff",
                    },
                    "countryRegion": {                          //country
                        "borderStrokeColor": "#444444",
                        "borderOutlineColor": "#00000000",
                        "borderWidthScale": 3,
                        "fillColor": "#888888",
                        "visible": true
                    },
                    "adminDistrict": {                          //states
                        "borderVisible": true,
                        "borderStrokeColor": "#444444",
                        "borderOutlineColor": "#00000000",
                        "borderWidthScale": 3,
                        "fillColor": "#888888",
                    },
                    "water": { "fillColor": "#4E5E6D" },
                    "point": { "visible": false }
                }

        };

下拉

<div class="form-group">
        <select id="customNavSelector" class="form-control selectpicker show-tick">
            <option value="Default" onclick="map.setView({ mapTypeId: Microsoft.Maps.MapTypeId.road, customMapStyle: defaultMapColors });">Default</option>
            <option value="Road" onclick="map.setView({ mapTypeId: Microsoft.Maps.MapTypeId.road, customMapStyle: defaultMapColorsWithRoads });">Road</option>
            <option value="Aerial" onclick="map.setView({ mapTypeId: Microsoft.Maps.MapTypeId.aerial, customMapStyle: '' });">Aerial</option>
        </select>
    </div>

地图对象

map = new Microsoft.Maps.Map(mapDiv,
                    {
                        credentials: "@ViewBag.BingMapKey",
                        center: new Microsoft.Maps.Location(@ConfigurationManager.AppSettings["CenterLatitude"], @ConfigurationManager.AppSettings["CenterLongitude"]),
                        customMapStyle: defaultMapColors,
                        mapTypeId: Microsoft.Maps.MapTypeId.road, //grayscale, aerial, road, canvasLight, canvasDark
                        //liteMode: true,
                        showMapTypeSelector: false, //set to true to show default bing map selector
                        disableStreetside: false,
                        disableStreetsideAutoCoverage: true,
                        zoom: zoom,
                        backgroundColor: 'black',
                        //showBreadcrumb: true,
                        //showLocateMeButton: locator,
                        enableInertia: false,
                        enableClickableLogo: false,
                        navigationBarMode: Microsoft.Maps.NavigationBarMode.compact     //compact, default, minified
                    });

1 个答案:

答案 0 :(得分:1)

存在一个已知问题,即设置地图样式会将新样式与旧样式合并,而不是完全覆盖它。该团队计划解决这个问题。同时,如果您处置当前地图并使用地图样式创建地图的新实例,它将按预期工作。