示例#1
0
 public function parseData($data)
 {
     $decodedData = json_decode($data, true);
     if (!$decodedData['status'] == 'OK') {
         // handle error here
     }
     if (isset($decodedData['results'])) {
         $results = $decodedData['results'];
     } elseif (isset($decodedData['result'])) {
         $results = array($decodedData['result']);
     }
     $position = 0;
     // geocode results have no id's
     foreach ($results as $result) {
         $coord = $result['geometry']['location'];
         $coord['lon'] = $coord['lng'];
         $centroid = new MapBasePoint($coord);
         $placemark = new BasePlacemark($centroid);
         if (isset($result['name'])) {
             $placemark->setTitle($result['name']);
         } elseif (isset($result['formatted_address'])) {
             $placemark->setTitle($result['formatted_address']);
         }
         if (isset($decodedData['icon'])) {
             $placemark->setStyleForTypeAndParam(MapStyle::POINT, MapStyle::ICON, $decodedData['icon']);
         }
         if (isset($result['reference'])) {
             $placemark->setId($result['reference']);
         } else {
             $placemark->setId($position);
         }
         // fields returned by detail query
         // http://code.google.com/apis/maps/documentation/places/#PlaceDetails
         if (isset($result['vicinity'])) {
             $placemark->setField('vicinity', $result['vicinity']);
         }
         if (isset($result['formatted_phone_number'])) {
             $placemark->setField('phone', $result['formatted_phone_number']);
         }
         if (isset($result['url'])) {
             $placemark->setField('url', $result['url']);
         }
         if (isset($result['formatted_address'])) {
             $placemark->setAddress($result['formatted_address']);
         }
         $this->items[] = $placemark;
         $position++;
     }
     return $this->items;
 }
示例#2
0
 public function unserialize($data)
 {
     $data = unserialize($data);
     parent::unserialize($data['parent']);
     $this->titleField = $data['titleField'];
     $this->geometryType = $data['geometryType'];
 }
 public function unserialize($data)
 {
     $data = unserialize($data);
     parent::unserialize($data['parent']);
     $this->titleField = $data['titleField'];
     $this->subtitleField = $data['subtitleField'];
 }
示例#4
0
 public function parseQuery($query)
 {
     // php will only parse the last argument if it isn't specified as an array
     $query = str_replace('markers=', 'markers[]=', $query);
     parse_str($query, $args);
     if (isset($args['center'])) {
         $this->center = filterLatLon($args['center']);
     }
     if (isset($args['zoom'])) {
         $this->zoomLevel = $args['zoom'];
     }
     if (isset($args['sensor'])) {
         $this->sensor = $args['sensor'] == 'true';
     }
     if (isset($args['format'])) {
         $this->imageFormat = $args['format'];
     }
     if (isset($args['mapType'])) {
         $this->mapType = $args['mapType'];
     }
     if (isset($args['size'])) {
         $sizeParts = explode('x', $args['size']);
         $this->imageWidth = $sizeParts[0];
         $this->imageHeight = $sizeParts[1];
     }
     if (isset($args['path'])) {
         $this->paths = $args['path'];
     }
     if (isset($args['markers'])) {
         foreach ($args['markers'] as $markerGroup) {
             $parts = explode('|', $markerGroup);
             for ($i = 0; $i < count($parts); $i++) {
                 if (filterLatLon($parts[$i])) {
                     $this->markers[implode('|', array_slice($parts, 0, $i))] = array_slice($parts, $i);
                     break;
                 }
             }
         }
     }
     if (isset($args['userLat'], $args['userLon'])) {
         $center = array('lat' => $args['userLat'], 'lon' => $args['userLon']);
         $userLocation = new BasePlacemark(new MapBasePoint($center));
         $style = new MapBaseStyle();
         // the following doesn't work from a local server
         //$style->setStyleForTypeAndParam(
         //    MapStyle::POINT,
         //    MapStyle::ICON,
         //    FULL_URL_BASE.'/modules/map/images/map-location@2x.png');
         $userLocation->setStyle($style);
         $this->addPoint($userLocation);
     }
     if (isset($args['style'])) {
         // TODO
     }
 }
