Get map images working
This commit is contained in:
parent
6fb7fc7825
commit
89eda187be
5 changed files with 52 additions and 25 deletions
|
|
@ -44,20 +44,26 @@ func getComplianceRequestImagePool(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "parcel env", http.StatusInternalServerError)
|
http.Error(w, "parcel env", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info().Int("len", len(*envelope)).Msg("got envelope")
|
|
||||||
ring := (*envelope)[0]
|
ring := (*envelope)[0]
|
||||||
log.Info().Int("len", len(ring)).Msg("got ring")
|
|
||||||
p := ring[0]
|
p := ring[0]
|
||||||
log.Info().Int("len", len(p)).Msg("got point")
|
err = writeImage(ctx, w, org, 22, p[1], p[0])
|
||||||
writeImage(ctx, w, org, 14, p[0], p[1])
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("write image")
|
||||||
|
http.Error(w, "failed to write image", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
func writeImage(ctx context.Context, w http.ResponseWriter, org *models.Organization, level uint, x, y float64) {
|
}
|
||||||
img, err := imagetile.ImageAtPoint(ctx, org, level, x, y)
|
func writeImage(ctx context.Context, w http.ResponseWriter, org *models.Organization, level uint, lat, lng float64) error {
|
||||||
|
img, err := imagetile.ImageAtPoint(ctx, org, level, lat, lng)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("image at point: %w", err)
|
||||||
|
}
|
||||||
|
log.Info().Int("size", len(img)).Msg("image")
|
||||||
w.Header().Set("Content-Type", "image/png")
|
w.Header().Set("Content-Type", "image/png")
|
||||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(img)))
|
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(img)))
|
||||||
_, err = io.Copy(w, bytes.NewBuffer(img))
|
_, err = io.Copy(w, bytes.NewBuffer(img))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "failed copy", http.StatusInternalServerError)
|
return fmt.Errorf("copy bytes: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,7 @@ func updateArcgisUserData(ctx context.Context, user *models.User, oauth *models.
|
||||||
log.Error().Err(err).Msg("Failed to update oauth token portal data")
|
log.Error().Err(err).Msg("Failed to update oauth token portal data")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
txn.Commit(ctx)
|
||||||
// At this point we have the arcgis ID. If the ID matches an existing ID, join it with the users organization
|
// At this point we have the arcgis ID. If the ID matches an existing ID, join it with the users organization
|
||||||
orgs, err := models.Organizations.Query(
|
orgs, err := models.Organizations.Query(
|
||||||
sm.Where(
|
sm.Where(
|
||||||
|
|
@ -357,6 +358,13 @@ func updateArcgisUserData(ctx context.Context, user *models.User, oauth *models.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txn, err = db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Create transaction")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer txn.Rollback(ctx)
|
||||||
|
|
||||||
fssync, err := fieldseeker.NewFieldSeekerFromAG(ctx, *client)
|
fssync, err := fieldseeker.NewFieldSeekerFromAG(ctx, *client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to create fieldseeker")
|
log.Error().Err(err).Msg("Failed to create fieldseeker")
|
||||||
|
|
@ -365,11 +373,13 @@ func updateArcgisUserData(ctx context.Context, user *models.User, oauth *models.
|
||||||
log.Info().Str("url", fssync.ServiceFeature.URL.String()).Msg("Found Fieldseeker")
|
log.Info().Str("url", fssync.ServiceFeature.URL.String()).Msg("Found Fieldseeker")
|
||||||
|
|
||||||
// Ensure the fieldseeker service is saved on the account
|
// Ensure the fieldseeker service is saved on the account
|
||||||
|
// Why yes, we do get 'ArcGIS' and 'arcgis' from the API, why do you ask?
|
||||||
|
url_corrected := strings.Replace(fssync.ServiceFeature.URL.String(), "/arcgis/", "/ArcGIS/", 1)
|
||||||
service_account, err := models.ArcgisServiceFeatures.Query(
|
service_account, err := models.ArcgisServiceFeatures.Query(
|
||||||
models.SelectWhere.ArcgisServiceFeatures.URL.EQ(fssync.ServiceFeature.URL.String()),
|
models.SelectWhere.ArcgisServiceFeatures.URL.EQ(url_corrected),
|
||||||
).One(ctx, txn)
|
).One(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("no fieldseeker service")
|
log.Error().Err(err).Str("url", fssync.ServiceFeature.URL.String()).Str("url_corrected", url_corrected).Msg("no fieldseeker service to link, it should have been created before")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setter := models.OrganizationSetter{
|
setter := models.OrganizationSetter{
|
||||||
|
|
@ -380,7 +390,6 @@ func updateArcgisUserData(ctx context.Context, user *models.User, oauth *models.
|
||||||
log.Error().Err(err).Msg("Failed to create new organization")
|
log.Error().Err(err).Msg("Failed to create new organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txn.Commit(ctx)
|
|
||||||
maybeCreateWebhook(ctx, fssync)
|
maybeCreateWebhook(ctx, fssync)
|
||||||
downloadFieldseekerSchema(ctx, fssync, account.ID)
|
downloadFieldseekerSchema(ctx, fssync, account.ID)
|
||||||
notification.ClearOauth(ctx, user)
|
notification.ClearOauth(ctx, user)
|
||||||
|
|
@ -390,7 +399,7 @@ func updateArcgisUserData(ctx context.Context, user *models.User, oauth *models.
|
||||||
func NewFieldSeeker(ctx context.Context, oauth *models.ArcgisOauthToken) (*fieldseeker.FieldSeeker, error) {
|
func NewFieldSeeker(ctx context.Context, oauth *models.ArcgisOauthToken) (*fieldseeker.FieldSeeker, error) {
|
||||||
row, err := sql.OrgByOauthId(oauth.ID).One(ctx, db.PGInstance.BobDB)
|
row, err := sql.OrgByOauthId(oauth.ID).One(ctx, db.PGInstance.BobDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to get org ID: %w", err)
|
return nil, fmt.Errorf("Failed to get org ID from oauth %d: %w", oauth.ID, err)
|
||||||
}
|
}
|
||||||
// The URL for fieldseeker should be something like
|
// The URL for fieldseeker should be something like
|
||||||
// https://foo.arcgis.com/123abc/arcgis/rest/services/FieldSeekerGIS/FeatureServer
|
// https://foo.arcgis.com/123abc/arcgis/rest/services/FieldSeekerGIS/FeatureServer
|
||||||
|
|
@ -494,6 +503,9 @@ func updateServiceData(ctx context.Context, txn bob.Tx, client *arcgis.ArcGIS, u
|
||||||
}
|
}
|
||||||
for _, sm := range service_maps {
|
for _, sm := range service_maps {
|
||||||
log.Info().Str("account-id", account.ID).Str("arcgis-id", sm.ID).Str("name", sm.Name).Str("title", sm.Title).Str("url", sm.URL.String()).Msg("inserting map service")
|
log.Info().Str("account-id", account.ID).Str("arcgis-id", sm.ID).Str("name", sm.Name).Str("title", sm.Title).Str("url", sm.URL.String()).Msg("inserting map service")
|
||||||
|
_, err := models.FindArcgisServiceMap(ctx, txn, sm.ID)
|
||||||
|
if err != nil {
|
||||||
|
if err.Error() == "sql: no rows in result set" {
|
||||||
setter := models.ArcgisServiceMapSetter{
|
setter := models.ArcgisServiceMapSetter{
|
||||||
AccountID: omit.From(account.ID),
|
AccountID: omit.From(account.ID),
|
||||||
ArcgisID: omit.From(sm.ID),
|
ArcgisID: omit.From(sm.ID),
|
||||||
|
|
@ -505,6 +517,10 @@ func updateServiceData(ctx context.Context, txn bob.Tx, client *arcgis.ArcGIS, u
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("save map service: %w", err)
|
return fmt.Errorf("save map service: %w", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
|
|
||||||
// Created this after (maybe mistakenly) marking the above as:
|
// Created this after (maybe mistakenly) marking the above as:
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
//"github.com/rs/zerolog/log"
|
//"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ImageAtPoint(ctx context.Context, org *models.Organization, level uint, x, y float64) ([]byte, error) {
|
func ImageAtPoint(ctx context.Context, org *models.Organization, level uint, lat, lng float64) ([]byte, error) {
|
||||||
oauth, err := background.GetOAuthForOrg(ctx, org)
|
oauth, err := background.GetOAuthForOrg(ctx, org)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("get oauth for org: %w", err)
|
return []byte{}, fmt.Errorf("get oauth for org: %w", err)
|
||||||
|
|
@ -19,11 +19,14 @@ func ImageAtPoint(ctx context.Context, org *models.Organization, level uint, x,
|
||||||
ctx,
|
ctx,
|
||||||
oauth,
|
oauth,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, fmt.Errorf("create fssync: %w", err)
|
||||||
|
}
|
||||||
map_service, err := aerialImageService(ctx, fssync.Arcgis)
|
map_service, err := aerialImageService(ctx, fssync.Arcgis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("no map service: %w", err)
|
return []byte{}, fmt.Errorf("no map service: %w", err)
|
||||||
}
|
}
|
||||||
return map_service.TileGPS(ctx, fssync.Arcgis, level, x, y)
|
return map_service.TileGPS(ctx, level, lat, lng)
|
||||||
}
|
}
|
||||||
|
|
||||||
func aerialImageService(ctx context.Context, gis *arcgis.ArcGIS) (*arcgis.MapService, error) {
|
func aerialImageService(ctx context.Context, gis *arcgis.ArcGIS) (*arcgis.MapService, error) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#!/run/current-system/sw/bin/bash
|
#!/run/current-system/sw/bin/bash
|
||||||
# normal
|
# normal
|
||||||
#export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_UPSTREAM=http://127.0.0.1:9001 ../flogo/flogo -target .
|
#export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_UPSTREAM=http://127.0.0.1:9001 ../flogo/flogo -target .
|
||||||
|
# MITM proxy
|
||||||
|
export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_UPSTREAM=http://127.0.0.1:9001 MITM_PROXY=http://127.0.0.1:8080 ../flogo/flogo -target .
|
||||||
# verbose
|
# verbose
|
||||||
export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_UPSTREAM=http://127.0.0.1:9001 FLOGO_VERBOSE=1 ../flogo/flogo -target .
|
#export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_UPSTREAM=http://127.0.0.1:9001 FLOGO_VERBOSE=1 ../flogo/flogo -target .
|
||||||
# no TUI
|
# no TUI
|
||||||
#export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_DISABLE_TUI=1 FLOGO_UPSTREAM=http://127.0.0.1:9001 ../flogo/flogo -target .
|
#export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && BIND=127.0.0.1:9001 FLOGO_BIND=:9000 FLOGO_DISABLE_TUI=1 FLOGO_UPSTREAM=http://127.0.0.1:9001 ../flogo/flogo -target .
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
#!/run/current-system/sw/bin/bash
|
#!/run/current-system/sw/bin/bash
|
||||||
export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && ./nidus-sync 2>&1 | tee nidus-sync.log
|
export $(cat /var/run/secrets/nidus-dev-sync-env | xargs) && MITM_PROXY=http://127.0.0.1:8080 ./nidus-sync 2>&1 | tee nidus-sync.log
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue