Skip to content

Commit

Permalink
add mapbox token and mal center location for new asset pages (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoening committed Feb 18, 2021
1 parent 10017e0 commit ec3d6f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions flexmeasures/ui/crud/assets.py
Expand Up @@ -10,13 +10,14 @@
from wtforms.validators import DataRequired
from sqlalchemy.exc import IntegrityError

from flexmeasures.data.config import db
from flexmeasures.data.auth_setup import unauthorized_handler
from flexmeasures.data.services.users import (
get_users,
create_user,
InvalidFlexMeasuresUser,
)
from flexmeasures.data.services.resources import get_markets
from flexmeasures.data.services.resources import get_markets, get_center_location
from flexmeasures.data.models.assets import AssetType, Asset
from flexmeasures.data.models.user import User
from flexmeasures.data.models.markets import Market
Expand Down Expand Up @@ -188,7 +189,11 @@ def get(self, id: str):

asset_form = with_options(NewAssetForm())
return render_flexmeasures_template(
"crud/asset_new.html", asset_form=asset_form, msg=""
"crud/asset_new.html",
asset_form=asset_form,
msg="",
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)

get_asset_response = InternalApi().get(
Expand Down Expand Up @@ -268,7 +273,11 @@ def post(self, id: str):
if asset is None:
msg = "Cannot create asset. " + error_msg
return render_flexmeasures_template(
"crud/asset_new.html", asset_form=asset_form, msg=msg
"crud/asset_new.html",
asset_form=asset_form,
msg=msg,
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)

else:
Expand All @@ -278,6 +287,8 @@ def post(self, id: str):
"crud/asset_new.html",
asset_form=asset_form,
msg="Cannot edit asset.",
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)
patch_asset_response = InternalApi().patch(
url_for("flexmeasures_api_v2_0.patch_asset", id=id),
Expand Down
5 changes: 3 additions & 2 deletions flexmeasures/ui/templates/crud/asset_new.html
Expand Up @@ -167,13 +167,14 @@ <h3>Location</h3>

// create map
var assetMap = L
.map('mapid', { center: [33.37, 126.57], zoom: 10 })
.map('mapid', { center: [{{ map_center[0] }}, {{ map_center[1] }}], zoom: 10})
.on('popupopen', function () {
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
});
tileLayer.addTo(assetMap);
addTileLayer(assetMap, '{{ mapboxAccessToken }}');


var location_icon = new L.DivIcon({
className: 'map-icon',
Expand Down

0 comments on commit ec3d6f6

Please sign in to comment.