         polygon-south-pole (polygon -45 -80, -135 -80, 135 -80, 45 -80, -45 -80)
         polygon-antimeridian (polygon 135 -10, -135 -10, -135 10, 135 10, 135 -10)
         polygon-near-sp (polygon 168.1075 -78.0047, 170.1569,-78.4112, 172.019,-78.0002, 169.9779,-77.6071, 168.1075 -78.0047)
-        search-area (polygon 8.38,12.57,11.38,14.8,3.39,22.53,0.35,21.85,8.38,12.57)]
+
+        ;; Search area as a polygon
+        ; search-area (assoc (polygon 8.38,12.57,11.38,14.8,3.39,22.53,0.35,21.85,8.38,12.57)
+        ;                    :options {:id "polygon"})
+
+
+        ;; Search area as a bounding rectangle
+        search-area (assoc (m/mbr -5 5 5 -5) :options {:id "bounding_box"})
+        ]
 
     (visual-interactive-search [polygon-ne
                                 polygon-se

            [cmr.spatial.dev.viz-helper :as viz-helper]
            [cmr.spatial.serialize :as srl]
            [cmr.common.dev.util :as dev-util]
            [cmr.spatial.lr-binary-search :as lbs]))

(defn polygon
  "Creates a single ring polygon with the given ordinates. Points must be in counter clockwise order."

  [shape]
  (assoc (srl/shape->lr shape) :options {:color "AA76775E"}))

(defmulti ords-str->shape
  (fn [spatial-type ords-str]
    spatial-type))

(defmethod ords-str->shape :polygon
  [spatial-type ords-str]
  (let [ords (map #(Double. ^String %) (str/split ords-str #","))]
    (derived/calculate-derived (apply polygon ords))))

(defmethod ords-str->shape :bounding_box
  [spatial-type ords-str]
  (let [[w n e s] (map #(Double. ^String %) (str/split ords-str #","))]
    (m/mbr w n e s)))

(defn handle-search-area-moved
  "This is the VDD callback function. Everytime the search area is moved this will be called with the
  new ordinates of the search area. It removes the existing MBR and LR of the search area, recalculates
  and displays them. It then searches for matches and says the number of hits that match."
  [id-ords-str]
  (println "Search area moved: " id-ords-str)

  (let [[id ords-str] (str/split id-ords-str #":")
        spatial-type (keyword id)
        shape (ords-str->shape spatial-type ords-str)]

    (let [results (search/find-refs :granule {spatial-type (cmr.spatial.codec/url-encode
                                                             shape)})
          {:keys [hits errors]} results]
      (if errors
        (doseq [error errors]
          (dev-util/speak error))
        (dev-util/speak (str hits))))))


(defn visual-interactive-search
  "Execute this to start a visual interactive search. The shapes will be ingested as granules. The
  search area will be displayed on the map as a draggable shape. As the search area is moved
  searches will be executed to find granules that match."
  [shapes search-area]
  (let [shapes (map derived/calculate-derived shapes)]
    (ingest/reset)
    (ingest/create-provider "PROV1")

    (let [coll (d/ingest "PROV1" (dc/collection {:spatial-coverage (dc/spatial :geodetic)}))]
      (doseq [shape shapes]
        (d/ingest "PROV1" (dg/granule coll {:spatial-coverage (dg/spatial shape)}))))
    (index/refresh-elastic-index)

    ;; Save the shapes for display
    (viz-helper/clear-geometries)
    (viz-helper/add-geometries shapes)

    (let [callback "cmr.demos.visual-spatial-search/handle-search-area-moved"
          search-area (-> search-area
                          derived/calculate-derived
                          (update-in [:options]
                                     merge
                                     {:callbackFn callback
                                      :style {:width 5 :color "9918A0ff"}
                                      :draggable true}))]
      (viz-helper/add-geometries [search-area]))))


(comment