示例#5
0
 protected function getSelectedPlacemarks()
 {
     if ($this->selectedPlacemarks) {
         return $this->selectedPlacemarks;
     }
     // all campuses
     if ($this->getArg('worldmap')) {
         $placemarks = array();
         foreach ($this->feedGroups as $id => $groupData) {
             $showOnWorldMap = self::argVal($groupData, 'SHOW_ON_WORLDMAP', 1);
             if ($showOnWorldMap) {
                 $point = filterLatLon($groupData['center']);
                 $placemark = new BasePlacemark(new MapBasePoint(array('lat' => $point['lat'], 'lon' => $point['lon'])));
                 $placemark->setId($id);
                 $placemark->setTitle($groupData['title']);
                 $placemark->setURL($this->groupURL($id));
                 $placemarks[] = $placemark;
             }
         }
         return $placemarks;
     }
     if ($searchTerms = $this->getArg(array('filter', 'q'))) {
         return $this->searchItems($searchTerms, null, $this->args);
     }
     // if anything was already selected by something else
     $feedId = $this->getArg('feed');
     if ($feedId) {
         $dataModel = $this->getDataModel($feedId);
         $category = $this->getArg('category', null);
         $featureIndex = $this->getArg('featureindex', null);
         if ($category !== null) {
             $dataModel->findCategory($category);
         }
         if ($this->placemarkId !== null) {
             $dataModel->setPlacemarkId($this->placemarkId);
         }
         $placemarks = $dataModel->placemarks();
         if ($featureIndex !== null && intval($featureIndex) < count($placemarks)) {
             $placemarks = array_slice($placemarks, intval($featureIndex), 1);
         }
         if ($placemarks) {
             return $placemarks;
         }
     }
     // make the map display arbitrary locations that aren't in any feeds
     if (isset($this->args['lat'], $this->args['lon'])) {
         $lat = $this->args['lat'];
         $lon = $this->args['lon'];
         $title = $this->getArg('title');
         if (!$title) {
             $title = "{$lat},{$lon}";
         }
         $feature = new BasePlacemark(new MapBasePoint(array('lat' => $lat, 'lon' => $lon)));
         $feature->setTitle($title);
         return array($feature);
     }
     // TODO: add ways to show all bookmarks in a campus
     return array();
 }
