summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2014-12-03 18:40:57 +0100
committerFélix Sipma <felix.sipma@no-log.org>2014-12-03 18:40:57 +0100
commit6632065a5f13cb2296007eb78085f777d9702022 (patch)
tree87897ad1cd81210df1a6bc74796662d6e6340ff6
parent9cad9cb6f89d1e839abaf3334e7e39191a4a3fd6 (diff)
PlaceListR json
-rw-r--r--Model.hs30
-rw-r--r--templates/place-list.julius15
2 files changed, 37 insertions, 8 deletions
diff --git a/Model.hs b/Model.hs
index 20a33f4..9bf554c 100644
--- a/Model.hs
+++ b/Model.hs
@@ -37,12 +37,26 @@ instance FromJSON Shop where
parseJSON _ = mzero
+toGeoFeature :: Entity Place -> G.GeoFeature Value
+toGeoFeature (Entity pid p) = G.GeoFeature
+ Nothing
+ (G.Point $ G.GeoPoint pointpos)
+ (object
+ [ "id" .= (String $ toPathPiece pid)
+ , "ident" .= (String $ placeIdent p)
+ ])
+ Nothing
+ where
+ pointpos =
+ [ pntLat $ placeLocation p
+ , pntLon $ placeLocation p
+ ]
+
instance ToJSON (Entity Place) where
- toJSON (Entity pid p) = toJSON $ G.GeoFeature
- Nothing
- (G.Point $ G.GeoPoint [pntLat $ placeLocation p, pntLon $ placeLocation p])
- (object
- [ "id" .= (String $ toPathPiece pid)
- , "ident" .= (String $ placeIdent p)
- ])
- Nothing
+ toJSON = toJSON . toGeoFeature
+
+toGeoFeatureCollection :: [Entity Place] -> G.GeoFeatureCollection Value
+toGeoFeatureCollection l = G.GeoFeatureCollection Nothing $ map toGeoFeature l
+
+instance ToJSON [Entity Place] where
+ toJSON = toJSON . toGeoFeatureCollection
diff --git a/templates/place-list.julius b/templates/place-list.julius
index 477198e..465be98 100644
--- a/templates/place-list.julius
+++ b/templates/place-list.julius
@@ -2,6 +2,21 @@ L.Icon.Default.imagePath = '@{StaticR $ StaticRoute ["images"] []}';
var map = L.map(#{toJSON mapid}).setView(#{toLeaflet center}, 9);
+function importFeature (feature, layer) {
+ layer.bindPopup(feature.properties.ident);
+};
+
+function placePointToLayer (feature, latlng) {
+ return L.marker(latlng, {});
+};
+
+$.getJSON("@{PlaceListR}", function(data) {
+ L.geoJson(data, {
+ pointToLayer: placePointToLayer,
+ onEachFeature: importFeature
+ }).addTo(map);
+});
+
// add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'