Location: PHPKode > projects > PhpArcIMS > phpConnector/phparcims_layer.php
<?php

require_once('phparcims0.5/phparcims_objects.php');

/**
* Defines the layer to be of type feature (e.g. shapefile, ArcSDE).
* @package phparcims_layer
* @constant string FEATURE_LAYER
*/
DEFINE(FEATURE_LAYER,'featureclass');
/**
* Defines the layer to be of type acetate.
* @package phparcims_layer
* @constant string ACETATE_LAYER
*/
DEFINE(ACETATE_LAYER,'acetate');
/**
* Defines the layer to be of type image (e.g. TIFF, ArcSDE raster).
* @package phparcims_layer
* @constant string IMAGE_LAYER
*/
DEFINE(IMAGE_LAYER,'image');

/**
* Specifies a point type for an {@link aimsFeatureLayer}.
* @package phparcims_layer
* @constant string POINT_FEATURE
*/
DEFINE(POINT_FEATURE,'point');
/**
* Specifies a line type for an {@link aimsFeatureLayer}.
* @package phparcims_layer
* @constant string LINE_FEATURE
*/
DEFINE(LINE_FEATURE,'line');
/**
* Specifies a polygon type for an {@link aimsFeatureLayer}.
* @package phparcims_layer
* @constant string POLYGON_FEATURE
*/
DEFINE(POLYGON_FEATURE,'polygon');

/**
* The class is used to define a single layer in the map. The following type of layers exist:
* <ul>
* <li>acetate: layer that can be put 'on-top' of the map, mainly used to display north arrows, scalebar, etc.</li>
* <li>image: used to diplay an image/grid; this can be tif, jpeg, ArcSDE grid, etc.</li>
* <li>featureclass: vector based layer (e.g. shapefile)</li>
* </ul>
* Featureclass layers are all defined in the service file. New layers based on datasets not already in the
* service, can not be added. New featureclass/image layers can only be created based on an existing datasource (layer).
* Any such new layer has to be defined with an existing layer as it's datasource.<br>
* Example:{@example frame ex_featureClassLayer.txt}
* <br>
*
* @class aimsLayer
* @package phparcims_layer
* @todo create methods for setting/removing CoordSys
*/
class aimsLayer {
	/**
	* The ID of the layer.
	* This ID is assigned when the layer is added to the layer is unique for each layer. Currently
	* it is read-only.
	* @class aimsLayer
	* @attribute public string ID
	*/
	var $ID;

	/**
	* <blockquote style="font-family: arial; background-color:#EEEEEE">
	* Maximum scale to display map using a relative scale such as 1:24000. Scale can also be calculated
	* as the number of map units per pixel.
	* <p><sup>(ESRI)</sup></p></blockquote>
	* @brief Maximum scale to display map.
	* @class aimsLayer
	* @attribute public string Maxscale
	*/
	var $Maxscale;
	/**
	* <blockquote style="font-family: arial; background-color:#EEEEEE">
	* Minimum scale to display map using a relative scale such as 1:24000. Scale can also be
	* calculated as the number of map units per pixel.
	* <p><sup>(ESRI)</sup></p></blockquote>
	* @brief Minimum scale to display map.
	* @class aimsLayer
	* @attribute public string Minscale
	*/
	var $Minscale;
	/**
	* The type of the layer.
	* Possibilities are: {@link FEATURE_LAYER},{@link IMAGE_LAYER} or {@link ACETATE_LAYER}. This member
	* should not be changes!
	* @class aimsLayer
	* @attribute public string Type
	*/
	var $Type;
	/**
	* The coordinate system (projection) of the layer.
	* @class aimsLayer
	* @attribute public object Coordsys
	*/
	var $Coordsys;
	/**
	* The name of the layer.
	* Is used when displaying the legend of the map.
	* @class aimsLayer
	* @attribute public string Name
	*/
	var $Name;
	/**
	* Indicates if the layer is visible on the map or not.
	* @class aimsLayer
	* @attribute public bool IsVisible
	*/
	var $IsVisible;
	/**
	* The {@link aimsMap} to which the layer belongs.
	* @class aimsLayer
	* @attribute private string _map
	*/
	var $_map;
	/**
	* Creates an aimsLayer. Abstract.
	* @constructor aimsLayer
	* @package phparcims_layer
	* @abstract
	*/
	function &aimsLayer($name, &$map, $id, $min=0, $max=0) {
		$this->Name=$name;
		$this->_map=&$map;
		$this->IsVisible=TRUE;
		if ($id) {
			if ($map->getLayerByID($id,$l,$i)) {
				$map->setError(5451,'Layer with same ID exists already.');
				return FALSE;
			}
			$this->ID=$id;
		} else {
			$this->ID=$map->getMaxLayerID()+1;
		}
		if ($min) $this->Minscale=$min;
		if ($max) $this->Maxscale=$max;
		$map->Layers[]=&$this;
		$map->clearError();
		return TRUE;
	}

