Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

地图geojson中properties键值为大写时的问题 #11799

Closed
nocny-x opened this issue Dec 6, 2019 · 11 comments
Closed

地图geojson中properties键值为大写时的问题 #11799

nocny-x opened this issue Dec 6, 2019 · 11 comments

Comments

@nocny-x
Copy link

nocny-x commented Dec 6, 2019

Version

4.5.0

Steps to reproduce

地图加载的geojson如果properties中的键名为大写时,渲染出来的地图没有区分开,不能单个选中

What is expected?

地图中每个区域应该可以单独选中

What is actually happening?

只能选中整块地图


基于https://www.echartsjs.com/examples/en/editor.html?c=map-usa 这个示例我在codepen上做了一段重现bug代码的示例:
https://codepen.io/xyq/pen/XWJbGBd

@echarts-bot
Copy link

echarts-bot bot commented Dec 6, 2019

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that you have posted enough image to demo your request. You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to [email protected]. Please attach the issue link if it's a technical questions.

If you are interested in the project, you may also subscribe our mail list.

Have a nice day! 🍵

@echarts-bot echarts-bot bot added bug en This issue is in English pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Dec 6, 2019
@alex2wong
Copy link
Contributor

@yuanqiangxie 目前Echarts 中的 geojsonParser 只支持 properties.name 作为 key 去标识 region 对象,所以要么你批量修改下你的数据,改成小写name,或者我们改下 parseGeoJson.js 的一行,虽然我觉得没必要。你们觉得呢? @yufeng04 @Ovilia

https://github.com/apache/incubator-echarts/blob/master/src/coord/geo/parseGeoJson.js#L139
var region = new Region( properties.name, // properties.name || properties.NAME geometries, properties.cp );

@yufeng04
Copy link
Contributor

yufeng04 commented Dec 9, 2019

@alex2wong 个人觉得还是开发者修改比较好!

@alex2wong
Copy link
Contributor

Geojson 的这个properties 是没有严格标准的,具体用户会提供 name,NAME,还是 Name 都不可预测。所以就怕过两天来个issue,说用的 nAME 怎么办? 倒是可以先把纯大写这种情况考虑下。

@nocny-x
Copy link
Author

nocny-x commented Dec 9, 2019

我觉得还是应该修改下parser好一些。我们现在用的是别人的wfs服务返回的json,服务端我们修改不了,现在只能是前端把key值替换成小写。我建议最好增加一个option配置项用户可自定义region标识@alex2wong

@yafengstark
Copy link

这个问题我找到所在点了,

 if (geo.type === 'MultiPolygon') {
            zrUtil.each(coordinates, function (item) {
                if (item[0]) {
                    geometries.push({
                        type: 'polygon',
                        exterior: item[0],
                        interiors: item.slice(1)
                    });
                }
            });
        }

        // 这是我后添加的,验证过可行
        properties.name = properties.NAME;


        var region = new Region(properties.name, geometries, properties.cp);

@yafengstark
Copy link

这个问题我找到所在点了,

 if (geo.type === 'MultiPolygon') {
            zrUtil.each(coordinates, function (item) {
                if (item[0]) {
                    geometries.push({
                        type: 'polygon',
                        exterior: item[0],
                        interiors: item.slice(1)
                    });
                }
            });
        }

        // 这是我后添加的,验证过可行
        properties.name = properties.NAME;


        var region = new Region(properties.name, geometries, properties.cp);

上面的大佬说过这块源码了,刚看到。看了一下geojson的文档,确实没有说properties的大小写要求,name和NAME都可以。如果echarts不修改这个地方,那使用NAME的geojson转换就很麻烦,而且不灵活(其他字段也无法像现在name字段这样的效果),优雅的方式应该是多添加一个参数,最少应该在目前的文档中注明使用时注意的地方(强制指定geojson 中properties中存在name)。 @alex2wong

@pissang pissang added enhancement and removed bug en This issue is in English pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Dec 10, 2019
@pissang
Copy link
Contributor

pissang commented Dec 10, 2019

谢谢建议 @yafengstark 。geojson 对于 properties 里拥有的属性确实没有规范规定,感觉是应该兼容一下。

@alex2wong 可以按照你修改的思路提一个 PR 么?感谢~

@yafengstark
Copy link

我尝试修改了一下,pr在这里,纯新手。
思路就是在map里面添加一个参数,用于指定geojson的名称字段对应的tag值,默认为name。一直传递到geojson解析的代码中去。

@alex2wong @pissang

@Ovilia
Copy link
Contributor

Ovilia commented Feb 27, 2020

#12156 中已修复,非常感谢 @yafengstark @alex2wong 的贡献~

@Ovilia Ovilia closed this as completed Feb 27, 2020
@maicWorkGithub
Copy link

@pissang 你好,请问geojson里的properties的数据,怎么在echarts的事件里获取到?比如click的时候,现在只能获取到上面说的name。但是 https://github.com/apache/incubator-echarts/blob/master/src/coord/geo/parseGeoJson.ts#L145 这行代码好像是把全部的值都带出来了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants