getElementsByTagName('map-source'); $layersToIdentify = array(); for($i = 0; $i < $msXML->length; $i++) { $node = $msXML->item($i); $file = $node->getElementsByTagName('file'); $layers = $node->getElementsByTagName('layer'); $msType = strtolower($node->getAttribute('type')); $queryable = false; if($node->hasAttribute('queryable')) { $queryable = parseBoolean($node->getAttribute('queryable')); } else { if($msType == 'mapserver') { $queryable = true; } else if($msType == 'wms') { $queryable = false; } } if($queryable) { for($l = 0; $l < $layers->length; $l++) { $layer = $layers->item($l); $path = $node->getAttribute('name').'/'.$layer->getAttribute('name'); $identify = false; foreach($layersList as $ll) { if($path == $ll) { $identify = true; } } if($identify == true) { $nodeName = 'file'; $params = ''; if($msType == 'wms') { $nodeName = 'url'; $paramElms = $node->getElementsByTagName('param'); foreach($paramElms as $p) { $params = $params . '&' . $p->getAttribute('name') . '=' . $p->getAttribute('value'); } } array_push($layersToIdentify, $msType.':'.$layer->getAttribute('name').':'.$node->getElementsByTagName($nodeName)->item(0)->nodeValue.$params); } } } } # Setup the Query Shape $queryShape = ms_shapeObjFromWkt($shape); # Generate the HTML from the Identify Function $substArray = array(); $content = ''; if($queryShape->type == MS_SHAPE_POINT) { $point = $queryShape->line(0)->point(0); $substArray['mapx'] = $point->x; $substArray['mapy'] = $point->y; } # Needed WMS Information $wmsBBOX = ($point->x - 100). ',' . ($point->y - 100) . ',' . ($point->x + 100) . ',' . ($point->y + 100); $wmsHeaderTemplate = implode('', file($CONFIGURATION['wms_header'])); $wmsRecordTemplate = implode('', file($CONFIGURATION['wms_record'])); $wmsFooterTemplate = implode('', file($CONFIGURATION['wms_footer'])); foreach($layersToIdentify as $mf) { $info = explode(':', $mf); if($info[0] == 'mapserver') { $path = $info[2]; if(substr($path,0,1) == '.') { $path = $CONFIGURATION['root'].$path; } $map = ms_newMapObj($path); //LK This set the map size and extent so pixel tolerance finally works. Also need to set in service in mapbook, maybe we should just always send extent and map size with services? if($_REQUEST['map_size']) { $map_size = explode(',',$_REQUEST['map_size']); $map->setSize($map_size[0],$map_size[1]); } if($_REQUEST['extent']) { $map_extent = explode(',',$_REQUEST['extent']); $map->setExtent($map_extent[0],$map_extent[1],$map_extent[2],$map_extent[3]); } for($i = 0; $i < $map->numlayers; $i++) { $layer = $map->getLayer($i); if($info[1] == 'all' || $info[1] == $layer->name) { $layer->set('status', MS_DEFAULT); $layer->set('template', $layer->getMetaData('identify_record')); $max_features = $layer->getMetaData('identify_max_features'); if($max_features) { $layer->set('maxfeatures', $max_feautres); } } else { $layer->set('status', MS_OFF); } // this is used for layers with attribute data also in Postgres $identify_record2 = $layer->getMetaData('identify_record2'); if($identify_record2) { $resultFeatures = array(); $point = $queryShape->line(0)->point(0); $map->queryByPoint($point, MS_MULTIPLE, -1); $layer->open(); $numResults = $layer->getNumResults(); $res = array(); if($numResults > 0) { $res = $layer->getResult(0); $firstResult = $layer->getFeature($res->shapeindex); for($rx = 0; $rx < $numResults; $rx++) { $result = $layer->getFeature($res->shapeindex)->values; $activity = array(); $sql = "SELECT * FROM restoration_activity WHERE project_id = '" . $result['ProjectID'] . "'"; $query = pg_query($dbconn,$sql); $activity = pg_fetch_all($query); $result['activity_table'] = $activity; $cost = array(); $sql = "SELECT * FROM cost WHERE project_id = '" . $result['ProjectID'] . "'"; $query = pg_query($dbconn,$sql); $cost = pg_fetch_all($query); $result['cost_table'] = $cost; } array_push($resultFeatures, $result); // The path has the MAP file name, so find the last backslash and remove the MAP file from the string $pos = strripos($path, "/"); // Now add the template HTML to the remaining path $path = substr($path, 0, $pos+1); // Open the template and replace the tags with values $identify_record = $path . $layer->getMetaData('identify_record'); $temp = fopen($identify_record,"r"); $template = fread($temp, filesize($identify_record)); foreach($resultFeatures as $k) { $results = $results . processTemplate($template, $k); $identify_record2 = $path . $layer->getMetaData('identify_record2'); $temp2 = fopen($identify_record2,"r"); $template2 = fread($temp2, filesize($identify_record2)); foreach($k['activity_table'] as $key) { $results = $results . processTemplate($template2, $key); } $identify_record3 = $path . $layer->getMetaData('identify_record3'); $temp3 = fopen($identify_record3,"r"); $template3 = fread($temp3, filesize($identify_record3)); foreach($k['cost_table'] as $key) { $results = $results . processTemplate($template3, $key); } } } $layer->set('status', OFF); } } if($queryShape->type == MS_SHAPE_POINT) { $point = $queryShape->line(0)->point(0); $map->queryByPoint($point, MS_MULTIPLE, -1); $substArray['mapx'] = $point->x; $substArray['mapy'] = $point->y; } else { $map->queryByShape($queryShape); } $results = $results . $map->processquerytemplate(array(), false); $content = $results; } else if($info[0] == 'wms') { $wmsUrl = $info[2].'&SERVICE=WMS&VERSION=1.1.0&REQUEST=GetFeatureInfo&WIDTH=100&HEIGHT=100&X=50&Y=50&EXCEPTIONS=application/vnd.ogc.se_xml&LAYERS='.$info[1].'&QUERY_LAYERS='.$info[1].'&BBOX='.$wmsBBOX.'&SRS='.$projection.'&STYLES=&INFO_FORMAT=application/vnd.ogc.gml'; #print ' WMS Link
'; # Resolve the url if relative $firstCh = substr($wmsUrl, 0, 1); if($firstCh == '/') { $wmsUrl = 'http://localhost'.$wmsUrl; } else { # Return an error here once error handling has been created. } # Fetch the GML $curlHandle = curl_init($wmsUrl); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); $gml = curl_exec($curlHandle); curl_close($curlHandle); # Now Parse the GML according to the gml_template $results = ''; $gmlDoc = new DOMDocument(); $gmlDoc->loadXML($gml); $gmlLayers = $gmlDoc->documentElement->childNodes; foreach($gmlLayers as $layer) { if($layer->childNodes->length > 0) { foreach($layer->childNodes as $feature) { $splitPos = strpos($feature->tagName, '_feature'); $featureDict = array(); if(!($splitPos === false)) { $featureDict['FEATURE_TITLE'] = substr($feature->tagName, 0, $splitPos-1); $featureLines = array(); $results = $results . processTemplate($wmsHeaderTemplate, $featureDict); foreach($feature->childNodes as $attr) { if(substr($attr->tagName, 0, 3) != 'gml') { $featureDict['NAME'] = str_replace('_', ' ', $attr->tagName); $featureDict['VALUE'] = $attr->firstChild->nodeValue; $results = $results . processTemplate($wmsRecordTemplate, $featureDict); } } $featureDict['NAME'] = ''; $featureDict['VALUE'] = ''; $results = $results . processTemplate($wmsFooterTemplate, $featureDict); } } } } $content = $content . $results; } } //LK This converts the coordinates to lat/lon and sends them to the mapserver template $clonePoint = $point; $projOutObj = ms_newprojectionobj("proj=latlong"); $projInObj = ms_newprojectionobj("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"); $clonePoint->project($projInObj, $projOutObj); $substArray['lng'] = round($clonePoint->x,4); $substArray['lat'] = round($clonePoint->y,4); $headerArray = file($CONFIGURATION['identify_header']); $footerArray = file($CONFIGURATION['identify_footer']); $contents = implode('', array_merge($headerArray, array($content), $footerArray)); header('Content-type: application/xml'); print ""; print "