ChinaMapView:这是一个可拖拽,可点击,可手势放大的自定义中国地图组件,使用简单,具备一个自定义View应有的基本素质
| 常规使用 | 下拉刷新及其他滑动冲突 |
|---|---|
![]() |
![]() |
| 展示省份名字(1.0.2新增支持) | 只允许点击,不允许缩放和拖动(1.0.4新增支持) |
|---|---|
![]() |
![]() |
| 属性(均包含set、get方法) | 类型 | 作用 |
|---|---|---|
| provinceslist | List | 包含所有的省份model |
| isShowName | boolean | 设置是否展示省份名字 |
| ### Data实例类 ProvinceModel,通过chinaMapModel.getProvinceslist()获得,以下为使用期间会接触到的属性,别的属性都是为绘制准备的,不用关心,也不用去设置。 |
| 属性(均包含set、get方法) | 类型 | 作用 |
|---|---|---|
| color | int | 省份填充的颜色 |
| normalBorderColor | int | 省份未选中状态下的边框颜色 |
| selectBorderColor | int | 省份未选中状态下的边框颜色 |
| nameColor | int | 省份名字颜色,每个省份名字的颜色可以不一致 |
| 方法 | 参数 | 作用 |
|---|---|---|
| setEnableTouch | boolean | 设置是否可以消费事件(默认为true) |
| setEnableScroll | boolean | 设置是否可以缩放和拖动(默认为true) |
| setScaleMin | int | 设置缩放的最小倍数,最终结果>=0 |
| setScaleMax | int | 设置缩放的最大倍数,最终结果>=1 |
| getChinaMapModel | ChinaMapModel | 返回ChinaMapModel对象,用于之后的修改刷新view的展示 |
| setOnProvinceClickLisener | ChinaMapView.onProvinceClickLisener | 省份点击选中接口 |
| setOnPromiseParentTouchListener | ChinaMapView.onPromiseParentTouchListener | 通知外界是否允许chinamapview之上的view拦截事件 |
| notifyDataChanged | void | 修改ChinaMapModel对象后,刷新View |
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.NoEndToLF:ChinaMapView:1.0.4'
}
java
<com.wxy.chinamapview.view.ChinaMapView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/map"></com.wxy.chinamapview.view.ChinaMapView>
java
chinaMapModel = map.getChinaMapModel();
##### 设置缩放的最大最小值
``` java
map.setScaleMin(1);
map.setScaleMax(3);
##### 修改省份颜色,这里所有省份都处理成一样了,实际场景可给省份设置不同的颜色,修改完后map.notifyDataChanged()刷新View
``` java
for (ProvinceModel provinceModel:chinaMapModel.getProvinceslist()){
provinceModel.setColor(color);
}
map.notifyDataChanged();
``` java for (ProvinceModel provinceModel:chinaMapModel.getProvinceslist()){ provinceModel.setNormalBordercolor(color); } map.notifyDataChanged();
##### 修改省份选中状态下边框颜色,这里所有省份都处理成一样了,实际场景可给省份设置不同的颜色,修改完后map.notifyDataChanged()刷新View
``` java
for (ProvinceModel provinceModel:chinaMapModel.getProvinceslist()){
provinceModel.setSelectBordercolor(color);
}
map.notifyDataChanged();
for (ProvinceModel provinceModel:chinaMapModel.getProvincesList()){
provinceModel.setNameColor(color);
}
map.notifyDataChanged();
``` java map.setOnProvinceClickLisener(new ChinaMapView.onProvinceClickLisener() { @Override public void onSelectProvince(String provinceName) { tvName.setText(provinceName); } });
##### 添加事件处理回调,即通知外界是否要拦截事件;
``` java
chinamapView.setOnPromiseParentTouchListener(new ChinaMapView.onPromiseParentTouchListener() {
@Override
public void onPromiseTouch(boolean promise) {
swipe.setEnabled(promise);
}
});
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
chinamapView.setEnableTouch(false);
//模拟耗时
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
String namestring = ColorChangeUtil.nameStrings[++currentColor % ColorChangeUtil.nameStrings.length];
btnChange.setText(namestring);
colorView.setList(colorView_hashmap.get(namestring));
//重置map各省份颜色
ColorChangeUtil.changeMapColors(chinaMapModel, namestring);
chinamapView.notifyDataChanged();
swipe.setRefreshing(false);
chinamapView.setEnableTouch(true);
}
},2000);
}
});
Copyright (c) [2018] [static]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
$ claude mcp add ChinaMapView \
-- python -m otcore.mcp_server <graph>