{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, Polygon" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "center = [22.398332241511387, 114.02332305908205]\n", "zoom = 11" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = Map(center=center, zoom=zoom)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "polygon_coords = [\n", " [22.403410892712124, 113.97697448730469],\n", " [22.38373008592495 , 113.98658752441405],\n", " [22.369126397545887, 114.01268005371094],\n", " [22.38563480185718 , 114.02778625488281],\n", " [22.395157990290755, 114.04701232910156],\n", " [22.413567638369805, 114.06005859375 ],\n", " [22.432609534876796, 114.06280517578125],\n", " [22.444668051657157, 114.04838562011717],\n", " [22.44847578656544 , 114.04289245605469],\n", " [22.444668051657157, 114.03259277343749],\n", " [22.447206553211814, 114.01954650878906],\n", " [22.436417600763114, 113.99620056152344],\n", " [22.420549970290875, 113.98178100585938]\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's create a polygon that can be transformed (i.e. rotated and scaled) and dragged. You can drag the polygon around, or use the handler to rotate it and to scale it. Note that the transformations are synced accross all the map views." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pg = Polygon(locations=polygon_coords, transform=True, draggable=True)\n", "m += pg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The scaling can be set to be uniform, meaning that it will preserve the height / width ratio." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pg.uniform_scaling = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ability to scale, rotate and drag can be turned off." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pg.scaling = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pg.rotation = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pg.draggable = False" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }