Ejemplo n.º 1
0
function normalizedBoundingBox($center, $tolerance, $fromProj = null, $toProj = null)
{
    if ($fromProj !== null || $toProj !== null) {
        $projector = new MapProjector();
    }
    // create the bounding box in lat/lon first
    if ($fromProj !== null) {
        $projector->setSrcProj($fromProj);
        $center = $projector->projectPoint($center);
    }
    // approximate upper/lower bounds for lat/lon before calculating GCD
    $dLatRadians = $tolerance / EARTH_RADIUS_IN_METERS;
    // by haversine formula
    $dLonRadians = 2 * asin(sin($dLatRadians / 2) / cos($center['lat'] * M_PI / 180));
    $dLatDegrees = $dLatRadians * 180 / M_PI;
    $dLonDegrees = $dLonRadians * 180 / M_PI;
    $min = array('lat' => $center['lat'] - $dLatDegrees, 'lon' => $center['lon'] - $dLonDegrees);
    $max = array('lat' => $center['lat'] + $dLatDegrees, 'lon' => $center['lon'] + $dLonDegrees);
    if ($toProj !== null) {
        $projector->setSrcProj(GEOGRAPHIC_PROJECTION);
        $projector->setDstProj($toProj);
        $min = $projector->projectPoint($min);
        $max = $projector->projectPoint($max);
    }
    return array('min' => $min, 'max' => $max, 'center' => $center);
}
Ejemplo n.º 2
0
 public function init($args)
 {
     $this->baseURL = $args['BASE_URL'];
     $this->diskCache = new DiskCache(Kurogo::getSiteVar('WMS_CACHE', 'maps'), 86400 * 7, true);
     $this->diskCache->preserveFormat();
     $filename = md5($this->baseURL);
     $metafile = $filename . '-meta.txt';
     if (!$this->diskCache->isFresh($filename)) {
         $params = array('request' => 'GetCapabilities', 'service' => 'WMS');
         $query = $this->baseURL . '?' . http_build_query($params);
         file_put_contents($this->diskCache->getFullPath($metafile), $query);
         $contents = file_get_contents($query);
         $this->diskCache->write($contents, $filename);
     } else {
         $contents = $this->diskCache->read($filename);
     }
     $this->wmsParser = new WMSDataParser();
     $this->wmsParser->parseData($contents);
     $this->enableAllLayers();
     // TODO make sure this projection is supported by the server
     $projections = $this->wmsParser->getProjections();
     if (count($projections)) {
         // make sure this is a projection we can handle
         foreach ($projections as $proj) {
             $contents = MapProjector::getProjSpecs($proj);
             if ($contents) {
                 $this->setMapProjection($proj);
             }
         }
     } else {
         $this->setMapProjection(GEOGRAPHIC_PROJECTION);
     }
 }
Ejemplo n.º 3
0
 public static function updateCategory(MapFolder $category, $items, $projection = null, $parentCategoryId = null)
 {
     $categoryId = $category->getId();
     $name = $category->getTitle();
     $description = $category->getSubtitle();
     $isStored = $category instanceof MapDBCategory && $category->isStored();
     if (!$isStored) {
         $sql = 'SELECT * FROM ' . self::CATEGORY_TABLE . ' WHERE category_id=?';
         $params = array($categoryId);
         $results = self::connection()->query($sql, $params);
         if ($results->fetch()) {
             $isStored = true;
         }
     }
     if (!$isStored) {
         if ($parentCategoryId === null) {
             $sql = 'INSERT INTO ' . self::CATEGORY_TABLE . ' (category_id, name, description) VALUES (?, ?, ?)';
             $params = array($categoryId, $name, $description);
         } else {
             $sql = 'INSERT INTO ' . self::CATEGORY_TABLE . ' (category_id, name, description, parent_category_id) VALUES (?, ?, ?, ?)';
             $params = array($categoryId, $name, $description, $parentCategoryId);
         }
     } else {
         if ($parentCategoryId === null) {
             $sql = 'UPDATE ' . self::CATEGORY_TABLE . '   SET name=?, description=? WHERE category_id=?';
             $params = array($name, $description, $categoryId);
         } else {
             $sql = 'UPDATE ' . self::CATEGORY_TABLE . '   SET name=?, description=?, parent_category_id=? WHERE category_id=?';
             $params = array($name, $description, $parentCategoryId, $categoryId);
         }
     }
     self::connection()->query($sql, $params);
     if ($projection === null || $projection instanceof MapProjector) {
         $projector = $projection;
     } else {
         $projector = new MapProjector();
         $projector->setSrcProj($projection);
     }
     foreach ($items as $item) {
         if ($item instanceof MapFolder) {
             self::updateCategory($item, $item->getListItems(), $projector, $categoryId);
         } elseif ($item instanceof Placemark) {
             self::updateFeature($item, $categoryId, $projector);
         }
     }
 }
