@ -1,12 +1,22 @@
package com.fanruan.map ;
import com.fr.concurrent.NamedThreadFactory ;
import com.fr.decision.webservice.v10.map.geojson.MapDataType ;
import com.fr.decision.webservice.v10.map.geojson.bean.GeoJSONFactory ;
import com.fr.decision.webservice.v10.map.geojson.helper.GEOJSONHelper ;
import com.fr.decision.webservice.v10.map.geojson.helper.GEOJSONUtils ;
import com.fr.log.FineLoggerFactory ;
import com.fr.third.org.apache.commons.lang3.time.StopWatch ;
import com.fr.workspace.server.repository.map.MapRepository ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Map ;
import java.util.concurrent.Callable ;
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
import java.util.concurrent.Future ;
/ * *
* 设计器地图资源Helper
*
@ -22,9 +32,21 @@ public class DesignGEOJSONHelper extends GEOJSONHelper {
StopWatch watch = new StopWatch ( ) ;
watch . start ( ) ;
URL_JSON_MAP . putAll ( MapRepository . getInstance ( ) . getMapResource ( GEOJSONUtils . getMapDataTypePath ( MapDataType . GEOGRAPHIC ) ) ) ;
URL_JSON_MAP . putAll ( MapRepository . getInstance ( ) . getMapResource ( GEOJSONUtils . getMapDataTypePath ( MapDataType . IMAGE ) ) ) ;
ExecutorService executorService = Executors . newFixedThreadPool ( 2 , new NamedThreadFactory ( "[design-map] initGeoJSON" ) ) ;
List < Callable < Void > > tasks = new ArrayList < > ( ) ;
tasks . add ( ( ) - > {
updateGeographic ( ) ;
return null ;
} ) ;
tasks . add ( ( ) - > {
updateImage ( ) ;
return null ;
} ) ;
List < Future < Void > > resultList = executorService . invokeAll ( tasks ) ;
for ( Future < Void > result : resultList ) {
result . get ( ) ;
}
executorService . shutdown ( ) ;
FineLoggerFactory . getLogger ( ) . info ( "Load chart map resources spend time {} ms" , watch . getTime ( ) ) ;
watch . stop ( ) ;
@ -33,4 +55,25 @@ public class DesignGEOJSONHelper extends GEOJSONHelper {
}
}
private void updateGeographic ( ) {
try {
Map < String , String > geographic = MapRepository . getInstance ( ) . getMapResource ( GEOJSONUtils . getMapDataTypePath ( MapDataType . GEOGRAPHIC ) ) ;
for ( Map . Entry < String , String > entry : geographic . entrySet ( ) ) {
URL_JSON_MAP . put ( entry . getKey ( ) , GeoJSONFactory . create ( entry . getValue ( ) , entry . getKey ( ) ) ) ;
}
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
private void updateImage ( ) {
try {
Map < String , String > image = MapRepository . getInstance ( ) . getMapResource ( GEOJSONUtils . getMapDataTypePath ( MapDataType . IMAGE ) ) ;
for ( Map . Entry < String , String > entry : image . entrySet ( ) ) {
URL_JSON_MAP . put ( entry . getKey ( ) , GeoJSONFactory . create ( entry . getValue ( ) , entry . getKey ( ) ) ) ;
}
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
}