Example #1
0
 $('#spatialquery_selectbutton').click(function() {
     if (state.spatialquery.selectButtonState === 'select') {
         query.startSpatialQuery();
     }
     else if (state.spatialquery.selectButtonState === 'finish') {
         query.endSpatialQuery();
     }
     else if (state.spatialquery.selectButtonState === 'clear') {
         query.clearSpatialQuery();
     }
 });
Example #2
0
            $('#spatialquery_acceptbutton').click(function() {
                if (state.spatialquery.type === undefined) {
                    return;
                }
                query.endSpatialQuery();
                var qStr = ""
                if (state.spatialquery.type === "rect") {
                    var minLat = Math.min(state.spatialquery.coords[0].lat, state.spatialquery.coords[1].lat);
                    var maxLat = Math.max(state.spatialquery.coords[0].lat, state.spatialquery.coords[1].lat);
                    var minLng = Math.min(state.spatialquery.coords[0].lng, state.spatialquery.coords[1].lng);
                    var maxLng = Math.max(state.spatialquery.coords[0].lng, state.spatialquery.coords[1].lng);
					//now clip
					var minLat = Math.max(minLat, -90);
					var maxLat = Math.min(maxLat, 90);
					var minLng = Math.max(minLng, -180);
					var maxLng = Math.min(maxLng, 180);
                    qStr = "$geo:" + minLng + "," + minLat + "," + maxLng + "," + maxLat;
                }
                else if (state.spatialquery.type === "path") {
                    if (state.spatialquery.coords.length > 0) {
                        qStr = "$path:" + jQuery('#spatialquery_radius').val();
                        for(let coord of state.spatialquery.coords) {
                            qStr += "," + coord.lat + "," + coord.lng;
                        }
                    }
                }
                else if (state.spatialquery.type === "point") {
                    if (state.spatialquery.coords.length > 0) {
                        qStr = "$point:" + jQuery('#spatialquery_radius').val();
						qStr += "," + state.spatialquery.coords[0].lat + "," + state.spatialquery.coords[0].lng;
                    }
                }
                else if (state.spatialquery.type === "cell") {
                    if (state.spatialquery.coords.length > 0) {
                        qStr = "$cell:"+ state.spatialquery.coords[0].lat + "," + state.spatialquery.coords[0].lng;
                    }
                }
                else if (state.spatialquery.type === "poly") {
                    if (state.spatialquery.coords.length >= 3) {
                        qStr = "$poly";
                        var delim = ":"
                        for(let coord of state.spatialquery.coords) {
                            qStr += delim + coord.lat + "," + coord.lng;
                            delim = ",";
                        }
                    }
                }
                if (qStr.length) {
					var id;
					for(i=0; true; ++i) {
						id = i + ""
						if (!state.spatialObjects.store.count(id)) {
							break;
						}
					}
					var data = {
						name : id,
						type : state.spatialquery.type,
						mapshape : state.spatialquery.mapshape,
						query : qStr
					};
					state.spatialObjects.store.insert(id, data);
					state.spatialObjects.names.insert(id, id);
					map.appendSpatialObjectToTable(id);
                }
                query.clearSpatialQuery();
            });