Ejemplo n.º 4
0
    protected function getCurrentScale()
    {
        if ($this->unitsPerMeter === null) {
            $contents = MapProjector::getProjSpecs($this->mapProjection);

            if (preg_match('/to_meter=([\d\.]+)/', $contents, $matches)) {
                $this->unitsPerMeter = 1 / $matches[1];
            } else {
                $this->unitsPerMeter = self::NO_PROJECTION;
            }
        }
        if ($this->unitsPerMeter != self::NO_PROJECTION) {
            $metersPerPixel = $this->getHorizontalRange() / $this->imageWidth / $this->unitsPerMeter;
            return $metersPerPixel / self::LIFE_SIZE_METERS_PER_PIXEL;
        } else {
            // TODO this isn't quite right, this won't allow us to use
            // maxScaleDenom and minScaleDenom in any layers
            return self::NO_PROJECTION;
        }
    }
Ejemplo n.º 5
0
    private function initializeMap(MapDataController $dataController, MapFeature $feature, $fullscreen=FALSE) {
        
        $MapDevice = new MapDevice($this->pagetype, $this->platform);
        $style = $feature->getStyle();
        $geometries = array();
        
        $geometries[] = $feature->getGeometry();

        // zoom
        if (isset($this->args['zoom'])) {
            $zoomLevel = $this->args['zoom'];
        } else {
            $zoomLevel = $dataController->getDefaultZoomLevel();
        }

        if ($MapDevice->pageSupportsDynamicMap() && $dataController->supportsDynamicMap()) {
            $imgController = $dataController->getDynamicMapController();
        } else {
            $imgController = $dataController->getStaticMapController();
        }

        if ($imgController->supportsProjections()) {
            $imgController->setDataProjection($dataController->getProjection());
        } else {
            $dataProjection = $dataController->getProjection();
            $outputProjection = $imgController->getMapProjection();
            if ($dataProjection != $outputProjection) {
                $projector = new MapProjector();
                $projector->setSrcProj($dataProjection);
                $projector->setDstProj($outputProjection);
                foreach ($geometries as $i => $geometry) {
                    $geometries[$i] = $projector->projectGeometry($geometry);
                }
            }
        }
        
        if (isset($this->args['lat'], $this->args['lon'])) {
            array_unshift($geometries, new EmptyMapPoint($this->args['lat'], $this->args['lon']));
        }
        
        // center
        if (isset($this->args['center'])) {
            $latlon = explode(",", $this->args['center']);
            $center = array('lat' => $latlon[0], 'lon' => $latlon[1]);
        } else {
            $center = $geometries[0]->getCenterCoordinate();
        }

        $imgController->setCenter($center);
        $imgController->setZoomLevel($zoomLevel);

        foreach ($geometries as $i => $geometry) {
            if ($geometry instanceof MapPolygon) {
                if ($imgController->canAddPolygons()) {
                    $imgController->addPolygon($geometry->getRings(), $style);
                }
            } elseif ($geometry instanceof MapPolyline) {
                if ($imgController->canAddPaths()) {
                    $imgController->addPath($geometry->getPoints(), $style);
                }
            } else {
                if ($imgController->canAddAnnotations()) {
                    $imgController->addAnnotation($geometry->getCenterCoordinate(), $style, $feature->getTitle());
                }
            }
        }

        if (!$fullscreen) {
            $this->assign('fullscreenURL', $this->buildBreadcrumbURL('fullscreen', $this->args, false));
        
            if ($imgController->isStatic()) {
                list($imageWidth, $imageHeight) = $MapDevice->staticMapImageDimensions();

            } else {
                list($imageWidth, $imageHeight) = $MapDevice->dynamicMapImageDimensions();
                $this->addInlineJavascriptFooter("\n hideMapTabChildren();\n");
            }
            
        } else {
            $this->assign('detailURL', $this->buildBreadcrumbURL('detail', $this->args, false));
            if ($imgController->isStatic()) {
                list($imageWidth, $imageHeight) = $MapDevice->staticMapImageDimensions();

            } else {
                list($imageWidth, $imageHeight) = $MapDevice->fullscreenMapImageDimensions();
                $this->addJavascriptFullscreenDynamicMap();
            }
        }
        
        $this->assign('fullscreen', $fullscreen);
        $this->assign('isStatic', $imgController->isStatic());
        
        $this->initializeMapElements('mapimage', $imgController, $imageWidth, $imageHeight);

        // call the function that updates the image size        
        if ($fullscreen && $imgController->isStatic()) {
            $this->addJavascriptFullscreenStaticMap();
        }
    }
