简体   繁体   English

如何更新 Mapel SVG 地图中特定国家/地区的背景颜色?

[英]How do I update the background color of specific countries within a Mapel SVG Map?

I was able to successfully implement the Mapael map into my HTML page, and was able to configure the hover fill color to my liking via the JavaScript code.我能够成功地将 Mapael 地图实施到我的 HTML 页面中,并且能够通过 JavaScript 代码根据我的喜好配置悬停填充颜色。

I'm trying to change the fill color of specific individual countries.我正在尝试更改特定国家/地区的填充颜色。

I've worked briefly with SVGs before, and I used to open up a file with a text editor and update certain elements that way.我之前曾短暂地使用过 SVG,我曾经使用文本编辑器打开一个文件并以这种方式更新某些元素。 Is there a different way to do this?有没有不同的方法来做到这一点?

I was wondering if this is possible with Mapael?我想知道这是否可以与 Mapael 一起使用? and Where does one grab the SVG file from?以及从哪里获取 SVG 文件?

I downloaded and deploy the repository version (jQuery-Mapael-2.2.0).我下载并部署了存储库版本 (jQuery-Mapael-2.2.0)。

See screenshot of the files and folders.查看文件和文件夹的屏幕截图。 文件结构截图

Mapael SVG 屏幕截图

svg code file svg 代码文件

You have to use Mapael special function / params :您必须使用 Mapael 特殊功能/参数:

    $(function () {
        $("yourMapElementSelector").mapael({
 // Customize some areas of the map
                areas: {
                    "US": {
                        attrs: {
                            fill: "#488402"
                        }
                        , attrsHover: {
                            fill: "#a4e100"
                        }
                    }
                },

    });
    });

I am not sure how Mapael works, but normally what I would do with the SVG is add IDs to each country, something like:我不确定 Mapael 是如何工作的,但通常我会对 SVG 做的是为每个国家/地区添加 ID,例如:

<g id="france">
or
<path id="france">

Or whatever shapes you use and then just define a CSS class similar to this:或者您使用的任何形状,然后只需定义一个类似于此的 CSS 类:

/* if the paths are inside a group */
.svgactive path {
   fill: red;
}

/* if the paths are standalone */
path.svgactive {
   fill: red;
}

And just toggle the class .svgactive on your specific id inside the SVG file.只需在 SVG 文件中的特定 id 上切换.svgactive类。

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

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