	/**
	* Return the full tag of the object as used/defined by ArcXML
	* @class aimsLayer
	* @method public returnTag
	* @param string Parent the name of the parent tag
	* @returns string The full tag with attributes and any possible sub-tags
	*/
	function returnTag($parent) {
		switch ($parent) {
		case 'GET_GEOCODE':
		case 'GET_FEATURES':
		case 'LAYERS':
			$TagStr='<LAYER id="'.$this->ID.'" />';
			break;
		case 'LAYERLIST';
			$TagStr = '<LAYERDEF id="'.$this->ID.'" ';
			$TagStr.=' name="'.$this->Name.'" ';
			$TagStr.=' visible="'.($this->IsVisible?'true':'false').'" >';
			break;
		case 'GET_EXTRACT':
		case 'MAP':
		case 'GET_IMAGE':
			$TagStr = '<LAYER id="'.$this->ID.'" ';
			$TagStr.='type="'.$this->Type.'" ';
			if (isset($this->Maxscale)) $TagStr.=' maxscale="'.$this->Maxscale.'" ';
			if (isset($this->Minscale)) $TagStr.=' minscale="'.$this->Minscale.'" ';
			$TagStr.=' name="'.$this->Name.'" ';
			$TagStr.=' visible="'.($this->IsVisible?'true':'false').'" >';
			break;
		}
		return $TagStr;
	}
}
/**
* A feature layer class can be used to create layers that contains
* points, lines, polygons, etc. In most cases
* @brief Class for feature layers objects.
* @class aimsFeatureLayer
* @package phparcims_layer
* @inherited aimsLayer
* @TODO sort out the extent thing (setEnvelope or have public attribute)
*/
class aimsFeatureLayer extends aimsLayer{
	/**
	* The {@link aimsEnvelope} of the layer.
	* @class aimsFeatureLayer
	* @attribute private object Extent
	*/
	var $Extent;
	/**
	* The {@link aimsRecordset} of the layer.
	* This can be used to get the definition of the fields in the attribute table and/or the
	* results of a query ({@link aimsMap::queryLayer}).
	* @class aimsFeatureLayer
	* @attribute public object Recordset
	*/
	var $Recordset;
	/**
	* @brief The feature type of the layer ({@link POINT_FEATURE}, {@link LINE_FEATURE} or {@link POLYGON_FEATURE}).
	* @class aimsFeatureLayer
	* @attribute public bool FeatureType
	*/
	var $FeatureType;

	/**
	* If TRUE highlights the result of the current query.
	* @class aimsFeatureLayer
	* @attribute public bool highlightQueryResult
	*/
	var $highlightQueryResult;

	var $_query;
	var $_renderer;
	var $_dataset;
	var $_selectionRenderer;

	/**
	* This method creates an aimsFeatureLayer in the {@link aimsMap} object Map. Use the
	* following code in case you want to modify the new object:<br>
	* <code> $newLayer = &new aimsFeatureLayer('New Layer',$myMap);
	* </code>
	* The refence ('&' ) is required, since otherwise you won't have a handle on the correct
	* object.
	* @brief Creates an aimsFeatureLayer in the {@link aimsMap} Map.
	* @constructor aimsFeatureLayer
	* @package phparcims_layer
	* @param string Name Name of the layer (used in legend display).
	* @param object Map The map to which the layer should be added.
	* @param optional int ID The service ID of the layer.
	* @param optional int Min The minium scale at which the layer should be displayed.
	* @param optional int Max The maximum scale at which the layer should be displayed.
	* @return bool TRUE if layer was created, FALSE otherwise.
	*/
	function aimsFeatureLayer($name, &$map, $id='', $min=0, $max=0) {
		$this->Type=FEATURE_LAYER;
		$this->Recordset=new aimsRecordset($this);
		$this->highlightQueryResult=FALSE;
		return parent::aimsLayer($name, $map, $id, $min=0, $max=0);
	}

