From 3273b46ef486d9fe205882aa7ae435aafe16a2bf Mon Sep 17 00:00:00 2001 From: priyatham Date: Sun, 27 Apr 2025 16:24:20 -0700 Subject: [PATCH] search bar start --- package-lock.json | 9 +++++++ package.json | 1 + src/App.css | 11 ++++++++ src/components/OpenLayerMap.tsx | 47 ++++++++++++++++++++++++++++----- src/components/SearchBar.tsx | 30 +++++++++++++++++++++ 5 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 src/components/SearchBar.tsx diff --git a/package-lock.json b/package-lock.json index 7dd04d9..73a7ba1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "ol": "^10.5.0", + "ol-ext": "^4.0.31", "react": "^19.0.0", "react-dom": "^19.0.0", "react-router-dom": "^7.5.0", @@ -2523,6 +2524,14 @@ "url": "https://opencollective.com/openlayers" } }, + "node_modules/ol-ext": { + "version": "4.0.31", + "resolved": "https://registry.npmjs.org/ol-ext/-/ol-ext-4.0.31.tgz", + "integrity": "sha512-byh26JcXZggkLUY79+c29cxf2ovkkwz5niWJzOIN+dLPDJ+ogSn0y4Wl8fIS9O2JtQff5/cInHRImgZBvl+N1g==", + "peerDependencies": { + "ol": ">= 5.3.0" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", diff --git a/package.json b/package.json index cd40ae6..af27824 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "ol": "^10.5.0", + "ol-ext": "^4.0.31", "react": "^19.0.0", "react-dom": "^19.0.0", "react-router-dom": "^7.5.0", diff --git a/src/App.css b/src/App.css index 6211cbb..9ccfcef 100644 --- a/src/App.css +++ b/src/App.css @@ -29,3 +29,14 @@ width: 220px; color: black; }; + +.input { + margin-bottom: 30px; + padding: 5px 15px; + width: 300px; +} + +.btn { + padding: 5px 10px; + cursor: pointer; +} diff --git a/src/components/OpenLayerMap.tsx b/src/components/OpenLayerMap.tsx index 48f0f00..d11c4c7 100644 --- a/src/components/OpenLayerMap.tsx +++ b/src/components/OpenLayerMap.tsx @@ -7,7 +7,9 @@ import Overlay from 'ol/Overlay' //import Popup from 'ol/Popup' //import {tile as tileStrategy} from 'ol/loadingstrategy'; //import {createXYZ} from 'ol/tilegrid'; +import {Search} from 'ol-ext/control/SearchFeature'; import { OSM } from 'ol/source'; +import {Select} from 'ol/interaction/Select'; import { Coordinate } from 'ol/coordinate'; import VectorLayer from "ol/layer/Vector" import VectorSource from "ol/source/Vector" @@ -16,6 +18,15 @@ import GeoJSON from "ol/format/GeoJSON" import {Style, Icon, Fill, Circle, Stroke} from "ol/style" const OpenLayersMap = () => { + const [term, setTerm] = useState(''); + + const submitForm = (event: React.FormEvent) => { + // Preventing the page from reloading + event.preventDefault(); + + // Do something + alert(term); + } const [data,setData] = useState({}); const mapDivRef = useRef(null); const popupRef = useRef(null); @@ -104,6 +115,15 @@ view: new View({ }), overlays: [overlay], }); + // Control Select + var select = new Select({}); + map.addInteraction(select); + + var search = new Search ({ + source:vectorsource_offset, + + + }) map.on('click', (e) => { setClickedCoordinate(e.coordinate); @@ -118,16 +138,19 @@ const feature = map.forEachFeatureAtPixel(e.pixel, function (feature) { // Show popup at clicked position overlay.setPosition(coordinate); if(feature) - console.log("feature " + JSON.stringify(feature)); + console.log("feature " + JSON.stringify(feature,null,'\t')); if(feature && feature.get("subname")){ if (popupRef.current) { - popupRef.current.innerHTML = `

You clicked here:

` + - `

Parcel

` + - - `

${feature.get('subname')}

` + + popupRef.current.innerHTML = `

Parcel

` + + `

Parcel ID ${feature.get('parcelid')}

` + + `

APN ${feature.get('apn')}

` + + `

Legldesc ${feature.get('legldesc')}

` + + `

x \& y coord${feature.get('x_coord')} / ${feature.get('y_coord')}

` + + `

${feature.get('situs_address')} ${feature.get('situs_street')} ${feature.get('situs_suffix')} ${feature.get('situs_community')} ${feature.get('situs_zip')}

` + `

Unit Qty ${feature.get('unitqty')}

` + - `

${feature.get('situs_community')} ${feature.get('situs_zip')}

` + + `

Usable sq ft. ${feature.get('usable_sq_feet')}

` + + `

total lvg area ${feature.get('total_lvg_area')}

` + `

bedrooms ${feature.get('bedrooms')} Baths ${feature.get('baths')}

` + `
`; } @@ -166,6 +189,18 @@ const feature = map.forEachFeatureAtPixel(e.pixel, function (feature) { return ( <>
+
+
+ setTerm(e.target.value)} + type="text" + placeholder="Enter a term" + className="input" + /> + +
+
{clickedCoordinate && ( diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx new file mode 100644 index 0000000..83eb7ae --- /dev/null +++ b/src/components/SearchBar.tsx @@ -0,0 +1,30 @@ +import React, { useState } from 'react'; + +const SearchBar = () => { + const [term, setTerm] = useState(''); + + const submitForm = (event: React.FormEvent) => { + // Preventing the page from reloading + event.preventDefault(); + + // Do something + alert(term); + } + + return ( +
+
+ setTerm(e.target.value)} + type="text" + placeholder="Enter a term" + className="input" + /> + +
+
+ ); +}; + +export default SearchBar;