"; if (!isset($mapName)) { die('mapname not set'); } if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) { $oMap = ms_newMapObj($_SESSION['maps'][$mapName]); } /* add the spatial filter if provided. It is expected to come as a WKT string, so we need to convert it to a shape */ if ($spatialFilter !== false ) { $oSpatialFilter = ms_shapeObjFromWkt($spatialFilter); } $oLayer = $oMap->GetLayerByName($layer); $oLayer->set('tolerance', 0); if ($oLayer->type == MS_LAYER_RASTER || $oLayer->type == MS_LAYER_QUERY || $oLayer->type == MS_LAYER_CIRCLE || $oLayer->type == MS_LAYER_CHART) { die('maptips are only valid for vector layers'); } //header('Content-type: text/x-json'); //header('X-JSON: true'); if (@$oLayer->queryByShape($oSpatialFilter) == MS_SUCCESS) { $oRes = $oLayer->getResult(0); $oLayer->open(); $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex); $mapTipLink = buildCustonUrl($oShape->values,$mapTipURL); /*if (isset($mapTipLinkField)){ $mapTipLink = $oShape->getValue($oLayer, $mapTipLinkField); }*/ echo "{mapTipText :'"; echo $oShape->values[$mapTipTextField]; echo "',mapTipLink:'"; echo $mapTipLink; echo "'}"; }else{ echo "{mapTipText: '', mapTipLink: ''}"; } $oLayer->close(); function buildCustonUrl($aValues,$url){ $pattern = "/\[(.+?)\]/"; preg_match_all($pattern, $url, $values,PREG_PATTERN_ORDER); if(is_array($values[0])){ foreach($values[0] as $key=>$item){ $url = str_replace($item,$aValues[$values[1][$key]],$url); } } return $url; } ?>