Ejemplo n.º 6
0
 private function getProjectedBBox()
 {
     $bbox = $this->getBoundingBox();
     $northeast = array('lat' => $bbox['ymax'], 'lon' => $bbox['xmax']);
     $southwest = array('lat' => $bbox['ymin'], 'lon' => $bbox['xmin']);
     if ($this->mapProjector) {
         $northeast = $this->mapProjector->projectPoint($northeast, MapProjector::FORMAT_LATLON);
         $southwest = $this->mapProjector->projectPoint($southwest, MapProjector::FORMAT_LATLON);
     }
     list($bbox['xmin'], $bbox['ymin'], $fmt) = MapProjector::getXYFromPoint($southwest);
     list($bbox['xmax'], $bbox['ymax'], $fmt) = MapProjector::getXYFromPoint($northeast);
     return $bbox;
 }
Ejemplo n.º 7
0
 function getFooterScript()
 {
     $zoomLevel = $this->zoomLevel;
     $targetScale = oldPixelScaleForZoomLevel($zoomLevel);
     if ($this->levelsOfDetail) {
         // TODO: if all zoom levels fail this test, the zoom level will
         // revert to the internal powers-of-two style zoom level i.e. not
         // necessarily what we want
         foreach ($this->levelsOfDetail as $levelData) {
             if ($levelData['scale'] < $targetScale) {
                 break;
             } else {
                 $zoomLevel = $levelData['level'];
             }
         }
     }
     $moreLayers = array();
     foreach ($this->moreLayers as $layer) {
         $moreLayers[] = '"' . $layer . '"';
     }
     $footer = $this->prepareJavascriptTemplate('ArcGISJSMapFooter');
     $footer->setValues(array('___WKID___' => $this->mapProjection, '___MAPELEMENT___' => $this->mapElement, '___IMAGE_WIDTH___' => $this->imageWidth, '___IMAGE_HEIGHT___' => $this->imageHeight, '___ZOOMLEVEL___' => $zoomLevel, '___BASE_URL___' => $this->baseURL, '___MORE_LAYER_SCRIPT___' => '[' . implode(',', $moreLayers) . ']', '___MARKER_SCRIPT___' => $this->getMarkerJS(), '___POLYGON_SCRIPT___' => $this->getPolygonJS(), '___PATH_SCRIPT___' => $this->getPathJS()));
     if ($this->mapProjector) {
         $xy = $this->mapProjector->projectPoint($this->center);
         list($x, $y) = MapProjector::getXYFromPoint($xy);
         $footer->setValues(array('___X___' => $x, '___Y___' => $y));
     } else {
         $footer->setValues(array('___X___' => $this->center['lon'], '___Y___' => $this->center['lat']));
     }
     return $footer->getScript();
 }
