简体   繁体   English

如果位置的“id”有空间,角度数据图不会填充正确的颜色

[英]angular-datamaps not filling proper colour if “id” of a location has space

For angular-datamaps, Assume this is my mapObject and I have location names with id's ("AZ", "CO", "AZ CO", "CO AB") (exactly along with space)对于角度数据图,假设这是我的 mapObject,并且我的位置名称带有 id(“AZ”、“CO”、“AZ CO”、“CO AB”)(完全与空格一起)

$scope.mapObject = {
  scope: 'usa',
  options: {
    width: 1110,
    legendHeight: 60 // optionally set the padding for the legend
  },
  geographyConfig: {
    highlighBorderColor: '#EAA9A8',
    highlighBorderWidth: 2
  },
  fills: {
    'HIGH': '#CC4731',
    'MEDIUM': '#306596',
    'LOW': '#667FAF',
    'defaultFill': '#DDDDDD'
  },
  data: {
    "AZ": {
      "fillKey": "MEDIUM",
    },
    "CO": {
     "fillKey": "HIGH",
    },
    "AZ CO": {
      "fillKey": "LOW",
    },
    "CO AB": {
      "fillKey": "MEDIUM",
    }
  },
}

When map is rendered, Colors filled is: Medium for AZ, High for CO, High for "AZ CO", High for "CO AB".渲染 map 时,Colors 填充为:AZ 为中,CO 为高,“AZ CO”为高,“CO AB”为高。

If "AZ" and "CO" values are in a different order (first "CO", then "AZ") inside data, then Colors filled are High for CO, Medium for AZ, Medium for "AZ CO", High for "CO AB"如果“AZ”和“CO”值在数据内部的顺序不同(首先是“CO”,然后是“AZ”),则 Colors 填充的 CO 为高,AZ 为中,“AZ CO”为中,“AZ CO”为中,“一氧化碳"

What do I do to get the corresponding colors without these locations overriding them?在没有这些位置覆盖它们的情况下,我该怎么做才能获得相应的 colors?

TIA. TIA。

Here is a suggestion:这是一个建议:

var locations = $scope.mapObject.data;
var colors = $scope.mapObject.fills;

var locationsColors = {};
var dataFormatted = [];
for (location in locations) {
  locationsColors[location] = colors[locations[location].fillKey];
}
console.log("Object of Locations Colors mapping : ", locationsColors);
console.log("Color of 'AZ CO' for example is : ", locationsColors["AZ CO"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM