@@ -18,37 +18,86 @@ define(["activity/ol","print","util","colormyworld","humane","flag","l10n"],
1818 } ) ,
1919 } ) ;
2020
21- window . map . on ( 'click' , function ( evt ) {
22- if ( colormyworld . mode == COLORING ) {
23- var FOUND = false ;
24- dummmy = window . map . forEachFeatureAtPixel ( evt . pixel , function ( target_feature , layer ) {
25- var target_name = target_feature . get ( "NAME" ) ;
26- if ( ! target_name ) target_name = target_feature . get ( "Name" ) ;
27- if ( ! target_name ) target_name = target_feature . get ( "name" ) ;
28- if ( colormyworld . currents . indexOf ( target_name ) < 0 ) {
29- if ( ! me . tooltipDisplay || target_name != me . tooltipDisplay ) {
30- me . tooltipDisplay = target_name ;
31- humane . timeout = 1000 ;
32- humane . log ( "<img src='./flags/" + flag [ `${ target_name . replace ( / / g, '_' ) } ` ] + ".svg' style='width: auto; height: 1em;'> " + l10n . get ( target_name . replace ( / / g, '_' ) ) . replace ( / _ / g, ' ' ) ) ;
33- setTimeout ( function ( ) {
34- me . tooltipDisplay = null ;
35- } , humane . timeout ) ;
21+ window . map . on ( 'click' , function ( evt ) {
22+ if ( colormyworld . mode == COLORING ) {
23+ var FOUND = false ;
24+ var clickedFeature = null ;
25+
26+ window . map . forEachFeatureAtPixel ( evt . pixel , function ( target_feature , layer ) {
27+ if ( layer === me . featureOverlay ) return ;
28+
29+ var name = target_feature . get ( "NAME" ) ||
30+ target_feature . get ( "Name" ) ||
31+ target_feature . get ( "name" ) || "" ;
32+ if ( ! name || name . trim ( ) === "" ) return ;
33+
34+ if ( colormyworld . currents . indexOf ( name ) >= 0 ) return ;
35+
36+ var geom = target_feature . getGeometry ( ) ;
37+ if ( ! geom || ( geom . getType ( ) !== 'Polygon' && geom . getType ( ) !== 'MultiPolygon' ) ) {
38+ return ;
39+ }
40+
41+ if ( ! clickedFeature ) {
42+ clickedFeature = target_feature ;
43+ }
44+
45+ if ( ! me . tooltipDisplay || me . tooltipDisplay != name ) {
46+ me . tooltipDisplay = name ;
47+ humane . timeout = 1000 ;
48+ humane . log (
49+ "<img src='./flags/" + ( flag [ name . replace ( / / g, '_' ) ] || 'world' ) + ".svg' " +
50+ "style='width:auto;height:1.4em;vertical-align:middle;margin-right:8px;'>" +
51+ l10n . get ( name . replace ( / / g, '_' ) ) . replace ( / _ / g, ' ' )
52+ ) ;
53+ setTimeout ( function ( ) { me . tooltipDisplay = null ; } , 1000 ) ;
54+ }
55+
56+ FOUND = true ;
57+ return false ;
58+
59+ } , {
60+ hitTolerance : 4
61+ } ) ;
62+
63+ if ( clickedFeature ) {
64+ var selectedColor = colormyworld . getRGBColorString ( ) ;
65+ var style = clickedFeature . getStyle ( ) ;
66+
67+ var currentFill = null ;
68+ if ( style && style . getFill ( ) ) {
69+ currentFill = style . getFill ( ) . getColor ( ) ;
70+ }
71+
72+ if ( currentFill && currentFill === selectedColor ) {
73+ clickedFeature . setStyle ( null ) ;
74+ }
75+ else {
76+ var strokeColor = ( typeof DEFAULT_STROKE !== 'undefined' ) ? DEFAULT_STROKE : '#333333' ;
77+
78+ var newStyle = new ol . style . Style ( {
79+ fill : new ol . style . Fill ( { color : selectedColor } ) ,
80+ stroke : new ol . style . Stroke ( { color : strokeColor , width : 1.5 } )
81+ } ) ;
82+ clickedFeature . setStyle ( newStyle ) ;
3683 }
37- var rgbColorString = colormyworld . getRGBColorString ( ) ;
38- print ( rgbColorString ) ;
39- var nouveau_style = new ol . style . Style ( {
40- fill : new ol . style . Fill ( { color : colormyworld . getRGBColorString ( ) } ) ,
41- stroke :new ol . style . Stroke ( { color : DEFAULT_STROKE , width : 1 } ) ,
42- } ) ;
43- target_feature . setStyle ( nouveau_style ) ;
44- FOUND = true ;
45- } } ) ;
46- if ( ! FOUND ) {
47- colormyworld . set_background ( null ) ;
4884 }
85+
86+ if ( ! FOUND ) {
87+ var selectedColor = colormyworld . getRGBColorString ( ) ;
88+ var currentBg = colormyworld . background_color ;
89+
90+ if ( currentBg === selectedColor ) {
91+ colormyworld . set_background ( 'rgb(0,120,255)' ) ;
92+ }
93+ else {
94+ colormyworld . set_background ( selectedColor ) ;
95+ }
96+ }
97+ } else {
98+ colormyworld . check_feature ( evt . pixel ) ;
4999 }
50- else colormyworld . check_feature ( evt . pixel ) ;
51- } ) ;
100+ } ) ;
52101
53102 var highlightStyleCache = { } ;
54103 me . featureOverlay = new ol . layer . Vector ( {
0 commit comments