aio-map 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.css +78 -0
- package/index.d.ts +85 -0
- package/index.js +1 -0
- package/package.json +27 -0
package/index.css
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
.ai-map {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
position: relative;
|
|
5
|
+
height: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.ai-map-footer {
|
|
9
|
+
padding: 0 6px;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
background: #f8f8f8;
|
|
12
|
+
display: flex;
|
|
13
|
+
width: 100%;
|
|
14
|
+
align-items: center;
|
|
15
|
+
position: relative;
|
|
16
|
+
height: 48px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ai-map-footer button {
|
|
20
|
+
background: #0069ff;
|
|
21
|
+
color: #fff;
|
|
22
|
+
font-family: inherit;
|
|
23
|
+
border: none;
|
|
24
|
+
border-radius: 6px;
|
|
25
|
+
padding: 0 24px;
|
|
26
|
+
height: 36px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ai-map-footer-html {
|
|
30
|
+
flex: 1;
|
|
31
|
+
height: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ai-map-header {
|
|
35
|
+
height: 48px;
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
width: 100%;
|
|
39
|
+
z-index: 1000;
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
display: flex;
|
|
42
|
+
padding: 0 6px;
|
|
43
|
+
align-items: center;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ai-map .leaflet-marker-icon {
|
|
47
|
+
width: 0px !important;
|
|
48
|
+
height: 0px !important;
|
|
49
|
+
margin: 0 !important;
|
|
50
|
+
display: flex !important;
|
|
51
|
+
justify-content: center !important;
|
|
52
|
+
align-items: flex-end !important;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ai-map .marker-icon {
|
|
56
|
+
position: relative;
|
|
57
|
+
padding-bottom: 0.63em;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.ai-map .marker-icon-circle {
|
|
62
|
+
width: 3em;
|
|
63
|
+
height: 3em;
|
|
64
|
+
border: 0.3em solid red;
|
|
65
|
+
border-radius: 100%;
|
|
66
|
+
color: red;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.ai-map .marker-icon-arrow {
|
|
70
|
+
border-left: 1em solid transparent;
|
|
71
|
+
border-right: 1em solid transparent;
|
|
72
|
+
border-top: 1em solid red;
|
|
73
|
+
left: calc(50% - 1em);
|
|
74
|
+
bottom: 0;
|
|
75
|
+
z-index: 10000;
|
|
76
|
+
position: absolute;
|
|
77
|
+
|
|
78
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LeafletEvent } from "leaflet";
|
|
2
|
+
import { FC, ReactNode } from "react";
|
|
3
|
+
import 'leaflet/dist/leaflet.css';
|
|
4
|
+
import './index.css';
|
|
5
|
+
type I_pos = [number, number];
|
|
6
|
+
export type I_marker = {
|
|
7
|
+
pos: [number, number];
|
|
8
|
+
html?: ReactNode;
|
|
9
|
+
eventHandlers?: any;
|
|
10
|
+
};
|
|
11
|
+
export type I_shapeStyle = {
|
|
12
|
+
stroke?: {
|
|
13
|
+
color?: string;
|
|
14
|
+
width?: number;
|
|
15
|
+
dash?: string;
|
|
16
|
+
};
|
|
17
|
+
fill?: {
|
|
18
|
+
color?: string;
|
|
19
|
+
opacity?: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type I_circle = {
|
|
23
|
+
type: 'circle';
|
|
24
|
+
center: I_pos;
|
|
25
|
+
radius?: number;
|
|
26
|
+
style?: I_shapeStyle;
|
|
27
|
+
};
|
|
28
|
+
export type I_rect = {
|
|
29
|
+
type: 'rect';
|
|
30
|
+
points: I_pos[];
|
|
31
|
+
style?: I_shapeStyle;
|
|
32
|
+
};
|
|
33
|
+
export type I_polyline = {
|
|
34
|
+
type: 'polyline';
|
|
35
|
+
points: I_pos[];
|
|
36
|
+
style?: I_shapeStyle;
|
|
37
|
+
};
|
|
38
|
+
export type I_shape = I_circle | I_rect | I_polyline;
|
|
39
|
+
type I_Map = {
|
|
40
|
+
children?: React.ReactNode;
|
|
41
|
+
onChange?: (coords: I_pos) => void;
|
|
42
|
+
zoom?: {
|
|
43
|
+
value?: number;
|
|
44
|
+
wheel?: boolean;
|
|
45
|
+
control?: boolean;
|
|
46
|
+
onChange?: (zoom: number) => void;
|
|
47
|
+
};
|
|
48
|
+
markers?: I_marker[];
|
|
49
|
+
value?: I_pos;
|
|
50
|
+
marker?: ReactNode | false;
|
|
51
|
+
style?: any;
|
|
52
|
+
onClick?: () => void;
|
|
53
|
+
dragging?: boolean;
|
|
54
|
+
submitText?: string;
|
|
55
|
+
onSubmit?: (pos: I_pos) => void;
|
|
56
|
+
shapes?: I_shape[];
|
|
57
|
+
footer?: ReactNode;
|
|
58
|
+
layers?: I_layers;
|
|
59
|
+
getSearchResult?: (searchValue: string) => Promise<I_searchResult[]>;
|
|
60
|
+
onSearch?: (searchResult: I_searchResult) => void;
|
|
61
|
+
mapRef?: any;
|
|
62
|
+
whenReady?: () => void;
|
|
63
|
+
onMoveEnd?: (e: LeafletEvent) => void;
|
|
64
|
+
actionsRef?: any;
|
|
65
|
+
};
|
|
66
|
+
export type I_layers = {
|
|
67
|
+
position: 'topright' | 'topleft';
|
|
68
|
+
items: I_layerItem[];
|
|
69
|
+
};
|
|
70
|
+
export type I_layerItem = {
|
|
71
|
+
name: string;
|
|
72
|
+
markers?: I_marker[];
|
|
73
|
+
shapes?: I_shape[];
|
|
74
|
+
active?: boolean;
|
|
75
|
+
};
|
|
76
|
+
declare const AIMap: FC<I_Map>;
|
|
77
|
+
export default AIMap;
|
|
78
|
+
type I_searchResult = {
|
|
79
|
+
text: string;
|
|
80
|
+
value: string;
|
|
81
|
+
pos: I_pos;
|
|
82
|
+
subtext?: string;
|
|
83
|
+
before?: ReactNode;
|
|
84
|
+
after?: ReactNode;
|
|
85
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{divIcon as e}from"leaflet";import{createContext as r,isValidElement as t,useContext as o,useEffect as n,useRef as a,useState as l}from"react";import{Circle as i,FeatureGroup as c,LayersControl as p,MapContainer as s,Marker as m,Polyline as _,Rectangle as d,TileLayer as u,useMapEvents as h}from"react-leaflet";import f from"aio-input";import{JSXToHTML as v}from"aio-utils";import"leaflet/dist/leaflet.css";import"./index.css";import{jsx as $}from"react/jsx-runtime";import{jsxs as M}from"react/jsx-runtime";let MAPCTX=r({}),AIMap=e=>{var r;let{value:t=[35.699939,51.338497],getSearchResult:o,onSearch:i,mapRef:c}=e,[p,s]=l(null),[m,_]=l((null===(r=e.zoom)||void 0===r?void 0:r.value)||14),d=a(!1);function u(e){!0!==d.current&&_(e)}c&&(c.current=p),e.actionsRef&&(e.actionsRef.current={flyTo(e){d.current=!0,p.flyTo([e.lat,e.lng],e.zoom);let r=()=>{p.off("moveend",r),d.current=!1,u(e.zoom),e.callback()};p.on("moveend",r)}});let[h,f]=l(t),v=a(void 0);function g(r){f(r),e.onChange&&(clearTimeout(v.current),v.current=setTimeout(()=>{e.onChange&&e.onChange(r)},600))}function C(){return M("div",{className:"marker-icon",children:[$("div",{className:"marker-icon-circle"}),$("div",{className:"marker-icon-arrow"})]})}function y(){return{pos:h,setMap:s,rootProps:e,move:g,getDefaultMarkerIcon:C,changeZoom:u,zoom:m}}return n(()=>{null!==p&&p.setView(t,m,{animate:!1}),f(t)},[t[0]+"-"+t[1]+"-"+m]),$(MAPCTX.Provider,{value:y(),children:M("div",{className:"ai-map",children:[!!o&&$(MapHeader,{}),$(MapBody,{}),$(MapFooter,{})]})})};export default AIMap;let MapBody=()=>{var e,r;let{rootProps:n,pos:a,setMap:l,getDefaultMarkerIcon:i,zoom:c}=o(MAPCTX),{style:p,dragging:m=!0,children:_,shapes:d=[],marker:h,markers:f=[],whenReady:v}=n,g={width:"100%",height:"100%"};return M(s,{center:a,style:{...g,...p},zoom:c,scrollWheelZoom:null!==(e=n.zoom)&&void 0!==e&&e.wheel?"center":void 0,zoomControl:(null===(r=n.zoom)||void 0===r?void 0:r.control)!==!1,attributionControl:!0,dragging:m,ref:l,whenReady:v,children:[$(u,{url:"https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png"}),$(MapEvents,{}),!1!==h&&$(MapMarker,{pos:a,html:t(h)?h:i()},"main-marker"),f.map((e,r)=>$(MapMarker,{pos:e.pos,html:e.html,eventHandlers:e.eventHandlers},`marker-${r}`)),d.map((e,r)=>$(MapShape,{shape:e},r)),$(MapLayers,{}),_]})},MagnifyIcon=()=>$("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",width:24,height:24,children:$("path",{d:"M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"})}),MapHeader=()=>{let{rootProps:e,move:r}=o(MAPCTX),{getSearchResult:t,onSearch:n}=e,[i,c]=l(""),[p,s]=l([]),m=a();function _(e){c(e),clearTimeout(m.current),m.current=setTimeout(async()=>{if(t){let r=await t(e);Array.isArray(r)&&s(r)}},1200)}return $("div",{className:"ai-map-header",children:$(f,{type:"text",value:i,options:p||[],before:$(MagnifyIcon,{}),onChange:e=>_(e),option:{onClick(e){n&&n(e)}}})})},MapLayers=()=>{let{rootProps:e}=o(MAPCTX),{layers:r}=e;if(!r)return null;let{position:t="topright",items:n=[]}=r;return $(p,{position:t,children:n.map((e,r)=>{let{shapes:t=[],markers:o=[],active:n=!0}=e;return $(p.Overlay,{name:e.name,checked:n,children:M(c,{children:[o.map((e,r)=>$(MapMarker,{pos:e.pos,html:e.html,eventHandlers:e.eventHandlers},r)),t.map((e,r)=>$(MapShape,{shape:e},r))]})},r)})})},MapShape=({shape:e})=>{let{style:r={},type:t}=e,{stroke:o={},fill:n={}}=r,{width:a=4,dash:l,color:c="orange"}=o,{color:p="orange",opacity:s=.3}=n,m={fillColor:p,color:c,fillOpacity:s,weight:a,dashArray:l};if("circle"===t){let{center:u,radius:h=100}=e;return $(i,{center:u,pathOptions:m,radius:h})}return"rect"===t?$(d,{bounds:e.points,pathOptions:m}):"polyline"===t?$(_,{positions:e.points,pathOptions:m}):null},MapFooter=()=>{let{rootProps:e,pos:r}=o(MAPCTX),{submitText:t="Submit",onSubmit:n,footer:a}=e;return n||a?M("div",{className:"ai-map-footer",children:[!!n&&$("button",{type:"button",onClick:()=>n(r),children:t}),$("div",{className:"ai-map-footer-html",children:a||null})]}):null},MapMarker=({pos:r,html:t,eventHandlers:n})=>{let{getDefaultMarkerIcon:a}=o(MAPCTX);function l(r){return e({html:v(r),className:"",iconSize:[32,32],iconAnchor:[16,32]})}t=t||a();let i={position:r};return t&&(i.icon=l(t)),$(m,{...i,animate:!1,eventHandlers:n})};function MapEvents(){let{rootProps:e,move:r,changeZoom:t}=o(MAPCTX);return h({click:()=>e.onClick?e.onClick():void 0,move(t){if(!1===e.dragging)return;let{lat:o,lng:n}=t.target.getCenter();r([o,n])},zoom(e){t(e.target._zoom)},locationfound(e){console.log("location found:",e)},moveend(r){e.onMoveEnd&&e.onMoveEnd(r)},movestart(e){}}),null}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aio-map",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/mohammadFeiz/aio-map.git"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"jquery": "^3.6.1",
|
|
16
|
+
"aio-utils": "latest",
|
|
17
|
+
"leaflet": "^1.9.4",
|
|
18
|
+
"react-leaflet": "^4.2.1",
|
|
19
|
+
"aio-input":"latest"
|
|
20
|
+
},
|
|
21
|
+
"author": "mohammad sharif feiz feiz.ms@gmail.com",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/mohammadFeiz/aio-map/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/mohammadFeiz/aio-map#readme"
|
|
27
|
+
}
|