@@ -4008,3 +4008,167 @@ OpenLayers.Layer.Yahoo = OpenLayers.Class(
4008
4008
4009
4009
CLASS_NAME : "OpenLayers.Layer.Yahoo"
4010
4010
} ) ;
4011
+
4012
+ /**
4013
+ * Class: OpenLayers.Layer.GML
4014
+ * Create a vector layer by parsing a GML file. The GML file is
4015
+ * passed in as a parameter.
4016
+ * *Deprecated*. To be removed in 3.0. Instead use OpenLayers.Layer.Vector
4017
+ * with Protocol.HTTP and Strategy.Fixed. Provide the protocol with a
4018
+ * format parameter to get the parser you want for your data.
4019
+ *
4020
+ * Inherits from:
4021
+ * - <OpenLayers.Layer.Vector>
4022
+ */
4023
+ OpenLayers . Layer . GML = OpenLayers . Class ( OpenLayers . Layer . Vector , {
4024
+
4025
+ /**
4026
+ * Property: loaded
4027
+ * {Boolean} Flag for whether the GML data has been loaded yet.
4028
+ */
4029
+ loaded : false ,
4030
+
4031
+ /**
4032
+ * APIProperty: format
4033
+ * {<OpenLayers.Format>} The format you want the data to be parsed with.
4034
+ */
4035
+ format : null ,
4036
+
4037
+ /**
4038
+ * APIProperty: formatOptions
4039
+ * {Object} Hash of options which should be passed to the format when it is
4040
+ * created. Must be passed in the constructor.
4041
+ */
4042
+ formatOptions : null ,
4043
+
4044
+ /**
4045
+ * Constructor: OpenLayers.Layer.GML
4046
+ * Load and parse a single file on the web, according to the format
4047
+ * provided via the 'format' option, defaulting to GML.
4048
+ *
4049
+ * Parameters:
4050
+ * name - {String}
4051
+ * url - {String} URL of a GML file.
4052
+ * options - {Object} Hashtable of extra options to tag onto the layer.
4053
+ */
4054
+ initialize : function ( name , url , options ) {
4055
+ var newArguments = [ ] ;
4056
+ newArguments . push ( name , options ) ;
4057
+ OpenLayers . Layer . Vector . prototype . initialize . apply ( this , newArguments ) ;
4058
+ this . url = url ;
4059
+ } ,
4060
+
4061
+ /**
4062
+ * APIMethod: setVisibility
4063
+ * Set the visibility flag for the layer and hide/show&redraw accordingly.
4064
+ * Fire event unless otherwise specified
4065
+ * GML will be loaded if the layer is being made visible for the first
4066
+ * time.
4067
+ *
4068
+ * Parameters:
4069
+ * visible - {Boolean} Whether or not to display the layer
4070
+ * (if in range)
4071
+ * noEvent - {Boolean}
4072
+ */
4073
+ setVisibility : function ( visibility , noEvent ) {
4074
+ OpenLayers . Layer . Vector . prototype . setVisibility . apply ( this , arguments ) ;
4075
+ if ( this . visibility && ! this . loaded ) {
4076
+ // Load the GML
4077
+ this . loadGML ( ) ;
4078
+ }
4079
+ } ,
4080
+
4081
+ /**
4082
+ * Method: moveTo
4083
+ * If layer is visible and GML has not been loaded, load GML, then load GML
4084
+ * and call OpenLayers.Layer.Vector.moveTo() to redraw at the new location.
4085
+ *
4086
+ * Parameters:
4087
+ * bounds - {Object}
4088
+ * zoomChanged - {Object}
4089
+ * minor - {Object}
4090
+ */
4091
+ moveTo :function ( bounds , zoomChanged , minor ) {
4092
+ OpenLayers . Layer . Vector . prototype . moveTo . apply ( this , arguments ) ;
4093
+ // Wait until initialisation is complete before loading GML
4094
+ // otherwise we can get a race condition where the root HTML DOM is
4095
+ // loaded after the GML is paited.
4096
+ // See http://trac.openlayers.org/ticket/404
4097
+ if ( this . visibility && ! this . loaded ) {
4098
+ this . loadGML ( ) ;
4099
+ }
4100
+ } ,
4101
+
4102
+ /**
4103
+ * Method: loadGML
4104
+ */
4105
+ loadGML : function ( ) {
4106
+ if ( ! this . loaded ) {
4107
+ this . events . triggerEvent ( "loadstart" ) ;
4108
+ OpenLayers . Request . GET ( {
4109
+ url : this . url ,
4110
+ success : this . requestSuccess ,
4111
+ failure : this . requestFailure ,
4112
+ scope : this
4113
+ } ) ;
4114
+ this . loaded = true ;
4115
+ }
4116
+ } ,
4117
+
4118
+ /**
4119
+ * Method: setUrl
4120
+ * Change the URL and reload the GML
4121
+ *
4122
+ * Parameters:
4123
+ * url - {String} URL of a GML file.
4124
+ */
4125
+ setUrl :function ( url ) {
4126
+ this . url = url ;
4127
+ this . destroyFeatures ( ) ;
4128
+ this . loaded = false ;
4129
+ this . loadGML ( ) ;
4130
+ } ,
4131
+
4132
+ /**
4133
+ * Method: requestSuccess
4134
+ * Process GML after it has been loaded.
4135
+ * Called by initialize() and loadUrl() after the GML has been loaded.
4136
+ *
4137
+ * Parameters:
4138
+ * request - {String}
4139
+ */
4140
+ requestSuccess :function ( request ) {
4141
+ var doc = request . responseXML ;
4142
+
4143
+ if ( ! doc || ! doc . documentElement ) {
4144
+ doc = request . responseText ;
4145
+ }
4146
+
4147
+ var options = { } ;
4148
+
4149
+ OpenLayers . Util . extend ( options , this . formatOptions ) ;
4150
+ if ( this . map && ! this . projection . equals ( this . map . getProjectionObject ( ) ) ) {
4151
+ options . externalProjection = this . projection ;
4152
+ options . internalProjection = this . map . getProjectionObject ( ) ;
4153
+ }
4154
+
4155
+ var gml = this . format ? new this . format ( options ) : new OpenLayers . Format . GML ( options ) ;
4156
+ this . addFeatures ( gml . read ( doc ) ) ;
4157
+ this . events . triggerEvent ( "loadend" ) ;
4158
+ } ,
4159
+
4160
+ /**
4161
+ * Method: requestFailure
4162
+ * Process a failed loading of GML.
4163
+ * Called by initialize() and loadUrl() if there was a problem loading GML.
4164
+ *
4165
+ * Parameters:
4166
+ * request - {String}
4167
+ */
4168
+ requestFailure : function ( request ) {
4169
+ OpenLayers . Console . userError ( 'Error in loading GML file ' + this . url ) ;
4170
+ this . events . triggerEvent ( "loadend" ) ;
4171
+ } ,
4172
+
4173
+ CLASS_NAME : "OpenLayers.Layer.GML"
4174
+ } ) ;
0 commit comments