Ejemplo n.º 8
0
 public function initializeForCommand()
 {
     if ($projection = $this->getArg('projection')) {
         $this->mapProjector = new MapProjector();
         $this->mapProjector->setDstProj($projection);
     }
     switch ($this->command) {
         case 'index':
             $categories = array();
             $response = array('displayType' => $this->getModuleDisplayType());
             $groups = $this->getFeedGroups();
             if ($groups) {
                 foreach ($groups as $id => &$groupData) {
                     if (isset($groupData['center'])) {
                         $latlon = filterLatLon($groupData['center']);
                         $groupData['lat'] = $latlon['lat'];
                         $groupData['lon'] = $latlon['lon'];
                     }
                     $groupData['id'] = $id;
                     $categories[] = $groupData;
                 }
                 $response['categories'] = $categories;
             } else {
                 $feeds = $this->loadFeedData();
                 foreach ($feeds as $id => $feedData) {
                     $categories[] = array('title' => $feedData['TITLE'], 'subtitle' => $feedData['SUBTITLE'], 'id' => $id);
                 }
             }
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         case 'category':
             $this->loadFeedData();
             $categoryId = $this->getArg('category');
             $groups = $this->getFeedGroups();
             if (isset($groups[$categoryId])) {
                 $this->feedGroup = $categoryId;
                 $groupData = $this->loadFeedData();
                 $categories = array();
                 foreach ($groupData as $id => $feed) {
                     if (!isset($feed['HIDDEN']) || !$feed['HIDDEN']) {
                         $category = array('id' => $id, 'title' => $feed['TITLE']);
                         if (isset($feed['SUBTITLE'])) {
                             $category['subtitle'] = $feed['SUBTITLE'];
                         }
                         $categories[] = $category;
                     }
                 }
                 $response = array('categories' => $categories);
                 $this->setResponse($response);
                 $this->setResponseVersion(1);
             } else {
                 $controller = $this->getDataModel();
                 if ($controller) {
                     //if ($categoryId) {
                     //    $category = $controller->findCategory($categoryId);
                     //    $placemarks = $category->placemarks();
                     //    $categories = $category->categories();
                     //} else {
                     $placemarks = $controller->placemarks();
                     $categories = $controller->categories();
                     //}
                     if ($placemarks) {
                         $response['placemarks'] = array();
                         foreach ($placemarks as $placemark) {
                             $response['placemarks'][] = $this->arrayFromPlacemark($placemark);
                         }
                     }
                     if ($categories) {
                         foreach ($categories as $aCategory) {
                             $response['categories'][] = $this->arrayFromCategory($aCategory);
                         }
                     }
                     if (!$placemarks && !$categories) {
                         // need something in the response so that it will be
                         // output as a JSON object rather than a JSON array
                         $response = array('categories' => array());
                     }
                     $this->setResponse($response);
                     $this->setResponseVersion(1);
                 } else {
                     $error = new KurogoError("Could not find data source for requested category");
                     $this->throwError($error);
                 }
             }
             break;
         case 'detail':
             $suppress = $this->getOptionalModuleVar('suppress', array(), 'details', 'page-detail');
             $tabKeys = $this->getOptionalModuleVar('tabkeys', array(), 'tabs', 'page-detail');
             $controller = $this->getDataModel();
             $placemarkId = $this->getArg('id', null);
             if ($controller && $placemarkId !== null) {
                 $placemarks = $controller->selectPlacemark($placemarkId);
                 $placemark = current($placemarks);
                 $fields = $placemark->getFields();
                 $geometry = $placemark->getGeometry();
                 $tabs = $this->getTabsForTabKeys($tabKeys, $this->command);
                 $response = array('sections' => $tabs, 'id' => $placemarkId, 'title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'address' => $placemark->getAddress());
                 if ($this->requestedVersion >= 2) {
                     $response['description'] = $placemark->getDescription($suppress);
                     $responseVersion = 2;
                 } else {
                     $response['details'] = array('description' => $placemark->getDescription($suppress));
                     $photoURL = $placemark->getField('PhotoURL');
                     if ($photoURL) {
                         $response['photoURL'] = $photoURL;
                     }
                     $responseVersion = 1;
                 }
                 if ($geometry) {
                     $center = $geometry->getCenterCoordinate();
                     $response['lat'] = $center['lat'];
                     $response['lon'] = $center['lon'];
                     $response['geometryType'] = $this->getGeometryType($geometry);
                     $response['geometry'] = $this->formatGeometry($geometry);
                 }
                 $this->setResponse($response);
                 $this->setResponseVersion($responseVersion);
             }
             break;
         case 'search':
             $mapSearch = $this->getSearchClass($this->args);
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             if ($lat || $lon) {
                 // defaults values for proximity search
                 $tolerance = 1000;
                 $maxItems = 0;
                 // check for settings in feedgroup config
                 $configData = $this->getDataForGroup($this->feedGroup);
                 if ($configData) {
                     if (isset($configData['NEARBY_THRESHOLD'])) {
                         $tolerance = $configData['NEARBY_THRESHOLD'];
                     }
                     if (isset($configData['NEARBY_ITEMS'])) {
                         $maxItems = $configData['NEARBY_ITEMS'];
                     }
                 }
                 // check for override settings in feeds
                 $configData = $this->getCurrentFeed();
                 if (isset($configData['NEARBY_THRESHOLD'])) {
                     $tolerance = $configData['NEARBY_THRESHOLD'];
                 }
                 if (isset($configData['NEARBY_ITEMS'])) {
                     $maxItems = $configData['NEARBY_ITEMS'];
                 }
                 $searchResults = $mapSearch->searchByProximity(array('lat' => $lat, 'lon' => $lon), 1000, 10);
             } else {
                 if ($searchTerms = $this->getArg(array('filter', 'q'))) {
                     $this->setLogData($searchTerms);
                     $searchResults = $mapSearch->searchCampusMap($searchTerms);
                 }
             }
             $provider = null;
             if ($this->requestedVersion >= 2 && $this->getArg('provider', null)) {
                 $providerId = $this->getArg('provider');
                 switch ($providerId) {
                     case 'google':
                         $provider = new GoogleJSMap();
                         break;
                     case 'esri':
                         $provider = new ArcGISJSMap();
                         break;
                 }
                 if ($provider && $projection) {
                     $provider->setMapProjection($projection);
                 }
             }
             $places = array();
             foreach ($searchResults as $result) {
                 if ($this->requestedVersion >= 2) {
                     $place = array('attribs' => $this->shortArrayFromPlacemark($result));
                 } else {
                     $place = $this->shortArrayFromPlacemark($result);
                 }
                 if ($provider) {
                     if ($result instanceof MapPolygon) {
                         $place['placemark'] = $provider->jsObjectForPolygon($result);
                     } elseif ($result instanceof MapPolyline) {
                         $place['placemark'] = $provider->jsObjectForPath($result);
                     } else {
                         $place['placemark'] = $provider->jsObjectForMarker($result);
                     }
                 }
                 $places[] = $place;
             }
             $response = array('total' => count($places), 'returned' => count($places), 'results' => $places);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
             // ajax calls
         // ajax calls
         case 'projectPoint':
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             $fromProj = $this->getArg('from', GEOGRAPHIC_PROJECTION);
             $toProj = $this->getArg('to', GEOGRAPHIC_PROJECTION);
             $projector = new MapProjector();
             $projector->setSrcProj($fromProj);
             $projector->setDstProj($toProj);
             $result = $projector->projectPoint(array('lat' => $lat, 'lon' => $lon));
             $this->setResponse($result);
             $this->setResponseVersion(1);
             break;
         case 'sortGroupsByDistance':
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             $categories = array();
             $showDistances = $this->getOptionalModuleVar('SHOW_DISTANCES', true);
             if ($lat || $lon) {
                 foreach ($this->getFeedGroups() as $id => $groupData) {
                     $center = filterLatLon($groupData['center']);
                     $distance = greatCircleDistance($lat, $lon, $center['lat'], $center['lon']);
                     $category = array('title' => $groupData['title'], 'id' => $id);
                     if ($showDistances && ($displayText = $this->displayTextFromMeters($distance))) {
                         $category['distance'] = $displayText;
                     }
                     $categories[] = $category;
                     $distances[] = $distance;
                 }
                 array_multisort($distances, SORT_ASC, $categories);
             }
             $this->setResponse($categories);
             $this->setResponseVersion(1);
             break;
         case 'staticImageURL':
             $params = array('STATIC_MAP_BASE_URL' => $this->getArg('baseURL'), 'STATIC_MAP_CLASS' => $this->getArg('mapClass'));
             $dc = Kurogo::deviceClassifier();
             $mapDevice = new MapDevice($dc->getPagetype(), $dc->getPlatform());
             $mapController = MapImageController::factory($params, $mapDevice);
             if (!$mapController->isStatic()) {
                 $error = new KurogoError(0, "staticImageURL must be used with a StaticMapImageController subclass");
                 $this->throwError($error);
             }
             $currentQuery = $this->getArg('query');
             $mapController->parseQuery($currentQuery);
             $overrides = $this->getArg('overrides');
             $mapController->parseQuery($overrides);
             $zoomDir = $this->getArg('zoom');
             if ($zoomDir == 1 || $zoomDir == 'in') {
                 $level = $mapController->getLevelForZooming('in');
                 $mapController->setZoomLevel($level);
             } elseif ($zoomDir == -1 || $zoomDir == 'out') {
                 $level = $mapController->getLevelForZooming('out');
                 $mapController->setZoomLevel($level);
             }
             $scrollDir = $this->getArg('scroll');
             if ($scrollDir) {
                 $center = $mapController->getCenterForPanning($scrollDir);
                 $mapController->setCenter($center);
             }
             $url = $mapController->getImageURL();
             $this->setResponse($url);
             $this->setResponseVersion(1);
             break;
         case 'geocode':
             // TODO: this is not fully implemented. do not use this API.
             includePackage('Maps', 'Geocoding');
             $locationSearchTerms = $this->getArg('q');
             $geocodingDataRetrieverClass = $this->getOptionalModuleVar('GEOCODING_DATA_RETRIEVER_CLASS');
             $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS');
             $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL');
             $arguments = array('BASE_URL' => $geocoding_base_url, 'CACHE_LIFETIME' => 86400, 'PARSER_CLASS' => $geocodingDataParserClass);
             $controller = DataRetriever::factory($geocodingDataRetrieverClass, $arguments);
             $controller->addCustomFilters($locationSearchTerms);
             $response = $controller->getParsedData();
             // checking for Geocoding service error
             if ($response['errorCode'] == 0) {
                 unset($response['errorCode']);
                 unset($response['errorMessage']);
                 $this->setResponse($response);
                 $this->setResponseVersion(1);
             } else {
                 $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']);
                 $this->setResponseError($kurogoError);
                 $this->setResponseVersion(1);
             }
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }
Ejemplo n.º 9
0
    function getFooterScript()
    {
        // put dojo stuff in the footer since the header script
        // gets loaded before the included script
        $zoomLevel = $this->zoomLevel;
        $targetScale = oldPixelScaleForZoomLevel($zoomLevel);
        if ($this->levelsOfDetail) {
            foreach ($this->levelsOfDetail as $levelData) {
                if ($levelData['scale'] < $targetScale) {
                    break;
                } else {
                    $zoomLevel = $levelData['level'];
                }
            }
        }
        $moreLayersJS = '';
        foreach ($this->moreLayers as $anotherLayer) {
            $moreLayersJS .= <<<JS
    map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("{$anotherLayer}", 1.0));
JS;
        }
        $footer = $this->prepareJavascriptTemplate('ArcGISJSMapFooter');
        $footer->setValues(array('___FULL_URL_PREFIX___' => FULL_URL_PREFIX, '___API_URL___' => FULL_URL_BASE . API_URL_PREFIX . "/map/projectPoint", '___WKID___' => $this->mapProjection, '___MAPELEMENT___' => $this->mapElement, '___IMAGE_WIDTH___' => $this->imageWidth, '___IMAGE_HEIGHT___' => $this->imageHeight, '___ZOOMLEVEL___' => $zoomLevel, '___BASE_URL___' => $this->baseURL, '___MORE_LAYER_SCRIPT___' => $moreLayersJS, '___MARKER_SCRIPT___' => $this->getMarkerJS(), '___POLYGON_SCRIPT___' => $this->getPolygonJS(), '___PATH_SCRIPT___' => $this->getPathJS()));
        if ($this->mapProjector) {
            $xy = $this->mapProjector->projectPoint($this->center);
            list($x, $y) = MapProjector::getXYFromPoint($xy);
            $footer->setValues(array('___X___' => $x, '___Y___' => $y));
        } else {
            $footer->setValues(array('___X___' => $this->center['lon'], '___Y___' => $this->center['lat']));
        }
        return $footer->getScript();
    }
Ejemplo n.º 10
0
 public function __construct($projString)
 {
     $this->specs = $projString;
     if (preg_match('/^\\d+$/', $projString)) {
         $this->format = 'wkid';
     } elseif (preg_match('/^\\w+\\[/', $projString)) {
         $this->format = 'wkt';
     } elseif (preg_match('/^\\+/', $projString)) {
         $this->format = 'proj4';
     }
     switch ($this->format) {
         case 'wkid':
             $projString = MapProjector::getProjSpecs($projString);
             $params = self::parseProj4String($projString);
             $this->initFromProj4Params($params);
             break;
         case 'wkt':
             $params = WKTParser::parseWKTString($projString);
             $this->initFromWKTParams($params);
             break;
         case 'proj4':
         default:
             $params = self::parseProj4String($projString);
             $this->initFromProj4Params($params);
             break;
     }
 }
Ejemplo n.º 11
0
 public function initializeForCommand()
 {
     switch ($this->command) {
         case 'index':
             $categories = array();
             $groups = $this->getFeedGroups();
             if ($groups) {
                 foreach ($groups as $id => &$groupData) {
                     if (isset($groupData['center'])) {
                         $latlon = filterLatLon($groupData['center']);
                         $groupData['lat'] = $latlon['lat'];
                         $groupData['lon'] = $latlon['lon'];
                     }
                     $groupData['id'] = $id;
                     $categories[] = $groupData;
                 }
                 $response = array('categories' => $categories);
             } else {
                 $feeds = $this->loadFeedData();
                 foreach ($feeds as $id => $feedData) {
                     $categories[] = array('title' => $feedData['TITLE'], 'subtitle' => $feedData['SUBTITLE'], 'id' => $id);
                 }
             }
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         case 'category':
             $this->loadFeedData();
             $category = $this->getArg('category');
             $groups = $this->getFeedGroups();
             if (isset($groups[$category])) {
                 $this->feedGroup = $category;
                 $groupData = $this->loadFeedData();
                 $categories = array();
                 foreach ($groupData as $id => $feed) {
                     if (!isset($feed['HIDDEN']) || !$feed['HIDDEN']) {
                         $category = array('id' => $id, 'title' => $feed['TITLE']);
                         if (isset($feed['SUBTITLE'])) {
                             $category['subtitle'] = $feed['SUBTITLE'];
                         }
                         $categories[] = $category;
                     }
                 }
                 $response = array('categories' => $categories);
                 $this->setResponse($response);
                 $this->setResponseVersion(1);
             } else {
                 $dataController = $this->getDataController();
                 if ($dataController) {
                     $listItems = $dataController->getListItems();
                     $placemarks = array();
                     $categories = array();
                     foreach ($listItems as $listItem) {
                         if ($listItem instanceof Placemark) {
                             $placemarks[] = $this->shortArrayFromPlacemark($listItem);
                         } else {
                             $categories[] = $this->arrayFromCategory($listItem);
                         }
                     }
                     $response = array();
                     if ($placemarks) {
                         $response['placemarks'] = $placemarks;
                     }
                     if ($categories) {
                         $response['categories'] = $categories;
                     }
                     $this->setResponse($response);
                     $this->setResponseVersion(1);
                 } else {
                     $error = new KurogoError("Could not find data source for requested category");
                     $this->throwError($error);
                 }
             }
             break;
         case 'detail':
             $dataController = $this->getDataController();
             $placemarkId = $this->getArg('id', null);
             if ($dataController && $placemarkId !== null) {
                 $placemark = $dataController->selectPlacemark($placemarkId);
                 $fields = $placemark->getFields();
                 $geometry = $placemark->getGeometry();
                 $response = array('id' => $placemarkId, 'title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'address' => $placemark->getAddress(), 'details' => $placemark->getFields());
                 if ($geometry) {
                     $center = $geometry->getCenterCoordinate();
                     $response['lat'] = $center['lat'];
                     $response['lon'] = $center['lon'];
                     $response['geometryType'] = $this->getGeometryType($geometry);
                     $response['geometry'] = $this->formatGeometry($geometry);
                 }
                 $this->setResponse($response);
                 $this->setResponseVersion(1);
             }
             break;
         case 'search':
             $mapSearch = $this->getSearchClass($this->args);
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             if ($lat || $lon) {
                 // defaults values for proximity search
                 $tolerance = 1000;
                 $maxItems = 0;
                 // check for settings in feedgroup config
                 $configData = $this->getDataForGroup($this->feedGroup);
                 if ($configData) {
                     if (isset($configData['NEARBY_THRESHOLD'])) {
                         $tolerance = $configData['NEARBY_THRESHOLD'];
                     }
                     if (isset($configData['NEARBY_ITEMS'])) {
                         $maxItems = $configData['NEARBY_ITEMS'];
                     }
                 }
                 // check for override settings in feeds
                 $configData = $this->getCurrentFeed();
                 if (isset($configData['NEARBY_THRESHOLD'])) {
                     $tolerance = $configData['NEARBY_THRESHOLD'];
                 }
                 if (isset($configData['NEARBY_ITEMS'])) {
                     $maxItems = $configData['NEARBY_ITEMS'];
                 }
                 $searchResults = $mapSearch->searchByProximity(array('lat' => $lat, 'lon' => $lon), 1000, 10);
             } else {
                 $searchTerms = $this->getArg('q');
                 if ($searchTerms) {
                     $searchResults = $mapSearch->searchCampusMap($searchTerms);
                 }
             }
             $places = array();
             foreach ($searchResults as $result) {
                 $places[] = $this->shortArrayFromPlacemark($result);
             }
             $response = array('total' => count($places), 'returned' => count($places), 'results' => $places);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
             // ajax calls
         // ajax calls
         case 'projectPoint':
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             $fromProj = $this->getArg('from', GEOGRAPHIC_PROJECTION);
             $toProj = $this->getArg('to', GEOGRAPHIC_PROJECTION);
             $projector = new MapProjector();
             $projector->setSrcProj($fromProj);
             $projector->setDstProj($toProj);
             $result = $projector->projectPoint(array('lat' => $lat, 'lon' => $lon));
             $this->setResponse($result);
             $this->setResponseVersion(1);
             break;
         case 'sortGroupsByDistance':
             $lat = $this->getArg('lat', 0);
             $lon = $this->getArg('lon', 0);
             $categories = array();
             $showDistances = $this->getOptionalModuleVar('SHOW_DISTANCES', true);
             if ($lat || $lon) {
                 foreach ($this->getFeedGroups() as $id => $groupData) {
                     $center = filterLatLon($groupData['center']);
                     $distance = greatCircleDistance($lat, $lon, $center['lat'], $center['lon']);
                     $category = array('title' => $groupData['title'], 'id' => $id);
                     if ($showDistances && ($displayText = $this->displayTextFromMeters($distance))) {
                         $category['distance'] = $displayText;
                     }
                     $categories[] = $category;
                     $distances[] = $distance;
                 }
                 array_multisort($distances, SORT_ASC, $categories);
             }
             $this->setResponse($categories);
             $this->setResponseVersion(1);
             break;
         case 'staticImageURL':
             $params = array('STATIC_MAP_BASE_URL' => $this->getArg('baseURL'), 'STATIC_MAP_CLASS' => $this->getArg('mapClass'));
             $dc = Kurogo::deviceClassifier();
             $mapDevice = new MapDevice($dc->getPagetype(), $dc->getPlatform());
             $mapController = MapImageController::factory($params, $mapDevice);
             if (!$mapController->isStatic()) {
                 $error = new KurogoError(0, "staticImageURL must be used with a StaticMapImageController subclass");
                 $this->throwError($error);
             }
             $currentQuery = $this->getArg('query');
             $mapController->parseQuery($currentQuery);
             $overrides = $this->getArg('overrides');
             $mapController->parseQuery($overrides);
             $zoomDir = $this->getArg('zoom');
             if ($zoomDir == 1 || $zoomDir == 'in') {
                 $level = $mapController->getLevelForZooming('in');
                 $mapController->setZoomLevel($level);
             } elseif ($zoomDir == -1 || $zoomDir == 'out') {
                 $level = $mapController->getLevelForZooming('out');
                 $mapController->setZoomLevel($level);
             }
             $scrollDir = $this->getArg('scroll');
             if ($scrollDir) {
                 $center = $mapController->getCenterForPanning($scrollDir);
                 $mapController->setCenter($center);
             }
             $url = $mapController->getImageURL();
             $this->setResponse($url);
             $this->setResponseVersion(1);
             break;
         case 'geocode':
             $locationSearchTerms = $this->getArg('q');
             $geocodingDataControllerClass = $this->getOptionalModuleVar('GEOCODING_DATA_CONTROLLER_CLASS');
             $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS');
             $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL');
             $arguments = array('BASE_URL' => $geocoding_base_url, 'CACHE_LIFETIME' => 86400, 'PARSER_CLASS' => $geocodingDataParserClass);
             $controller = DataController::factory($geocodingDataControllerClass, $arguments);
             $controller->addCustomFilters($locationSearchTerms);
             $response = $controller->getParsedData();
             // checking for Geocoding service error
             if ($response['errorCode'] == 0) {
                 unset($response['errorCode']);
                 unset($response['errorMessage']);
                 $this->setResponse($response);
                 $this->setResponseVersion(1);
             } else {
                 $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']);
                 $this->setResponseError($kurogoError);
                 $this->setResponseVersion(1);
             }
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }
Ejemplo n.º 12
0
 private function getCenterJS() {
     if ($this->mapProjector) {
         $xy = $this->mapProjector->projectPoint($this->center);
         list($x, $y) = MapProjector::getXYFromPoint($xy);
         $xy = array('x' => $x, 'y' => $y);
     } else {
         $xy = array('x' => $this->center['lat'], 'y' => $this->center['lon']);
     }
 
     $js = 'new esri.geometry.Point('.$xy['x'].', '.$xy['y'].', spatialRef)';
 
     return $js;
 }
Ejemplo n.º 13
0
    private function initializeMap(MapDataController $dataController, MapFeature $feature, $fullscreen=FALSE) {
        
        $style = $feature->getStyle();
        $geometries = array();
        
        $geometries[] = $feature->getGeometry();

        // zoom
        if (isset($this->args['zoom'])) {
            $zoomLevel = $this->args['zoom'];
        } else {
            $zoomLevel = $dataController->getDefaultZoomLevel();
        }

        if ($this->pageSupportsDynamicMap() && $dataController->supportsDynamicMap()) {
            $imgController = $dataController->getDynamicMapController();
        } else {
            $imgController = $dataController->getStaticMapController();
        }

        if ($imgController->supportsProjections()) {
            $imgController->setDataProjection($dataController->getProjection());
        } else {
            $dataProjection = $dataController->getProjection();
            $outputProjection = $imgController->getMapProjection();
            if ($dataProjection != $outputProjection) {
                $projector = new MapProjector();
                $projector->setSrcProj($dataProjection);
                $projector->setDstProj($outputProjection);
                foreach ($geometries as $i => $geometry) {
                    $geometries[$i] = $projector->projectGeometry($geometry);
                }
            }
        }
        
        if (isset($this->args['lat'], $this->args['lon'])) {
            array_unshift($geometries, new EmptyMapPoint($this->args['lat'], $this->args['lon']));
        }
        
        // center
        if (isset($this->args['center'])) {
            $latlon = explode(",", $this->args['center']);
            $center = array('lat' => $latlon[0], 'lon' => $latlon[1]);
        } else {
            $center = $geometries[0]->getCenterCoordinate();
        }

        $imgController->setCenter($center);
        $imgController->setZoomLevel($zoomLevel);

        foreach ($geometries as $i => $geometry) {
          switch ($geometry->getType()) {
              case MapGeometry::POINT:
                  if ($imgController->canAddAnnotations()) {
                      $imgController->addAnnotation($geometry->getCenterCoordinate(), $style, $feature->getTitle());
                  }
                  break;
              case MapGeometry::POLYLINE:
                  if ($imgController->canAddPaths()) {
                      $imgController->addPath($geometry->getPoints(), $style);
                  }
                  break;
              case MapGeometry::POLYGON:
                  if ($imgController->canAddPolygons()) {
                      $imgController->addPolygon($geometry->getRings(), $style);
                  }
                  break;
              default:
                  break;
          }
        }

        if (!$fullscreen) {
            $this->assign('fullscreenURL', $this->buildBreadcrumbURL('fullscreen', $this->args, false));
        
            if ($imgController->isStatic()) {
                list($imageWidth, $imageHeight) = $this->staticMapImageDimensions();

            } else {
                list($imageWidth, $imageHeight) = $this->dynamicMapImageDimensions();
                $this->addInlineJavascriptFooter("\n hideMapTabChildren();\n");
            }
            
        } else {
            $this->assign('detailURL', $this->buildBreadcrumbURL('detail', $this->args, false));
            if ($imgController->isStatic()) {
                list($imageWidth, $imageHeight) = $this->staticMapImageDimensions();

            } else {
                list($imageWidth, $imageHeight) = $this->fullscreenMapImageDimensions();
                $this->addInlineJavascriptFooter("\n hide('loadingimage');\n");
            }
            $this->addOnOrientationChange('rotateScreen();');
        }
        
        $this->assign('fullscreen', $fullscreen);
        $this->assign('isStatic', $imgController->isStatic());
        
        $this->initializeMapElements('mapimage', $imgController, $imageWidth, $imageHeight);

        // call the function that updates the image size        
        if ($fullscreen && $imgController->isStatic()) {
            // Let Webkit figure out what the window size is and then hide the address bar
            // and resize the map
            $this->addOnLoad('setTimeout(function () { window.scrollTo(0, 1); updateMapDimensions(); }, 1000);');
            $this->addOnOrientationChange('updateMapDimensions();');
        }
    }