1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| Sub AjoutCarteDpt_A()
Dim l_Url As String
Dim Sh As Shape, Img As Object
Dim tArea(50) As String, tZone(50) As String, tCoord() As String, nbZone As Integer
Dim texte As String, nodept As String, txt As String
Dim area As String, zone As String
Dim i As Integer, j As Integer, k As Integer
Dim posX As Integer, posY As Integer
Dim X As Integer, Y As Integer
Dim Xmax As Integer, Ymax As Integer
Dim Xmin As Integer, Ymin As Integer
Dim kX As Single, kY As Single
For Each Sh In ActiveSheet.Shapes
Sh.Delete
Next
[A1] = InputBox("Département")
nodept = [A1]
[A1].Select
Debug.Print [A1]
l_Url = "http://s599720764.onlinehome.fr/cartocistes/cartographie" & nodept & "/images/image0.png"
'Debug.Print l_Url
Set Img = ActiveSheet.Pictures.Insert(l_Url)
Img.Name = "ImageDept"
Debug.Print Img.Width, Img.Height
l_Url = "http://s599720764.onlinehome.fr/cartocistes/cartographie" & nodept & "/indexOrdi.php?codeRegion=" & nodept & "&codePays=FR"
'Debug.Print l_Url
texte = GetCodeSource(l_Url) 'avec les balises(format html)
' Boucle recherche <area shape="poly" coords=
j = 1
Do
j = InStr(j, texte, "<area shape=""poly"" coords=")
If j = 0 Then Exit Do
txt = Mid(texte, j, 200)
j = j + Len("<area shape=""poly"" coords=") + 1
k = InStr(j, texte, """")
If k > 0 Then
txt = Mid(texte, k, 50) 'Sauter jusqu'à la 1ère zone
If InStr(1, txt, "href") Then
nbZone = nbZone + 1
area = Mid(texte, j, k - j)
tArea(nbZone) = area
' Recherche alt= pour nom de la zone
j = k
j = InStr(j, texte, "alt=")
If j > 0 Then
j = j + 5
k = InStr(j, texte, """")
If k > 0 Then
zone = Mid(texte, j, k - j)
tZone(nbZone) = zone
End If
End If
End If
End If
Loop While j > 0
Xmax = 0
Ymax = 0
Xmin = 999
Ymin = 999
'--- recherche Xmax, Ymax
For i = 1 To nbZone
tCoord = Split(tArea(i), ",")
posX = CInt(tCoord(UBound(tCoord) - 1))
posY = CInt(tCoord(UBound(tCoord)))
For j = 0 To UBound(tCoord) - 1 Step 2
X = CInt(tCoord(j))
Y = CInt(tCoord(j + 1))
If X > Xmax Then Xmax = X
If Y > Ymax Then Ymax = Y
If X < Xmin Then Xmin = X
If Y < Ymin Then Ymin = Y
Next j
Next i
'--- calcul coefficients d'ajustment
With Img.ShapeRange
kX = .Width / (Xmax + Xmin) '--- taille zones ok
kY = .Height / (Ymax + Ymin)
End With
Debug.Print Xmin, Ymin, Xmax, Ymax, kX, kY
'--- tracé zones ajustées
For i = 1 To nbZone
tCoord = Split(tArea(i), ",")
posX = CInt(tCoord(UBound(tCoord) - 1)) * kX
posY = CInt(tCoord(UBound(tCoord))) * kY
With Sheets(1).Shapes.BuildFreeform(msoEditingAuto, posX, posY)
For j = 0 To UBound(tCoord) - 1 Step 2
X = CInt(tCoord(j)) * kX
Y = CInt(tCoord(j + 1)) * kY
.AddNodes msoSegmentLine, msoEditingAuto, X, Y
Next j
.ConvertToShape.Select
End With
Selection.Name = Left(tZone(i), 32)
Next
End Sub |
Partager