Skip to content

Commit

Permalink
fetch minimum station info from server
Browse files Browse the repository at this point in the history
  • Loading branch information
ponkore committed Mar 5, 2014
1 parent 5148eec commit 401123a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 39 deletions.
79 changes: 44 additions & 35 deletions resources/public/js/jrw-lines-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var lon=135.500035;
var zoom=12;

var map; //complex object of type OpenLayers.Map
var layer;

//Initialise the 'map' object
$(function() {
Expand Down Expand Up @@ -42,7 +43,7 @@ $(function() {
fillOpacity: 1.0,
label : "${name}",
fontColor: "${fontcolor}",
fontSize: "10px",
fontSize: "15px",
fontFamily: "Courier New, monospace",
fontWeight: "bold",
labelOutlineColor: "white",
Expand All @@ -51,9 +52,28 @@ $(function() {
pointRadius: 8,
strokeColor: "#00FF00"}});

function create_features(url, create_feature_fn, layer) {
layer = new OpenLayers.Layer.Vector("L01", { styleMap: composedDrawStyle });
map.addLayer(layer);

function create_feature_fn(val, geometry) {
var isShinkansen = (val["properties"]["name"] == "山陽新幹線");
var feature = new OpenLayers.Feature.Vector(geometry, {
id: val["id"],
name: val["properties"]["name"],
fontcolor: (isShinkansen ? "#0000FF" : "#000000"),
strokeWidth: 2.0,
strokeColor: "#FF0000"
});
return feature;
}

function create_features(param) {
var geojson_format = new OpenLayers.Format.GeoJSON();
$.getJSON(url, "",
var url = "/map/stations";
if (layer != undefined) {
layer.removeAllFeatures();
}
$.getJSON(url, param,
function(data, textStatus, jqXHR) {
$.each(data["features"], function(i, val) {
var geometry = geojson_format.parseGeometry(val["geometry"]);
Expand All @@ -66,41 +86,30 @@ $(function() {
});
}

function feature_composed_fn(val, geometry) {
var isShinkansen = (val["properties"]["N05_002"] == "山陽新幹線");
var isStation = (val["geometry"]["type"] == "Point");
var nn = (isStation ? val["properties"]["N05_011"] : val["properties"]["N05_002"]);
var feature = new OpenLayers.Feature.Vector(geometry, {
id: val["id"],
name: nn,
fontcolor: (isShinkansen ? "#0000FF" : "#000000"),
strokeWidth: (isStation? 2.0 : 4.5),
strokeColor: (isStation? "#FF0000" : (isShinkansen ? "#0000FF" : "#000000"))
});
return feature;
}

function mapMoved(event) {
// log(event.type);
var extent = map.getExtent().transform(
new OpenLayers.Projection("EPSG:900913"),
new OpenLayers.Projection("EPSG:4326")
);
var zoom = map.getZoom();
var scale = map.getScale();
console.debug("left:" + extent.left +
",top:" + extent.top +
",right:" + extent.right +
",bottom:" + extent.bottom +
",zoom:" + zoom +
",scale:" + scale);
create_features({
left: extent.left,
top: extent.top,
right: extent.right,
bottom: extent.bottom,
zoom: zoom,
scale: scale
});
}

function mapZoomEnd(event) {
// log(event.type + "/" + map.numZoomLevels + "/" + map.getZoom());
// var displayStationLabel = (map.getZoom() > 12);
console.debug(event.type + "/" + map.numZoomLevels + "/" + map.getZoom());
}

// function log(msg) {
// document.getElementById("output").innerHTML += msg + "\n";
// }

var urls = [
"JRW-railroad.geojson",
"JRW-stations.geojson"
];
$.each(urls, function(i, val) {
var layer = new OpenLayers.Layer.Vector("L" + i, { styleMap: composedDrawStyle });
map.addLayer(layer);
var file = "/map/" + val;
create_features(file, feature_composed_fn, layer);
});
});
20 changes: 19 additions & 1 deletion src/mapmap/routes/map.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
(ns mapmap.routes.map
(:use compojure.core)
(:require [mapmap.views.layout :as layout]
[mapmap.views.geojson-util :as gj-util]
[mapmap.model.geojson :as model]
[noir.response :refer [json]]))

(defn- map-page
"returns JSON string"
[id]
(slurp (str "src/mapmap/model/json/" id)))

(defn- stations-json
""
[params]
(let [query-params (:query-params params)
left (-> (get query-params "left") Double/valueOf)
top (-> (get query-params "top") Double/valueOf)
right (-> (get query-params "right") Double/valueOf)
bottom (-> (get query-params "bottom") Double/valueOf)
filter-fn (fn [info]
(when-let [[lon lat] (:geometry info)]
(and (<= left lon right) (<= bottom lat top))))]
(->> (model/get-stations filter-fn)
(map gj-util/to-station-feature-map)
(gj-util/make-feature-collection)
(json))))

(defn- map-view
""
[]
(layout/render "ng-map.html" {}))

(defroutes map-routes
(GET "/mapview" [] (map-view))
(GET "/map/:id" [id] (map-page id)))
(GET "/map/stations" params (stations-json params)))
6 changes: 3 additions & 3 deletions src/mapmap/views/geojson_util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
(:require [clojure.data.json :as json]
[mapmap.model.geojson :as model]))

(defn- to-station-feature-map
(defn to-station-feature-map
""
[info]
(assoc {}
:type "Feature"
:id (:id info)
:properties {:name (:station-name info)}
:geometry (:geometry info)))
:geometry {:type "Point" :coordinates (:geometry info)}))

(defn- to-line-feature-map
(defn to-line-feature-map
""
[info]
(assoc {}
Expand Down

0 comments on commit 401123a

Please sign in to comment.