Redis geojson实现地图聚合效果

目录

地图聚合API

Java  Redis示例


 地图聚合API

https://openlayers.org/en/latest/examples/cluster.html

通过地图平移缩放事件控制地图四至范围内地图刷新和加载详细点控制。最终实现效果如下:

Java  Redis示例

添加geojson数据:

/**
	 * 更新GEOHASH值
	 * @param dwCode
	 * @param coordinate
	 * @param memberName "HLYID-score"
	 */
	public static void positonToGeohash(String dwCode,String hlyId,GeoCoordinate coordinate,String memberName){
		String storeKey=XHT_ZZJG_GEOPOSITION+dwCode;
		String expireKey=XHT_ZZJG_GEOEXPIRE+dwCode;
		RedisUtil.geoadd(storeKey, coordinate, memberName);
		// 设置超时过期
		RedisUtil.zadd(expireKey,System.currentTimeMillis(),memberName);
		Set<String> expiredKeys = RedisUtil.zrangeByScore(expireKey, 0, System.currentTimeMillis()-30*60*1000);
		
		if(expiredKeys!=null && expiredKeys.size()>0) {
			//删除超时的数据
			RedisUtil.zrem(storeKey,expiredKeys.toArray(new String[expiredKeys.size()]));
			RedisUtil.zrem(expireKey,expiredKeys.toArray(new String[expiredKeys.size()]));
			//zzjgList.toArray(new String[zzjgList.size()])
			//TODO : 两个集合中的size不一致时,需要按照expiredKeys中为标准删除storeKey中多余的数据
			
		}
		
		RedisUtil.expire(expireKey, Constants.MOBILE_TOKEN_KEY_HALF_HOUR);//Constants.MOBILE_TOKEN_KEY_HALF_HOUR
		RedisUtil.expire(storeKey, Constants.MOBILE_TOKEN_KEY_HALF_HOUR);
	}	

完整代码请下载连接(没有的自行补全):https://download.csdn.net/download/boonya/12048388

缺少的工具类请参考:Redis连接池及单节点工具与多Redis节点管理工具

发布了627 篇原创文章 · 获赞 535 · 访问量 359万+

猜你喜欢

转载自blog.csdn.net/boonya/article/details/103679524