Example #1
0
function arrayFromMapFeature(MapFeature $feature) {
    $category = $feature->getCategory();
    if (is_array($category)) {
        $category = implode(MAP_CATEGORY_DELIMITER, $category);
    }
    $result = array(
        'title' => $feature->getTitle(),
        'subtitle' => $feature->getSubtitle(),
        'id' => $feature->getIndex(),
        'category' => $category,
        'description' => $feature->getDescription(),
        );

    $geometry = $feature->getGeometry();
    if ($geometry) {
        $center = $geometry->getCenterCoordinate();
        if ($geometry instanceof MapPolygon) {
            $serializedGeometry = $geometry->getRings();
        } elseif ($geometry instanceof MapPolyline) {
            $serializedGeometry = $geometry->getPoints();
        } elseif ($geometry) {
            $serializedGeometry = $geometry->getCenterCoordinate();
        }
        $result['geometry'] = $serializedGeometry;
        $result['lat'] = $center['lat'];
        $result['lon'] = $center['lon'];
    }
    
    return $result;
}
Example #2
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();
        }
    }
    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();');
        }
    }