3
$\begingroup$

I'm trying to create this:

  1. A map with a PNG picture in the background
  2. A locator for position
  3. The locator (p1) needs to have a disk with center in p1

The problem is that the locator disk and the map can coexist together, I tried ImageCompose, Overlay, Show... "p1" update good but the disk doesn't move!

size = 6000;
escala = 1000;
proporcion = size/escala;
r = 100;

With[{source = ImageResize[Import["LINK.png"], {escala}]},
  Manipulate[
    Image[source, ImageSize -> escala],
    {{pt, {escala/2, escala/2}}, ControlType -> Locator},
    Row[
      {Style["Posición = ", Bold, 15], 
       Dynamic @ Style[{Dynamic[proporcion pt[[1]]] , 
       Dynamic[proporcion (escala - pt[[2]])]}, Bold, 25]}],
    ControlPlacement -> Top, 
    TrackedSymbols -> {pt}]

The map is 6000 x 6000 and the "Position" coordinates have to be in this range. I want to see the image in the CDF so I use With.

When I try to add a Graphic[Disk[p1]], the disk doesn't move in any way, I want to see that disk moving around the image with and control its radius.

This is the easiest way that I see to create my map. I can't use a map from the Geographic module because they are all real-life maps. I want a fantasy map.

$\endgroup$

1 Answer 1

5
$\begingroup$

Here is some code that solves your moving disk problem.

With[
   {source = ExampleData[{"TestImage", "Lena"}],
    disk = 
      Graphics[{White, Opacity[.4], EdgeForm[Black], Disk[{0, 0}, Scaled[.05]]}]},
  Manipulate[
    source,
    {{pt, ImageDimensions[source]/2}, Appearance -> disk, ControlType -> Locator},
    Dynamic @ 
      Row[{Style["Posición = ", Bold, 15], Style[{pt[[1]], pt[[2]]}, Bold, 25]}],
    ControlPlacement -> Top,
    TrackedSymbols -> {pt}]]

lena

Update

To be able to adjust the radius of disk, a somewhat different approach must taken. Injecting the disk into the code with With must be abandoned because that produces a static, fixed-size disk. Instead I will define a function in which the disk is expressed as a function of its radius and call it with the dynamic variable associated with a control.

With[{source = ExampleData[{"TestImage", "Lena"}]},
  With[{dimensions = ImageDimensions[source]},
    Manipulate[
      source,
      {{r, .05, Style["r", Bold, 15]}, .02, .5, .01, ImageSize -> 500},
      {{pt, dimensions/2}, Locator, Appearance -> disk[r]}, 
      Dynamic @ 
        Row[{Style["Posición = ", Bold, 15], Style[{pt[[1]], pt[[2]]}, Bold, 15]}], 
      ControlPlacement -> Top,
      Initialization :> (
        disk[r_] :=
          Graphics[
            {White, Opacity[.4], EdgeForm[Black], Disk[{0, 0}, ImageScaled[r]]},
            ImageSize -> dimensions])]]]

lena-update

$\endgroup$
4
  • $\begingroup$ I like it but i can't control the radius! I would like to change the radius between 1 and 512 (the picture of the example is 512x512), i know how to create the slider itself the i can't introduce "r" in Disk[] like this: Disk[{0,0},r] $\endgroup$ Commented Nov 26, 2016 at 15:19
  • $\begingroup$ Thanks! it was so useful to me. I like it! Can i add the position over the disk? (not inside, over) to avoid the label with the "{ }" because it doesn't look good at all. $\endgroup$ Commented Nov 27, 2016 at 16:14
  • $\begingroup$ @ShiroIgnis You say you like my answer. If so, you should accept it. But all you do, is ask for more help. For your latest request, here's a hint: disk makes a graphics object. That object can contain text like any other graphics object. You will have to add an argument to disk to pass in the coordinates. It would be good practice for you to work this out on own from this hint. If you are not up to it, you should ask about it in a new question. $\endgroup$
    – m_goldberg
    Commented Nov 27, 2016 at 16:35
  • $\begingroup$ Ok, i didn't know about "accept the answer", I appologise, I checked the answer. It's enough for me =) i will continue by me own since this point, thanks again. $\endgroup$ Commented Nov 27, 2016 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.