Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added functionality for mongoDB polygon queries and added visual exam…

…ple of displaying polygons via gSpot with polygons.html
  • Loading branch information...
commit 1806a453dee61336e6bb1f67e3be15f0b0f6692c 1 parent 728a6f8
msmalley authored
5 README.md
View
@@ -1,3 +1,5 @@
+* IMPORTANT - Geoply Requires MongoDB 2.0+
+* ----------------------------------------
* Geoply is a MongoDB-Based Geo-Location Toolkit
* Includes 1GB+ DB, MongoBase and gSpot
* Follow [Mark on Twitter](http://twitter.com/m_smalley) for more updates
@@ -9,9 +11,10 @@
# Advanced and Newly Introduced Features:
* Ability to have custom icons per marker
-* Use of GeoNames feature_code for icon (5 codes currently supported)
+* Use of GeoNames feature_code for icon (8 codes currently supported)
* Function for checking if icon exists, else show default icon
* Query from the URL, with current variables including (limit and feature_code)
+* Polygon Queries and Visual Display of Polygons through gSpot
# Installation Instructions:
* Ensure MongoDB and Mongo PHP Drivers Working
22 ROADMAP.txt
View
@@ -0,0 +1,22 @@
+Geoply is currently at version 1.0.2
+
+Some of these future features will be given proper time-lines later, but for
+now, this is just a rough idea of things that need to get done...
+
+Little things to do:
+* Optional AJAX Loader (Cover Screen)
+* More feature_code / icons supported
+* Selection of InfoWindow Styles
+* Options for Individual Marker BGs
+
+Big things to do:
+* OpenStreetMap Support Included
+* Included OpenStreetMap GridFS Storage
+* MapReduce Features / Functions
+* Inclusion of Worldwide Country Polygon Data
+* Route-Support Display / Query
+* WYSIWYG Editor (Polygons, Routes, Points)
+* WYSIWYG Editor for Map Tiles
+
+Most Recently Added:
+* Polygon Support Display / Query
1  data/malaysia.json
View
@@ -0,0 +1 @@
+{"malaysia":[[[[73.18,-0.69],[73.16,-0.68],[73.17,-0.68],[73.18,-0.69]]],[[[73.2,-0.68],[73.19,-0.68],[73.2,-0.67],[73.2,-0.68]]],[[[73.13,-0.67],[73.13,-0.67],[73.12,-0.65],[73.13,-0.67]]],[[[73.23,-0.65],[73.23,-0.63],[73.24,-0.62],[73.23,-0.65]]],[[[73.12,-0.64],[73.09,-0.61],[73.09,-0.58],[73.12,-0.64]]],[[[73.25,-0.61],[73.24,-0.59],[73.25,-0.58],[73.25,-0.61]]]]}}
1  data/world.json
View
1 addition, 0 deletions not shown
27 js/g-spot.js
View
@@ -10,6 +10,7 @@
lng: false,
imgs: 'img',
markers: false,
+ polygon: false,
check_markers: true
};
@@ -64,6 +65,20 @@
check_markers = this.options.check_markers;
ajax = $(map_container).attr('data-ajax');
+ if(this.options.polygon!==false){
+ poly_count = 0; poly_array = [];
+ $.each(this.options.polygon, function(key, latlng){
+ lat = false; lng = false;
+ $.each(latlng, function(key, value){
+ if(key==0) lat = value;
+ if(key==1) lng = value;
+ });
+ google_point = new google.maps.LatLng(lat, lng);
+ poly_array[poly_count] = google_point;
+ poly_count++;
+ })
+ }
+
if(((adhoc_zoom!==null)&&(adhoc_zoom!==false)&&((!this.options.zoom))||(($(map_container).attr('data-override')=='true')&&(adhoc_zoom)))){
this.options.zoom = adhoc_zoom;
} if(((adhoc_type!==null)&&(adhoc_type!==false)&&((!this.options.type))||(($(map_container).attr('data-override')=='true')&&(adhoc_type)))){
@@ -139,6 +154,18 @@
debug.log('THIS LNG = ', this.options.lng);
}
+ if(poly_count>0){
+ this_polygon = new google.maps.Polygon({
+ paths: poly_array,
+ strokeColor: "#FF0000",
+ strokeOpacity: 0.5,
+ strokeWeight: 2,
+ fillColor: "#FF0000",
+ fillOpacity: 0.2
+ });
+ this_polygon.setMap(map);
+ }
+
adhoc_marker = false;
if((adhoc_lat!==null)&&(adhoc_lat!==false)&&(adhoc_lng!==null)&&(adhoc_lng!==false)){
if((is_numeric(adhoc_lat)) && (is_numeric(adhoc_lng))){
23 mb/classes/mb_db.class.php
View
@@ -184,6 +184,7 @@ public function find($args = false){
'order' => false,
'id' => false,
'near' => false,
+ 'within' => false,
'distance' => 100
);
$settings = $this->settings($args,$defaults);
@@ -208,10 +209,11 @@ public function find($args = false){
try{
- if(isset($settings['near'])){
+ if($this->is_set($settings['near'])){
$geo_near_query = array('geoNear'=>$settings['col'],'near'=>$settings['near'],'$spherical'=>true,'$maxDistance'=>$settings['distance']/6378,'num'=>$settings['limit']);
$geo_results = $dbh->command($geo_near_query);
+ //$result = array(); $result[0]=$geo_results; return $result;
foreach($geo_results['results'] as $result){
if(is_array($result['obj'])){
$temp_geo_results[] = $result['obj'];
@@ -219,6 +221,7 @@ public function find($args = false){
} $results = $temp_geo_results;
return $results;
+
}elseif(is_array($settings['col'])){
$combined_array = false;
@@ -238,9 +241,23 @@ public function find($args = false){
return $combined_array;
}else{
-
+
+ if(isset($settings['within'])){
+ /* NEW WHERE NEEDED */
+ $settings['where'] = array(
+ 'loc' => array(
+ '$within' => array(
+ '$polygon' => $settings['within']
+ )
+ )
+ );
+ }
+ //return $settings['where'];
$collection = $dbh->$settings['col'];
- $results = $this->arrayed($collection->find($settings['where'])->sort($sort_clause)->skip($settings['offset'])->limit($settings['limit']));
+ //return $settings['where'];
+ //return $collection->find($settings['where']);
+ //return $collection->find($settings['where'])->timeout(-1)->sort($sort_clause)->skip($settings['offset'])->limit($settings['limit']);
+ $results = $this->arrayed($collection->find($settings['where'])->sort($sort_clause)->skip($settings['offset'])->limit($settings['limit'])->timeout(-1));
return $results;
}
51 polygons.html
View
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<head>
+
+ <meta charset="utf-8">
+
+ <title>Geoply - The MongoDB Geo-Location Toolkit</title>
+
+ <script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
+ <script src="js/jquery-1.6.4.min.js"></script>
+
+ <link rel="stylesheet" href="css/g-spot.css">
+ <script src="js/g-spot.js"></script>
+
+ <!--[if lt IE 9]>
+ <style>.git-ribbon { top: -2em; left: -2em; }</style>
+ <![endif]-->
+
+ <script>
+
+ /* CREATING A MAP IS THIS SIMPLE */
+ polygon = [[3.154346,101.708443],[3.155857,101.721784],[3.147474,101.723233],[3.146322,101.711817],[3.154346,101.708443]];
+ options = { polygon: polygon };
+ $(document).ready(function(){
+ $('#gspot').gSpot(options);
+ });
+
+ </script>
+
+</head>
+<body>
+
+ <div class="git-ribbon"><a href="https://github.com/msmalley/Geoply">Fork Me on GitHub</a></div>
+
+ <div id="header">
+ <h1>Geoply</h1>
+ <span class="social-media-links">
+ <a href="http://twitter.com/m_smalley" class="twitter">Twitter</a>
+ <a href="http://facebook.com/mark.smalley" class="facebook">Facebook</a>
+ <a href="http://www.linkedin.com/profile/view?id=10311122" class="linkedin">Linked-In</a>
+ </span>
+ </div>
+
+ <div id="map-wrapper">
+
+ <div id="gspot" data-ajax="queries/polygons.php" data-zoom="16" data-override="true"></div>
+
+ </div>
+
+</body>
+</html>
6 queries/icons.php
View
@@ -34,8 +34,6 @@
else $lng = 101.712624; // These defaults represent KL MUG HQ
// More information on KL MUG - http://lauli.ma/klmug
-$i = 0;
-
foreach($available_codes as $code => $icon){
$query = array(
@@ -66,15 +64,13 @@
$marker_info['content'] = '<pre>'.print_r($result,true).'</pre>';
}
$marker_info['icon'] = $icon;
- $markers[$i] = $marker_info;
+ $markers[] = $marker_info;
$this_count++;
}
}
}
}
- $i++;
-
}
echo json_encode($markers);
58 queries/polygons.php
View
@@ -0,0 +1,58 @@
+<?php
+
+$markers = array();
+
+define('MONGODB_NAME', 'geo');
+
+require_once(dirname(__DIR__).'/mb/classes/mb_base.class.php'); // The one file to rule them all
+require_once(dirname(__DIR__).'/mb/classes/mb_db.class.php'); // Required for MongoDB Connections
+
+$db = new MONGOBASE_DB; // Assign the DB
+
+$lat = 3.152864; // These defaults represent KL MUG HQ
+$lng = 101.712624; // These defaults represent KL MUG HQ
+// More information on KL MUG - http://lauli.ma/klmug
+
+/* LAT / LNG
+$tl = array(3.154346,101.708443);
+$tr = array(3.155857,101.721784);
+$br = array(3.147474,101.723233);
+$bl = array(3.146322,101.711817);
+*/
+
+/* LNG / LAT */
+$tl = array('lng'=>101.708443,'lat'=>3.154346);
+$tr = array('lng'=>101.721784,'lat'=>3.155857);
+$br = array('lng'=>101.723233,'lat'=>3.147474);
+$bl = array('lng'=>101.711817,'lat'=>3.146322);
+$near_my_office[] = $tl;
+$near_my_office[] = $tr;
+$near_my_office[] = $br;
+$near_my_office[] = $bl;
+
+$query = array(
+ 'col' => 'geonames',
+ 'limit' => 100,
+ 'within' => $near_my_office
+);
+$results = $db->find($query);
+
+if((isset($results))&&(is_array($results))){
+ foreach($results as $result){
+ $marker_info['lat'] = $result['loc']['lat'];
+ $marker_info['lng'] = $result['loc']['lng'];
+ $marker_info['title'] = $result['name'];
+ $marker_info['this_id'] = $db->_id($result['_id']);
+ $marker_info['slug'] = '?id='.$db->_id($result['_id']);
+ if(count($markers)<1){
+ $marker_info['open'] = true;
+ $marker_info['content'] = '<p>This example shows the results of a polygon query, where we have currently hard-coded the polygon to be the error surrounding MongoPress HQ. This is querying 7.9+ Million documents and only displaying those within the polygon. We will soon be introducing polygons for each country!</p>';
+ }else{
+ $marker_info['open'] = false;
+ $marker_info['content'] = '<pre>'.print_r($result,true).'</pre>';
+ }
+ $markers[] = $marker_info;
+ }
+}
+
+echo json_encode($markers);
Please sign in to comment.
Something went wrong with that request. Please try again.