@@ -340,6 +340,128 @@ ol.supermap.StyleUtils = {
340340 } ) ;
341341 }
342342 } ,
343+ dashStyle : function ( style , widthFactor ) {
344+ if ( ! style ) return [ ] ;
345+ var w = style . strokeWidth * widthFactor ;
346+ var str = style . strokeDashstyle ;
347+ switch ( str ) {
348+ case 'solid' :
349+ return [ ] ;
350+ case 'dot' :
351+ return [ 1 , 4 * w ] ;
352+ case 'dash' :
353+ return [ 4 * w , 4 * w ] ;
354+ case 'dashdot' :
355+ return [ 4 * w , 4 * w , 1 , 4 * w ] ;
356+ case 'longdash' :
357+ return [ 8 * w , 4 * w ] ;
358+ case 'longdashdot' :
359+ return [ 8 * w , 4 * w , 1 , 4 * w ] ;
360+ default :
361+ if ( ! str ) return [ ] ;
362+ if ( SuperMap . Util . isArray ( str ) ) return str ;
363+ str = SuperMap . String . trim ( str ) . replace ( / \s + / g, "," ) ;
364+ return str . replace ( / \[ | \] / gi, "" ) . split ( "," ) ;
365+ }
366+ } ,
367+ getStyleFromiPortalMarker : function ( icon ) {
368+ if ( icon . indexOf ( "./" ) == 0 ) {
369+ return null ;
370+ }
371+ //兼容iportal示例的问题
372+ if ( icon . indexOf ( "http://support.supermap.com.cn:8092/static/portal" ) == 0 ) {
373+ icon = icon . replace ( "http://support.supermap.com.cn:8092/static/portal" , "http://support.supermap.com.cn:8092/apps/viewer/static" ) ;
374+ }
375+ return new ol . style . Style ( {
376+ image : new ol . style . Icon ( {
377+ src : icon ,
378+ opacity : 1 ,
379+ size : [ 48 , 43 ] ,
380+ anchor : [ 0.5 , 1 ]
381+ } )
382+ } ) ;
383+ } ,
384+ getStyleFromiPortalStyle : function ( iPortalStyle , type , fStyle ) {
385+ var featureStyle = fStyle ? JSON . parse ( fStyle ) : null ;
386+ var me = this ;
387+ if ( type === 'Point' || type === 'MultiPoint' ) {
388+ var pointStyle = featureStyle || iPortalStyle . pointStyle ;
389+ if ( pointStyle . externalGraphic ) {
390+ if ( pointStyle . externalGraphic . indexOf ( "./" ) == 0 ) {
391+ return null ;
392+ }
393+ //兼容iportal示例的问题
394+ if ( pointStyle . externalGraphic . indexOf ( "http://support.supermap.com.cn:8092/static/portal" ) == 0 ) {
395+ pointStyle . externalGraphic = pointStyle . externalGraphic . replace ( "http://support.supermap.com.cn:8092/static/portal" , "http://support.supermap.com.cn:8092/apps/viewer/static" ) ;
396+ }
397+ return new ol . style . Style ( {
398+ image : new ol . style . Icon ( {
399+ src : pointStyle . externalGraphic ,
400+ opacity : pointStyle . graphicOpacity ,
401+ size : [ pointStyle . graphicWidth , pointStyle . graphicHeight ] ,
402+ //anchor: [-pointStyle.graphicXOffset / pointStyle.graphicWidth, -pointStyle.graphicYOffset / pointStyle.graphicHeight]
403+ } )
404+ } ) ;
405+ }
406+ return new ol . style . Style ( {
407+ image : new ol . style . Circle ( {
408+ fill : new ol . style . Fill ( {
409+ color : me . hexToRgba ( pointStyle . fillColor , pointStyle . fillOpacity )
410+ } ) ,
411+ stroke : new ol . style . Stroke ( {
412+ color : me . hexToRgba ( pointStyle . strokeColor , pointStyle . strokeOpacity ) ,
413+ lineCap : pointStyle . strokeLineCap ,
414+ lineDash : this . dashStyle ( pointStyle , 1 ) ,
415+ width : pointStyle . strokeWidth
416+ } ) ,
417+ radius : pointStyle . pointRadius
418+ } )
419+ } ) ;
420+ }
421+ if ( type === 'LineString' || type === 'MultiLineString' || type === 'Box' ) {
422+ var lineStyle = featureStyle || iPortalStyle . lineStyle ;
423+ return new ol . style . Style ( {
424+ stroke : new ol . style . Stroke ( {
425+ color : me . hexToRgba ( lineStyle . strokeColor , lineStyle . strokeOpacity ) ,
426+ lineCap : lineStyle . strokeLineCap ,
427+ lineDash : this . dashStyle ( lineStyle , 1 ) ,
428+ width : lineStyle . strokeWidth
429+ } )
430+ } ) ;
431+ }
432+ if ( type === 'Polygon' || type === 'MultiPolygon' ) {
433+ var polygonStyle = featureStyle || iPortalStyle . polygonStyle ;
434+ return new ol . style . Style ( {
435+ fill : new ol . style . Fill ( {
436+ color : me . hexToRgba ( polygonStyle . fillColor , polygonStyle . fillOpacity )
437+ } ) ,
438+ stroke : new ol . style . Stroke ( {
439+ color : me . hexToRgba ( polygonStyle . strokeColor , polygonStyle . strokeOpacity ) ,
440+ lineCap : polygonStyle . strokeLineCap ,
441+ lineDash : this . dashStyle ( polygonStyle , 1 ) ,
442+ width : polygonStyle . strokeWidth
443+ } )
444+ } ) ;
445+ }
446+ } ,
447+
448+ hexToRgba : function ( hex , opacity ) {
449+ var color = [ ] , rgba = [ ] ;
450+ hex = hex . replace ( / # / , "" ) ;
451+ if ( hex . length == 3 ) {
452+ var tmp = [ ] ;
453+ for ( var i = 0 ; i < 3 ; i ++ ) {
454+ tmp . push ( hex . charAt ( i ) + hex . charAt ( i ) ) ;
455+ }
456+ hex = tmp . join ( "" ) ;
457+ }
458+ for ( var i = 0 ; i < 6 ; i += 2 ) {
459+ color [ i ] = "0x" + hex . substr ( i , 2 ) ;
460+ rgba . push ( parseInt ( Number ( color [ i ] ) ) ) ;
461+ }
462+ rgba . push ( opacity ) ;
463+ return "rgba(" + rgba . join ( "," ) + ")" ;
464+ } ,
343465
344466 getDefaultStyle : function ( type ) {
345467 var style = style || { } ;
0 commit comments