示例#6
0
 protected function initializeForPage()
 {
     $this->featureIndex = $this->getArg('featureindex', null);
     switch ($this->page) {
         case 'help':
             break;
         case 'index':
             if ($action = $this->getArg('action', false)) {
                 if ($this->feedGroup && $action == 'add') {
                     // TODO have config for different types of cookie expiration times
                     $expireTime = time() + 897298;
                     setcookie(MAP_GROUP_COOKIE, $this->feedGroup, $expireTime, COOKIE_PATH);
                 } else {
                     if ($action == 'remove') {
                         $expireTime = time() - 4096;
                         setcookie(MAP_GROUP_COOKIE, '', $expireTime, COOKIE_PATH);
                     }
                 }
             }
             if ($this->numGroups == 0) {
                 $categories = array(array('title' => $this->getLocalizedString('NO_MAPS_FOUND')));
                 $this->assign('categories', $categories);
             } else {
                 if ($this->feedGroup === null && $this->numGroups > 1) {
                     // show the list of groups
                     foreach ($this->feedGroups as $id => $groupData) {
                         $categories[] = array('title' => $groupData['title'], 'url' => $this->groupURL($id), 'listclass' => $id);
                     }
                     // TODO there should ba a cleaner way to do this
                     $apiURL = FULL_URL_BASE . API_URL_PREFIX . "/{$this->configModule}";
                     $this->addInlineJavascript("\napiURL = '{$apiURL}';\n");
                     $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS');
                     $this->assign('browseHint', $this->getLocalizedString('SELECT_A_MAP_GROUP', $groupAlias));
                     $this->assign('categories', $categories);
                     $this->addOnLoad('sortGroupsByDistance();');
                 } else {
                     $groupData = $this->getDataForGroup($this->feedGroup);
                     $this->assign('browseBy', $groupData['title']);
                     if ($this->numGroups > 1) {
                         $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS_PLURAL');
                         $clearLink = array(array('title' => "All {$groupAlias}", 'url' => $this->groupURL('')));
                         $this->assign('clearLink', $clearLink);
                     }
                     $categories = $this->assignCategories();
                     /*
                     if (count($categories)==1) {
                         $category = current($categories);
                         $this->redirectTo('category', array('category'=>$category['id']));
                     }
                     */
                 }
             }
             $this->assign('placeholder', $this->getLocalizedString('MAP_SEARCH_PLACEHOLDER'));
             $this->assign('tip', $this->getLocalizedString('MAP_SEARCH_TIP'));
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $this->generateBookmarkLink();
             }
             break;
         case 'bookmarks':
             if (!$this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $this->redirectTo('index', array());
             }
             $places = array();
             foreach ($this->getBookmarks() as $aBookmark) {
                 if ($aBookmark) {
                     // prevent counting empty string
                     $titles = $this->getTitleForBookmark($aBookmark);
                     $subtitle = count($titles) > 1 ? $titles[1] : null;
                     // TODO split up bookmarks by category
                     $places[] = array('title' => $titles[0], 'subtitle' => $subtitle, 'url' => $this->detailURLForBookmark($aBookmark));
                 }
             }
             $this->assign('places', $places);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             if ($searchTerms) {
                 $this->feedGroup = null;
                 // TODO: redirect if there is one result
                 $args = array_merge($this->args, array('addBreadcrumb' => true));
                 // still need a way to show the Google logo if we use their search
                 $searchResults = $this->searchItems($searchTerms, null, $args);
                 $places = array();
                 foreach ($searchResults as $place) {
                     $places[] = $this->linkForItem($place);
                 }
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('places', $places);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'category':
             $category = $this->getCategory();
             if ($category) {
                 // populate drop-down list at the bottom
                 $this->assignCategories();
                 // build the drill-down list
                 $dataController = $this->getDataController();
                 $dataController->addDisplayFilter('category', $this->getDrillDownPath());
                 $listItems = $dataController->getListItems();
                 if (count($listItems) == 1) {
                     // redirect to a category's children if it only has one item
                     $args = $this->args;
                     if (current($listItems) instanceof Placemark) {
                         $args['featureindex'] = current($listItems)->getId();
                         $this->redirectTo('detail', $args, true);
                     } else {
                         // assume MapFolder
                         $path = $this->getDrillDownPath();
                         $path[] = current($listItems)->getId();
                         $args['path'] = implode(MAP_CATEGORY_DELIMITER, $path);
                         $this->redirectTo('category', $args, false);
                     }
                 }
                 $places = array();
                 foreach ($listItems as $listItem) {
                     if ($listItem instanceof Placemark) {
                         $url = $this->detailURL($listItem->getId(), $category);
                     } else {
                         // for folder objects, getIndex returns the subcategory ID
                         $drilldownPath = array_merge($this->getDrillDownPath(), array($listItem->getId()));
                         $url = $this->categoryURL($category, $drilldownPath, false);
                     }
                     $places[] = array('title' => $listItem->getTitle(), 'subtitle' => $listItem->getSubtitle(), 'url' => $url);
                 }
                 $this->assign('title', $dataController->getTitle());
                 $this->assign('places', $places);
                 if ($this->numGroups > 1) {
                     $categories = $this->assignCategories();
                     if (count($categories) == 1) {
                         $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS_PLURAL');
                         $clearLink = array(array('title' => "All {$groupAlias}", 'url' => $this->groupURL('')));
                         $this->assign('clearLink', $clearLink);
                     }
                 }
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'detail':
             $detailConfig = $this->loadPageConfigFile('detail', 'detailConfig');
             $tabKeys = array();
             $tabJavascripts = array();
             $title = $this->getArg('title');
             $dataController = $this->getDataController();
             $drilldownPath = $this->getDrillDownPath();
             if ($drilldownPath) {
                 $dataController->addDisplayFilter('category', $drilldownPath);
             }
             if ($this->featureIndex !== null) {
                 $feature = $dataController->selectPlacemark($this->featureIndex);
             } elseif (isset($this->args['lat'], $this->args['lon'])) {
                 $lat = $this->args['lat'];
                 $lon = $this->args['lon'];
                 $feature = new BasePlacemark(new MapBasePoint(array('lat' => $lat, 'lon' => $lon)));
                 if (!$title) {
                     $title = "{$lat},{$lon}";
                 }
                 // hacky
                 $dataController->setSelectedPlacemarks(array($feature));
             }
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 if (isset($this->args['featureindex'])) {
                     // this is a place from a feed
                     $cookieParams = array('category' => $this->getCategory(), 'featureindex' => $this->featureIndex);
                     $cookieID = http_build_query($cookieParams);
                     $this->generateBookmarkOptions($cookieID);
                 } elseif (isset($this->args['lat'], $this->args['lon'])) {
                     $cookieParams = array('lat' => $this->args['lat'], 'lon' => $this->args['lon']);
                     if ($feature) {
                         $cookieParams['title'] = $feature->getTitle();
                     }
                     $cookieID = http_build_query($cookieParams);
                     $this->generateBookmarkOptions($cookieID);
                 }
             }
             if ($feature) {
                 if (!$title) {
                     $title = $feature->getTitle();
                 }
                 // prevent infinite loop in smarty_modifier_replace
                 // TODO figure out why smarty gets in an infinite loop
                 $address = str_replace("\n", " ", $feature->getSubtitle());
             } else {
                 // TODO put something reasonable here
                 $title = '';
                 $address = $this->getArg('address');
             }
             $this->assign('name', $title);
             $this->assign('address', $address);
             $possibleTabs = $detailConfig['tabs']['tabkeys'];
             foreach ($possibleTabs as $tabKey) {
                 if ($this->generateTabForKey($tabKey, $feature, $dataController, $tabJavascripts)) {
                     $tabKeys[] = $tabKey;
                 }
             }
             $this->assign('tabKeys', $tabKeys);
             $this->enableTabs($tabKeys, null, $tabJavascripts);
             break;
         case 'fullscreen':
             $dataController = $this->getDataController();
             $dataController->selectPlacemark($this->featureIndex);
             $this->initializeMap($dataController, true);
             break;
     }
 }