	/**
	* You want to clone a featurelayer in case you want to want to display another version
	* of the layer were only certan features are selected. In this case you would clone the layer
	* and specify a {@link aimsAttributeQuery} or a {@link aimsSpatialQuery}.
	* @brief Clones a featurelayer.
	* @class aimsFeatureLayer
	* @method public clone
	* @param string Name The name for the new layer.
	* @param optional int ID THe service ID to be used for the new layer.
	* @return object Reference to the cloned featurelayer. FALSE if feature object couldn't be cloned.
	*/
	function &clone($name, $id='') {
		if (!($clone =  new aimsFeatureLayer($name, $this->_map, $id))) return FALSE;
		if (!($dataset=new aimsDataset(DS_CLONE,$this))) return FALSE;
		if (!($clone->setDataset($dataset))) return FALSE;
		return $clone;
	}

	/**
	* This method is currently of no use, since it's used only when configuring a mapservice.
	* @class aimsFeatureLayer
	* @method public setDataset
	* @param object Dataset The dataset used for the layer.
	* @return bool TRUE if dataset was valid. FALSE otherwise.
	*/
	function setDataset($d) {
		if (is_a($d,'aimsDataset')) {
			$this->_dataset=$d;
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsDataset.');
		return FALSE;
	}
	/**
	* While the extent of a layer can be set, it had no effect when requesting
	* images from the server.
	* @brief Set the extent of the layer.
	* @class aimsFeatureLayer
	* @method public setExtent
	* @param object theExtent The new extent of the layer.
	* @return bool TRUE if extent was set. FALSE otherwise.
	*/
	function setExtent($e) {
		if (is_a($e,'aimsEnvelope')) {
			$this->Extent=$e;
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsEnvelope.');
		return FALSE;
	}
	/**
	* Returns the extent of the layer
	* @class aimsFeatureLayer
	* @method public getExtent
	* @return object The extent of the layer.
	*/
	function getExtent() {
		return $this->Extent;
	}
	/**
	* Sets the query/filter on the layer. The query can be an {@link aimsAttributeQuery} or
	* an {@link aimsSpatialQuery}.
	* @brief Sets the query/filter on the layer.
	* @class aimsFeatureLayer
	* @method public setQuery
	* @param object Query The query/filter.
	* @return bool TRUE if query was set, FALSE otherwise.
	*/
	function setQuery($q) {
		if (is_a($q,'aimsQuery')) {
			$this->_query=$q;
			switch ($this->FeatureType) {
			case POINT_FEATURE:
				$s=new aimsSimpleMarkerSymbol();
				$s->Color=array(255,255,0);
				$s->Outline=array(0,0,0);
				break;
			case LINE_FEATURE:
				$s=new aimsSimpleLineSymbol();
				$s->Color=array(255,255,0);
				break;
			case POLYGON_FEATURE:
				$s = new aimsSimplePolygonSymbol();
				$s->Fillcolor=array(255,0,0);
				$s->Filltransparency=0.5;
				$s->Boundarycolor=array(255,255,0);
				break;
			}
			$r=new aimsRenderer($s);
			$this->_selectionRenderer=$r;
			$this->_map->clearError();
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsGeneralQuery.');
		return FALSE;
	}

	/**
	* Removes the currently define query (filter) for the layer.
	* @brief Removes the currently defined query for the layer.
	* @class aimsFeatureLayer
	* @method public removeQuery
	*/
	function removeQuery(){
		unset($this->_query);
	}

	/**
	* Sets renderer for a layer
	* @class aimsFeatureLayer
	* @method public setRenderer
	* @param object Renderer Renderer for layer.
	* @return bool TRUE if renderer was set successfully, otherwise FALSE.
	*/
	function setRenderer ($r) {
		if (is_a('aimsRenderer',$r)) {
			$this->_renderer=$r;
			$this->_map->clearError();
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsRenderer.');
		return FALSE;
	}

	/**
	* Returns the renderer of the feature layer.
	* @class aimsFeatureLayer
	* @method public getRenderer
	* @return ref object The renderer.
	*/
	function &getRenderer() {
		return $this->_renderer;
	}

	/**
	* Removes the renderer of the feature layer. The default renderer is used again.
	* @class aimsFeatureLayer
	* @method public removeRenderer
	*/
	function removeRenderer($name) {
		unset($this->_renderer);
	}

	/**
	* Sets the renderer to be used when features are selected.
	* Before the renderer is actually used, the {@link aimsFeatureLayer::highlightQueryResult}
	* needs to be set to TRUE.
	* @class aimsFeatureLayer
	* @method public setSelectionRenderer
	* @param object Renderer The renderer to be used.
	* @return bool TRUE if renderer was set successfully, otherwise FALSE.
	*/
	function setSelectionRenderer($r) {
		if (is_a('aimsRenderer',$r)) {
			$this->_selectionRenderer=$r;
			$this->_map->clearError();
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsRenderer.');
		return FALSE;
	}
	/**
	* Returns the selection renderer of the feature layer.
	* @class aimsFeatureLayer
	* @method public getSelectionRenderer
	* @return ref object The selection renderer.
	*/
	function &getSelectionRenderer() {
		return $this->_selectionRenderer;
	}

	/**
	* Removes the selection renderer of the feature layer.
	* @class aimsFeatureLayer
	* @method public removeSelectionRenderer
	*/
	function removeSelectionRenderer($name) {
		unset($this->_selectionRenderer);
	}


	/**
	* Return the full tag of the object as used/defined by ArcXML
	* @class aimsFeatureLayer
	* @method public returnTag
	* @param string Parent the name of the parent tag
	* @returns string The full tag with attributes and any possible sub-tags
	*/
	function returnTag($parent=''){
		printDebug('[aimsFeatureLayer.returnTag]',2);
		if (($parent=='GET_IMAGE'||$parent=='GET_EXTRACT') && !$this->_dataset) {
			return '';
		}
		$TagStr=parent::returnTag($parent);

		switch ($parent) {
		case 'GET_FEATURES':
		case 'GET_GEOCODE':
		case 'LAYERS':
			printDebug('[aimsLayer.returnTag] get_features 1',1);
			//$TagStr.='</LAYER>';
			$TagStr.=$this->_query->returnTag($parent);
			break;
		case 'LAYERLIST':
			if (isset($this->_query)) {
				$TagStr.=$this->_query->returnTag('LAYER');
				if ($this->highlightQueryResult) $TagStr.=$this->_selectionRenderer->returnTag('LAYER');
			}
			if (isset($this->_renderer)) $TagStr.=$this->_renderer->returnTag('LAYER');
			$TagStr.='</LAYERDEF>';
			break;
		case 'GET_IMAGE':
		case 'GET_EXTRACT':
			if (isset($this->_dataset)) {
				$TagStr.=$this->_dataset->returnTag('LAYER');
			}
			if (isset($this->Coordsys)) $TagStr.=$this->Coordsys->returnTag('LAYER');
//			if (isset($this->_query)) $TagStr.=$this->_query->returnTag('LAYER');
			if (isset($this->_query)) {
				$TagStr.=$this->_query->returnTag('LAYER');
				if ($this->highlightQueryResult) $TagStr.=$this->_selectionRenderer->returnTag('LAYER');
			}
			if (isset($this->_renderer)) $TagStr.=$this->_renderer->returnTag('LAYER');
			$TagStr.='</LAYER>';
		}
		return $TagStr;
	}

}

/**
* @class aimsImageLayer
* @package phparcims_layer
* @inherited aimsLayer
* @TODO sort out the extent thing (setEnvelope or have public attribute)
*/
class aimsImageLayer extends aimsLayer {
	var $Transparency;
	var $TransparentColor;
	/**
	* The extent of the layer.
	* @class aimsImageLayer
	* @attribute private object Extent
	*/
	var $Extent;
	var $_dataset;

	/**
	* This method creates the shell for an aimsImageLayer in the {@link aimsMap} object Map. Use the
	* following code in case you want to modify the new object:<br>
	* <code> $newLayer = &new aimsFeatureLayer('New Layer',$myMap);
	* </code>
	* The refence ('&' ) is required, since otherwise you won't have a handle on the correct
	* object.
	* @brief Creates an aimsImageLayer in the {@link aimsMap} Map.
	* @constructor aimsImageLayer
	* @package phparcims_layer
	* @param string Name Name of the layer (will be displayed in the legend).
	* @param object Map The map to which the layer should be added.
	* @param optional int ID The service ID of the layer (save to leave out).
	* @param optional int Min The minium scale at which the layer should be displayed.
	* @param optional int Max The maximum scale at which the layer should be displayed.
	* @return bool TRUE if layer was created, FALSE otherwise.
	*/
	function aimsImageLayer($name, &$map, $id='', $min=0, $max=0) {
		$this->Type=IMAGE_LAYER;
		return parent::aimsLayer($name, $map, $id, $min=0, $max=0);
	}
	/**
	* You want to clone a imagelayer in case you want to want to display another version of it.
	* @brief Clones a image layer.
	* @class aimsImageLayer
	* @method public clone
	* @param string Name The name for the new layer.
	* @param optional int ID THe service ID to be used for the new layer.
	* @return object Reference to the cloned featurelayer. FALSE if feature object couldn't be cloned.
	*/
	function &clone($name, $id='') {
		if (!($clone =  new aimsImageLayer($name, $this->_map, $id))) return FALSE;
		if (!($dataset=new aimsDataset(DS_CLONE,$this))) return FALSE;
		if (!($clone->setDataset($dataset))) return FALSE;
		return $clone;
	}

	/**
	* This method is currently of no use, since it's used only when configuring a mapservice.
	* @class aimsImageLayer
	* @method public setDataset
	* @param object Dataset The dataset used for the layer.
	* @return bool TRUE if dataset was valid. FALSE otherwise.
	*/
	function setDataset($d) {
		if (is_a($d,'aimsDataset')) {
			$this->_dataset=$d;
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsDataset.');
		return FALSE;
	}
	/**
	* While the extent of a layer can be set, it had no effect when requesting
	* images from the server.
	* @brief Set the extent of the layer.
	* @class aimsImageLayer
	* @method public setExtent
	* @param object theExtent The new extent of the layer.
	* @return bool TRUE if extent was set. FALSE otherwise.
	*/
	function setExtent($e) {
		if (is_a($e,'aimsEnvelope')) {
			$this->Extent=$e;
			return TRUE;
		}
		$this->_map->setError(5410,'The supplied object is not of type aimsEnvelope.');
		return FALSE;
	}
	/**
	* Returns the extent of the layer
	* @class aimsImageLayer
	* @method public getExtent
	* @return object The extent of the layer.
	*/
	function getExtent() {
		return $this->Extent;
	}
	/**
	* Return the full tag of the object as used/defined by ArcXML
	* @class aimsImageLayer
	* @method public returnTag
	* @param string Parent the name of the parent tag
	* @returns string The full tag with attributes and any possible sub-tags
	*/
	function returnTag($parent=''){
		printDebug('[aimsImageLayer.returnTag]',2);
		if ($parent=='GET_IMAGE' && !$this->_dataset) {
			return '';
		}
		$TagStr=parent::returnTag($parent);

		switch ($parent) {
		case 'GET_FEATURES':
		case 'GET_GEOCODE':
		case 'LAYERS':
			break;
		case 'LAYERLIST':
			$TagStr.='</LAYERDEF>';
			break;
		case 'GET_IMAGE':
			if (isset($this->_dataset)) $TagStr.=$this->_dataset->returnTag('LAYER');
			if (isset($this->Coordsys)) $TagStr.=$this->Coordsys->returnTag('LAYER');
			$TagStr.='<IMAGEPROPERTIES ';
			if (isset($this->Transparency)) $TagStr.='transparency="'.$this->Transparency.'" ';
			if (isset($this->TransparentColor)) $TagStr.='transcolor="'.$this->TransparentColor.'" ';
			$TagStr.='></IMAGEPROPERTIES></LAYER>';
			break;
		default:
			$TagStr.='';
		}
		return $TagStr;
	}

}

/**
* @class aimsAcetateLayer
* @package phparcims_layer
* @inherited aimsLayer
*/
class aimsAcetateLayer extends aimsLayer {
	var $Objects;

	/**
	* This method creates the shell for an aimsAcetateLayer in the {@link aimsMap} object Map.
	* Before it can be used a workspace as well as the dataset name must be specified.
	* @brief Creates an aimsImageLayer in the {@link aimsMap} Map.
	* @constructor aimsAcetateLayer
	* @package phparcims_layer
	* @param string Name Name of the layer (will be displayed in the legend).
	* @param object Map The map to which the layer should be added.
	* @param optional int ID The service ID of the layer (save to leave out).
	* @return bool TRUE if layer was created, FALSE otherwise.
	*/
	function aimsAcetateLayer($name, &$map, $id=0) {
		$this->Type=ACETATE_LAYER;
		return parent::aimsLayer($name, $map, $id);
	}

	/**
	* In order to add individual points, lines, north arrow, etc. This works only with
	* acetate layers. See {@link aimsObject} for more info about object that can be added.
	* <p><b>Note</b>: in case a specific object will be removed later on, the object should have
	* a name ({@link aimsObject::Name}). In case it doesn't have a name, the method will provide
	* its own name which is based on an internal, sequential number.
	* @brief Adds an object to an acetate layer
	* @class aimsAcetateLayer
	* @method public addObject
	* @param object Object The object to be added
	* @return boolean True if object was added, False otherwise
	*/
	function addObject($obj) { //,$u,$low=0,$up=0, $name='', $coord='') {
		if (!is_a($obj,'aimsObject')) {
			$this->_map->setError(5410,'The supplied object is not of type aimsEnvelope.');
			return FALSE;
		}
		if ($obj->Name) {
			$this->Objects[$obj->Name]=$obj;
		}else{
			$this->Objects[strval($this->ObjectID)]=$obj;
			$obj->Name=$this->ObjectID;
		}
		$this->ObjectID++;
		return TRUE;
	}

	/**
	* Removes an object from the acetate layer. The object is identified by
	* its name. In case the object does not have a name, you can provide the index
	* of the object to remove.
	* @brief Remove an object from an acetate layer
	* @class aimsAcetateLayer
	* @method public removeObject
	* @param string Name Name of the object
	* @return boolean True if object was removed, False otherwise
	*/
	function removeObject($name) {
		if ($this->Type==3) {
			if (count($this->Objects)>0) {
				if (array_key_exists($name,$this->Objects)) {
					unset($this->Objects[$name]);
					return TRUE;
				}
			}
		}
		return FALSE;
	}

	/**
	* Returns a refernce to an object in the layer. The object is identified
	* by its name.
	* @brief Returns an object from the acetate layer.
	* @class aimsAcetateLayer
	* @method public getObject
	* @param string Name Name of the object
	* @return ref mixed Reference to object if it was found, False otherwise
	*/
	function &getObject($name) {
		if (count($this->Objects)>0) {
			if (array_key_exists($name,$this->Objects)) {
				return $this->Objects[$name];
			}
		}
		return FALSE;
	}

	/**
	* Return the full tag of the object as used/defined by ArcXML
	* @class aimsAcetateLayer
	* @method public returnTag
	* @param string Parent the name of the parent tag
	* @returns string The full tag with attributes and any possible sub-tags
	*/
	function returnTag($parent=''){
		if (count($this->Objects)==0) return '';
		printDebug('[aimsAcetateLayer.returnTag]',2);
		$tagStr=parent::returnTag($parent);
		switch ($parent) {
		case 'LAYERS':
		case 'GET_IMAGE':
			foreach ($this->Objects as $oName => $object) {
				$tagStr.= $object->returnTag($parent);
			}
			break;
		default:
			return '';
		}
		return $tagStr.'</LAYER>';
	}
}

?>
Return current item: PhpArcIMS