Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 97643556
authored
Jan 23, 2025
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan gmap.js
1 parent
8de27740
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
131 deletions
opensipkd/base/alembic/helpers.py
opensipkd/base/alembic/versions/3d466f57ca86_upgrade_routes.py
opensipkd/base/alembic/versions/671617e55c56_menus_add_valu_and_action.py
opensipkd/base/alembic/versions/8ad1f7810384_add_route_updated.py
opensipkd/base/alembic/versions/8e703a7a0657_create_table.py
opensipkd/base/static/js/gmap.js
opensipkd/base/alembic/helpers.py
View file @
9764355
...
...
@@ -2,14 +2,55 @@
from
alembic
import
op
from
sqlalchemy.engine
import
reflection
import
sqlalchemy
as
sa
def
table_has_column
(
table
,
column
):
def
has_table
(
table
,
schema
=
None
,
insp
=
None
):
if
not
insp
:
engine
=
op
.
get_bind
()
insp
=
reflection
.
Inspector
.
from_engine
(
engine
)
return
insp
.
has_table
(
table
,
schema
=
schema
)
def
table_has_column
(
table
,
column
,
schema
=
None
):
engine
=
op
.
get_bind
()
insp
=
reflection
.
Inspector
.
from_engine
(
engine
)
has_column
=
False
for
col
in
insp
.
get_columns
(
table
):
if
column
not
in
col
[
'name'
]:
if
has_table
(
table
,
schema
,
insp
):
for
col
in
insp
.
get_columns
(
table
,
schema
=
schema
):
if
column
!=
col
[
'name'
]:
continue
has_column
=
True
else
:
has_column
=
True
return
has_column
def
table_has_seq
(
table
,
name
,
schema
=
None
):
engine
=
op
.
get_bind
()
insp
=
reflection
.
Inspector
.
from_engine
(
engine
)
has_seq
=
False
if
has_table
(
table
,
schema
,
insp
):
for
seq
in
insp
.
get_sequence_names
(
schema
=
schema
):
if
name
!=
seq
:
continue
has_seq
=
True
else
:
has_seq
=
True
return
has_seq
def
fields_update
(
table
,
field
,
typ
,
schema
=
None
,
**
kw
):
context
=
op
.
get_context
()
helpers
=
context
.
opts
[
'helpers'
]
if
not
helpers
.
table_has_column
(
table
,
field
,
schema
):
op
.
add_column
(
table
,
sa
.
Column
(
field
,
typ
),
schema
=
schema
)
nullable
=
kw
.
get
(
"nullable"
,
None
)
if
nullable
!=
None
and
nullable
==
False
:
default
=
kw
.
get
(
"default"
)
if
default
!=
None
:
op
.
execute
(
f
"UPDATE {schema}.{table} SET {field} = {default}"
)
op
.
alter_column
(
table
,
field
,
nullable
=
False
,
schema
=
schema
)
opensipkd/base/alembic/versions/3d466f57ca86_upgrade_routes.py
deleted
100644 → 0
View file @
8de2774
"""upgrade routes
Revision ID: 3d466f57ca86
Revises: 8e703a7a0657
Create Date: 2024-12-13 11:24:35.337079
"""
# revision identifiers, used by Alembic.
revision
=
'3d466f57ca86'
down_revision
=
'8e703a7a0657'
branch_labels
=
None
depends_on
=
None
from
alembic
import
op
import
sqlalchemy
as
sa
def
upgrade
():
pass
def
downgrade
():
pass
opensipkd/base/alembic/versions/671617e55c56_menus_add_valu_and_action.py
View file @
9764355
...
...
@@ -31,5 +31,6 @@ def upgrade():
sa
.
Column
(
'page_typ'
,
sa
.
String
(
256
)))
def
downgrade
():
pass
opensipkd/base/alembic/versions/8ad1f7810384_add_route_updated.py
View file @
9764355
...
...
@@ -27,5 +27,6 @@ def upgrade():
if
not
helpers
.
table_has_column
(
'routes'
,
'update_uid'
):
op
.
add_column
(
'routes'
,
sa
.
Column
(
'update_uid'
,
sa
.
Integer
,
default
=
0
))
def
downgrade
():
pass
opensipkd/base/alembic/versions/8e703a7a0657_create_table.py
deleted
100644 → 0
View file @
8de2774
"""create table
Revision ID: 8e703a7a0657
Revises: 671617e55c56
Create Date: 2024-11-16 09:03:42.025169
"""
# revision identifiers, used by Alembic.
revision
=
'8e703a7a0657'
down_revision
=
'671617e55c56'
branch_labels
=
None
depends_on
=
None
from
alembic
import
op
import
sqlalchemy
as
sa
def
upgrade
():
pass
def
downgrade
():
pass
opensipkd/base/static/js/gmap.js
View file @
9764355
let
map
;
let
btnCurrent
=
{
lat
:
0
,
lng
:
0
};
let
btnCurrent
=
{
lat
:
0
,
lng
:
0
};
let
selectedFeature
=
null
;
let
btnRemove
;
let
infoWindow
;
let
feature_data
=
{};
let
strokeColor
,
strokeOpacity
,
strokeWeight
,
fillColor
,
fillOpacity
;
let
strokeColorControl
,
strokeOpacityControl
,
strokeWeightControl
,
fillColorControl
,
fillOpacityControl
;
let
strokeColorControl
,
strokeOpacityControl
,
strokeWeightControl
,
fillColorControl
,
fillOpacityControl
;
//let styleControls;
let
featureStyleOptions
=
{
strokeColor
:
"#810fcb"
,
...
...
@@ -17,7 +21,7 @@ let featureStyleOptions = {
function
initMap
()
{
map
=
new
google
.
maps
.
Map
(
document
.
getElementById
(
"gmap"
),
{
center
:
{
lat
:
map_center
[
0
],
lng
:
map_center
[
1
]
},
center
:
{
lat
:
map_center
[
0
],
lng
:
map_center
[
1
]
},
zoom
:
map_zoom
,
animation
:
google
.
maps
.
Animation
.
DROP
,
streetViewControl
:
false
,
...
...
@@ -36,16 +40,39 @@ function initMap() {
map
.
data
.
setControls
(
gmapControls
);
google
.
maps
.
event
.
addListener
(
map
.
data
,
'addfeature'
,
function
(
e
)
{
google
.
maps
.
event
.
addListener
(
map
,
"center_changed"
,
function
(
e
)
{
latLngObj
=
map
.
getCenter
();
console
.
log
(
"lat long object "
+
latLngObj
);
console
.
log
(
e
);
});
google
.
maps
.
event
.
addListener
(
map
.
data
,
"center_changed"
,
function
(
e
)
{
latLngObj
=
map
.
data
.
getCenter
();
console
.
log
(
"lat long object data "
+
latLngObj
);
console
.
log
(
e
);
});
google
.
maps
.
event
.
addListener
(
map
.
data
,
"addfeature"
,
function
(
e
)
{
if
(
map
.
data
.
map
.
data
.
getControls
()
!==
null
)
{
if
(
e
.
feature
.
getGeometry
().
getType
()
===
"Point"
)
{
var
center
=
{
lat
:
e
.
feature
.
getGeometry
().
get
().
lat
(),
lng
:
e
.
feature
.
getGeometry
().
get
().
lng
(),
};
selectedFeature
=
e
.
feature
;
btnRemove
.
disabled
=
false
;
map
.
setCenter
(
center
);
// map.setZoom(18);
}
else
{
let
bounds
=
new
google
.
maps
.
LatLngBounds
();
bounds
=
extendBound
(
bounds
,
e
.
feature
);
selectedFeature
=
e
.
feature
;
btnRemove
.
disabled
=
false
;
map
.
fitBounds
(
bounds
);
}
}
});
google
.
maps
.
event
.
addListener
(
map
.
data
,
'click'
,
function
(
e
)
{
google
.
maps
.
event
.
addListener
(
map
.
data
,
"click"
,
function
(
e
)
{
if
(
e
.
hasOwnProperty
(
"feature"
)
===
true
)
{
selectedFeature
=
e
.
feature
;
btnRemove
.
disabled
=
false
;
...
...
@@ -62,10 +89,13 @@ function initMap() {
map
.
data
.
setStyle
((
feature
)
=>
{
if
(
feature
.
getProperty
(
"styles"
))
{
featureStyleOptions
=
Object
.
assign
(
featureStyleOptions
,
JSON
.
parse
(
feature
.
getProperty
(
"styles"
)));
featureStyleOptions
=
Object
.
assign
(
featureStyleOptions
,
JSON
.
parse
(
feature
.
getProperty
(
"styles"
))
);
setFeatureStyleOptionControls
();
}
else
{
feature
.
setProperty
(
"styles"
,
JSON
.
stringify
(
featureStyleOptions
))
feature
.
setProperty
(
"styles"
,
JSON
.
stringify
(
featureStyleOptions
))
;
}
return
featureStyleOptions
;
});
...
...
@@ -73,11 +103,11 @@ function initMap() {
addYourLocationButton
();
loadData
();
bindDataLayerListeners
(
map
.
data
);
strokeColorControl
=
document
.
getElementById
(
'strokeColor'
);
strokeOpacityControl
=
document
.
getElementById
(
'strokeOpacity'
);
strokeWeightControl
=
document
.
getElementById
(
'strokeWeight'
);
fillColorControl
=
document
.
getElementById
(
'fillColor'
);
fillOpacityControl
=
document
.
getElementById
(
'fillOpacity'
);
strokeColorControl
=
document
.
getElementById
(
"strokeColor"
);
strokeOpacityControl
=
document
.
getElementById
(
"strokeOpacity"
);
strokeWeightControl
=
document
.
getElementById
(
"strokeWeight"
);
fillColorControl
=
document
.
getElementById
(
"fillColor"
);
fillOpacityControl
=
document
.
getElementById
(
"fillOpacity"
);
if
(
strokeColorControl
!==
null
)
{
setFeatureStyleOptionControls
();
setStyleControlEvents
();
...
...
@@ -86,11 +116,26 @@ function initMap() {
function
setStyleControlEvents
()
{
if
(
strokeColorControl
!==
null
)
{
strokeColorControl
.
addEventListener
(
'change'
,
featureStyleOptionsControlChange
);
strokeOpacityControl
.
addEventListener
(
'change'
,
featureStyleOptionsControlChange
);
strokeWeightControl
.
addEventListener
(
'change'
,
featureStyleOptionsControlChange
);
fillColorControl
.
addEventListener
(
'change'
,
featureStyleOptionsControlChange
);
fillOpacityControl
.
addEventListener
(
'change'
,
featureStyleOptionsControlChange
);
strokeColorControl
.
addEventListener
(
"change"
,
featureStyleOptionsControlChange
);
strokeOpacityControl
.
addEventListener
(
"change"
,
featureStyleOptionsControlChange
);
strokeWeightControl
.
addEventListener
(
"change"
,
featureStyleOptionsControlChange
);
fillColorControl
.
addEventListener
(
"change"
,
featureStyleOptionsControlChange
);
fillOpacityControl
.
addEventListener
(
"change"
,
featureStyleOptionsControlChange
);
}
}
...
...
@@ -139,39 +184,49 @@ function showInfo(event) {
let
content
=
""
;
for
(
let
key
in
contents
)
{
let
keys
=
contents
[
key
];
let
value
=
key
===
"id"
?
event
.
feature
.
getId
()
:
event
.
feature
.
getProperty
(
key
);
value
=
value
===
undefined
?
""
:
value
let
value
=
key
===
"id"
?
event
.
feature
.
getId
()
:
event
.
feature
.
getProperty
(
key
);
value
=
value
===
undefined
?
""
:
value
;
let
cnt
=
keys
[
0
]
+
": "
+
value
;
if
(
keys
.
length
>
1
)
{
if
(
keys
[
1
]
===
'b'
)
{
cnt
=
"<b>"
+
cnt
+
"</b>"
if
(
keys
[
1
]
===
"b"
)
{
cnt
=
"<b>"
+
cnt
+
"</b>"
;
}
}
content
+=
cnt
+
'<br>'
;
content
+=
cnt
+
"<br>"
;
}
if
(
edit_url
!==
""
&&
event
.
feature
.
getId
()
!==
undefined
)
{
let
url
=
edit_url
.
replace
(
"{id}"
,
selectedFeature
.
getId
());
content
+=
'<a class="btn btn-info" href="{url}">Edit</a>'
.
replace
(
"{url}"
,
url
);
content
+=
'<a class="btn btn-info" href="{url}">Edit</a>'
.
replace
(
"{url}"
,
url
);
}
infoWindow
.
setContent
(
content
);
infoWindow
.
open
(
map
);
}
function
bindDataLayerListeners
(
dataLayer
)
{
dataLayer
.
addListener
(
'addfeature'
,
saveData
);
dataLayer
.
addListener
(
'removefeature'
,
saveData
);
dataLayer
.
addListener
(
'setgeometry'
,
saveData
);
dataLayer
.
addListener
(
"addfeature"
,
saveData
);
dataLayer
.
addListener
(
"removefeature"
,
saveData
);
dataLayer
.
addListener
(
"setgeometry"
,
saveData
);
}
function
extendBound
(
newbounds
,
feature
)
{
if
(
feature
===
undefined
)
return
newbounds
;
let
featureType
=
feature
.
getGeometry
().
getType
();
if
(
featureType
===
'LineString'
)
{
feature
.
getGeometry
().
getArray
().
forEach
(
function
(
latLng
)
{
if
(
featureType
===
"LineString"
)
{
feature
.
getGeometry
()
.
getArray
()
.
forEach
(
function
(
latLng
)
{
newbounds
.
extend
(
latLng
);
});
}
else
if
(
featureType
===
'Polygon'
)
{
feature
.
getGeometry
().
getArray
().
forEach
(
function
(
path
)
{
}
else
if
(
featureType
===
"Polygon"
)
{
feature
.
getGeometry
()
.
getArray
()
.
forEach
(
function
(
path
)
{
path
.
getArray
().
forEach
(
function
(
latLng
)
{
newbounds
.
extend
(
latLng
);
});
...
...
@@ -205,11 +260,9 @@ function setControls() {
let
bounds
=
new
google
.
maps
.
LatLngBounds
();
bounds
=
extendBound
(
bounds
,
e
);
let
properties
=
{};
e
.
forEachProperty
(
function
(
val
,
key
)
{
e
.
forEachProperty
(
function
(
val
,
key
)
{
properties
[
key
]
=
val
;
}
);
});
map
.
data
.
add
({
geometry
:
new
google
.
maps
.
Data
.
Point
(
bounds
.
getCenter
()),
properties
:
properties
,
...
...
@@ -231,83 +284,86 @@ function saveData() {
}
function
addYourLocationButton
()
{
let
controlDiv
=
document
.
createElement
(
'div'
);
let
btnCurrent
=
document
.
createElement
(
'button'
);
let
controlDiv
=
document
.
createElement
(
"div"
);
let
btnCurrent
=
document
.
createElement
(
"button"
);
btnCurrent
.
type
=
"button"
;
btnCurrent
.
style
.
backgroundColor
=
'#fff'
;
btnCurrent
.
style
.
border
=
'none'
;
btnCurrent
.
style
.
outline
=
'none'
;
btnCurrent
.
style
.
width
=
'28px'
;
btnCurrent
.
style
.
height
=
'28px'
;
btnCurrent
.
style
.
borderRadius
=
'2px'
;
btnCurrent
.
style
.
boxShadow
=
'0 1px 4px rgba(0,0,0,0.3)'
;
btnCurrent
.
style
.
cursor
=
'pointer'
;
btnCurrent
.
style
.
marginRight
=
'10px'
;
btnCurrent
.
style
.
padding
=
'0'
;
btnCurrent
.
title
=
'Your Location'
;
btnCurrent
.
style
.
backgroundColor
=
"#fff"
;
btnCurrent
.
style
.
border
=
"none"
;
btnCurrent
.
style
.
outline
=
"none"
;
btnCurrent
.
style
.
width
=
"28px"
;
btnCurrent
.
style
.
height
=
"28px"
;
btnCurrent
.
style
.
borderRadius
=
"2px"
;
btnCurrent
.
style
.
boxShadow
=
"0 1px 4px rgba(0,0,0,0.3)"
;
btnCurrent
.
style
.
cursor
=
"pointer"
;
btnCurrent
.
style
.
marginRight
=
"10px"
;
btnCurrent
.
style
.
padding
=
"0"
;
btnCurrent
.
title
=
"Your Location"
;
controlDiv
.
appendChild
(
btnCurrent
);
let
imgCurrent
=
document
.
createElement
(
'div'
);
imgCurrent
.
style
.
margin
=
'5px'
;
imgCurrent
.
style
.
width
=
'18px'
;
imgCurrent
.
style
.
height
=
'18px'
;
imgCurrent
.
style
.
backgroundImage
=
'url(https://maps.gstatic.com/tactile/mylocation/mylocation-sprite-2x.png)'
;
imgCurrent
.
style
.
backgroundSize
=
'180px 18px'
;
imgCurrent
.
style
.
backgroundPosition
=
'0 0'
;
imgCurrent
.
style
.
backgroundRepeat
=
'no-repeat'
;
let
imgCurrent
=
document
.
createElement
(
"div"
);
imgCurrent
.
style
.
margin
=
"5px"
;
imgCurrent
.
style
.
width
=
"18px"
;
imgCurrent
.
style
.
height
=
"18px"
;
imgCurrent
.
style
.
backgroundImage
=
"url(https://maps.gstatic.com/tactile/mylocation/mylocation-sprite-2x.png)"
;
imgCurrent
.
style
.
backgroundSize
=
"180px 18px"
;
imgCurrent
.
style
.
backgroundPosition
=
"0 0"
;
imgCurrent
.
style
.
backgroundRepeat
=
"no-repeat"
;
btnCurrent
.
appendChild
(
imgCurrent
);
let
txtCurrent
=
document
.
createElement
(
'i'
);
let
txtCurrent
=
document
.
createElement
(
"i"
);
txtCurrent
.
className
=
"fa"
;
txtCurrent
.
ariaHidden
=
"true"
;
//<i class="fa fa-trash" aria-hidden="true"></i>
imgCurrent
.
appendChild
(
txtCurrent
);
google
.
maps
.
event
.
addListener
(
map
,
'center_changed'
,
function
()
{
imgCurrent
.
style
[
'background-position'
]
=
'0 0'
;
google
.
maps
.
event
.
addListener
(
map
,
"center_changed"
,
function
()
{
imgCurrent
.
style
[
"background-position"
]
=
"0 0"
;
});
btnCurrent
.
addEventListener
(
'click'
,
function
()
{
btnCurrent
.
addEventListener
(
"click"
,
function
()
{
let
imgX
=
0
,
animationInterval
=
setInterval
(
function
()
{
imgX
=
-
imgX
-
18
;
imgCurrent
.
style
[
'background-position'
]
=
imgX
+
'px 0'
;
imgCurrent
.
style
[
"background-position"
]
=
imgX
+
"px 0"
;
},
500
);
if
(
navigator
.
geolocation
)
{
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
let
latlng
=
new
google
.
maps
.
LatLng
(
position
.
coords
.
latitude
,
position
.
coords
.
longitude
);
let
latlng
=
new
google
.
maps
.
LatLng
(
position
.
coords
.
latitude
,
position
.
coords
.
longitude
);
map
.
setCenter
(
latlng
);
map
.
setZoom
(
18
);
clearInterval
(
animationInterval
);
btnCurrent
.
style
[
'background-position'
]
=
'-144px 0'
;
btnCurrent
.
style
[
"background-position"
]
=
"-144px 0"
;
});
}
else
{
clearInterval
(
animationInterval
);
btnCurrent
.
style
[
'background-position'
]
=
'0 0'
;
btnCurrent
.
style
[
"background-position"
]
=
"0 0"
;
}
});
// let btnRemove = document.getElementById('btnRemove');
btnRemove
=
document
.
createElement
(
'button'
);
btnRemove
=
document
.
createElement
(
"button"
);
btnRemove
.
type
=
"button"
;
btnRemove
.
style
.
backgroundColor
=
'#fff'
;
btnRemove
.
style
.
border
=
'none'
;
btnRemove
.
style
.
outline
=
'none'
;
btnRemove
.
style
.
width
=
'28px'
;
btnRemove
.
style
.
height
=
'28px'
;
btnRemove
.
style
.
borderRadius
=
'2px'
;
btnRemove
.
style
.
boxShadow
=
'0 1px 4px rgba(0,0,0,0.3)'
;
btnRemove
.
style
.
cursor
=
'pointer'
;
btnRemove
.
style
.
backgroundColor
=
"#fff"
;
btnRemove
.
style
.
border
=
"none"
;
btnRemove
.
style
.
outline
=
"none"
;
btnRemove
.
style
.
width
=
"28px"
;
btnRemove
.
style
.
height
=
"28px"
;
btnRemove
.
style
.
borderRadius
=
"2px"
;
btnRemove
.
style
.
boxShadow
=
"0 1px 4px rgba(0,0,0,0.3)"
;
btnRemove
.
style
.
cursor
=
"pointer"
;
// btnRemove.style.marginRight = '10px';
btnRemove
.
style
.
padding
=
'0'
;
btnRemove
.
title
=
'Delete Selected Feature'
;
btnRemove
.
style
.
padding
=
"0"
;
btnRemove
.
title
=
"Delete Selected Feature"
;
controlDiv
.
appendChild
(
btnRemove
);
let
imgRemove
=
document
.
createElement
(
'div'
);
imgRemove
.
style
.
margin
=
'5px'
;
imgRemove
.
style
.
width
=
'18px'
;
imgRemove
.
style
.
height
=
'18px'
;
let
imgRemove
=
document
.
createElement
(
"div"
);
imgRemove
.
style
.
margin
=
"5px"
;
imgRemove
.
style
.
width
=
"18px"
;
imgRemove
.
style
.
height
=
"18px"
;
btnRemove
.
appendChild
(
imgRemove
);
let
txtRemove
=
document
.
createElement
(
'i'
);
let
txtRemove
=
document
.
createElement
(
"i"
);
txtRemove
.
className
=
"fa fa-trash"
;
txtRemove
.
ariaHidden
=
"true"
;
//<i class="fa fa-trash" aria-hidden="true"></i>
imgRemove
.
appendChild
(
txtRemove
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment