Esempio n. 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;
 }
Esempio n. 2
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();
 }
Esempio n. 3
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;
 }