示例#7
0
 public function parseData($content)
 {
     $data = json_decode($content, true);
     if (isset($data['error'])) {
         $error = $data['error'];
         $details = isset($error['details']) ? json_encode($error['details']) : '';
         Kurogo::log(LOG_ERR, "Error response from ArcGIS server:\n" . "Code: {$error['code']}\n" . "Message: {$error['message']}\n" . "Details: {$details}\n", 'maps');
         //throw new KurogoDataServerException("Map server returned error: \"{$error['message']}\"");
     }
     if (isset($data['serviceDescription'])) {
         // this is a service (top level)
         if (isset($data['spatialReference'], $data['spatialReference']['wkid'])) {
             $wkid = $data['spatialReference']['wkid'];
             $this->setProjection($wkid);
         }
         if (isset($data['singleFusedMapCache'])) {
             $this->isTiledService = true;
         }
         foreach ($data['layers'] as $layerData) {
             $parentId = $layerData['parentLayerId'];
             $folderId = $layerData['id'];
             if (isset($this->folders[$parentId])) {
                 $this->folders[$parentId]->addFolder(new ArcGISFolder($folderId, $layerData['name']));
             } else {
                 $this->createFolder($folderId, $layerData['name']);
             }
         }
         return $this->categories();
     } elseif (isset($data['type'])) {
         // this is a feature layer or group layer
         $this->currentFolder->setSubtitle($data['description']);
         if (isset($data['displayField']) && $data['displayField']) {
             $this->currentFolder->setDisplayField($data['displayField']);
         }
         if (isset($data['geometryType']) && $data['geometryType']) {
             $this->currentFolder->setGeometryType($data['geometryType']);
         }
         if (isset($data['extent'])) {
             $this->currentFolder->setExtent($data['extent']);
             if (!$this->projection) {
                 $this->setProjection($data['extent']['spatialReference']['wkid']);
             }
         }
         if (isset($data['drawingInfo'])) {
             // TODO: figure out the API spec to create styles from this
         }
         if (isset($data['fields'])) {
             $displayField = $this->currentFolder->getDisplayField();
             foreach ($data['fields'] as $fieldInfo) {
                 if ($fieldInfo['type'] == 'esriFieldTypeOID') {
                     $this->currentFolder->setIdField($fieldInfo['name']);
                     continue;
                 } else {
                     if (strtolower($fieldInfo['name']) == 'shape' || strtolower($fieldInfo['name']) == 'shape_length' || strtolower($fieldInfo['name']) == 'shape_area') {
                         continue;
                     } else {
                         if ($fieldInfo['type'] == 'esriFieldTypeGeometry') {
                             $this->currentFolder->setGeometryField($fieldInfo['name']);
                             continue;
                         } else {
                             if (!isset($possibleDisplayField) && $fieldInfo['type'] == 'esriFieldTypeString') {
                                 $possibleDisplayField = $fieldInfo['name'];
                             }
                         }
                     }
                 }
                 $name = $fieldInfo['name'];
                 if (strtoupper($name) == strtoupper($displayField)) {
                     // handle case where display field is returned in
                     // a different capitalization from return fields
                     $name = $displayField;
                 }
                 $this->currentFolder->setFieldAlias($name, $fieldInfo['alias']);
             }
             if (!$this->currentFolder->hasField($displayField) && isset($possibleDisplayField)) {
                 // if the display field is still problematic (e.g. the OID
                 // field was returned as the display field), just choose the
                 // first string field that shows up. obviously if there are no
                 // other string fields then this will also fail.
                 $this->currentFolder->setDisplayField($possibleDisplayField);
             }
         }
         if ($data['type'] == 'Group Layer') {
             return $this->currentFolder->categories();
         }
         return null;
     } elseif (isset($data['features'])) {
         $idField = $this->currentFolder->getIdField();
         if (isset($data['geometryType'])) {
             $geometryType = $data['geometryType'];
         } else {
             $geometryType = $this->currentFolder->getGeometryType();
         }
         if (isset($data['displayFieldName'])) {
             // will set if we got here via layer query
             $displayField = $data['displayFieldName'];
         } else {
             $displayField = $this->currentFolder->getDisplayField();
         }
         foreach ($data['features'] as $featureInfo) {
             if (isset($featureInfo['foundFieldName'])) {
                 // may be set if we got here via search
                 $displayField = $featureInfo['foundFieldName'];
             }
             $title = null;
             $placemarkId = null;
             $displayAttribs = array();
             // use human-readable field alias to construct feature details
             foreach ($featureInfo['attributes'] as $name => $value) {
                 if (strtoupper($name) == strtoupper($displayField)) {
                     $title = $value;
                 } elseif ($idField && strtoupper($name) == strtoupper($idField)) {
                     $placemarkId = $value;
                 } elseif ($value !== null && trim($value) !== '') {
                     $finalField = $this->currentFolder->aliasForField($name);
                     if ($finalField !== null) {
                         $displayAttribs[$finalField] = $value;
                     }
                 }
             }
             $geometryJSON = null;
             if ($geometryType && isset($featureInfo['geometry'])) {
                 $geometryJSON = $featureInfo['geometry'];
             }
             if ($title || $placemarkId) {
                 // only create placemarks if there is usable data associated with it
                 $geometry = null;
                 if ($geometryJSON) {
                     switch ($geometryType) {
                         case 'esriGeometryPoint':
                             $geometry = new ArcGISPoint($geometryJSON);
                             break;
                         case 'esriGeometryPolyline':
                             $geometry = new ArcGISPolyline($geometryJSON);
                             break;
                         case 'esriGeometryPolygon':
                             $geometry = new ArcGISPolygon($geometryJSON);
                             break;
                     }
                 }
                 $geometry = $this->projectGeometry($geometry);
                 $placemark = new BasePlacemark($geometry);
                 foreach ($displayAttribs as $name => $value) {
                     $placemark->setField($name, $value);
                 }
                 if ($title === null) {
                     $title = $placemarkId;
                 }
                 if ($placemarkId === null) {
                     $placemarkId = $title;
                 }
                 $placemark->setTitle($title);
                 $placemark->setId($placemarkId);
                 $this->currentFolder->addPlacemark($placemark);
             }
         }
         return $this->currentFolder->placemarks();
     }
     return null;
 }